8000 add list of dashboard names to workbook object by jacalata · Pull Request #210 · tableau/document-api-python · GitHub
[go: up one dir, main page]

Skip to content

add list of dashboard names to workbook object #210

8000 New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions tableaudocumentapi/workbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ def __init__(self, filename):
self._workbookTree = xml_open(self._filename, 'workbook')

self._workbookRoot = self._workbookTree.getroot()
# prepare our datasource objects

self._dashboards = self._prepare_dashboards(self._workbookRoot)

self._datasources = self._prepare_datasources(
self._workbookRoot) # self.workbookRoot.find('datasources')
self._workbookRoot)

self._datasource_index = self._prepare_datasource_index(self._datasources)

Expand All @@ -31,6 +33,10 @@ def __init__(self, filename):

self._shapes = self._prepare_shapes(self._workbookRoot)

@property
def dashboards(self):
return self._dashboards

@property
def datasources(self):
return self._datasources
Expand Down Expand Up @@ -99,6 +105,20 @@ def _prepare_datasources(xml_root):

return datasources

@staticmethod
def _prepare_dashboards(xml_root):
dashboards = []

dashboard_elements = xml_root.find('.//dashboards')
if dashboard_elements is None:
return []

for dash_element in dashboard_elements:
dash_name = dash_element.attrib['name']
dashboards.append(dash_name)

return dashboards

@staticmethod
def _prepare_worksheets(xml_root, ds_index):
worksheets = []
Expand Down
12 changes: 12 additions & 0 deletions test/test_workbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
'shapes_test.twb'
)

DASHBOARDS_FILE = os.path.join(
TEST_ASSET_DIR,
'filtering.twb'
)


class EphemeralFields(unittest.TestCase):
def test_ephemeral_fields_do_not_cause_errors(self):
Expand All @@ -37,3 +42,10 @@ def test_shape_exist(self):
def test_shape_count(self):
wb = Workbook(SHAPES_FILE)
self.assertEqual(len(wb.shapes), 4)


class Dashboards(unittest.TestCase):
def test_dashboards_setup(self):
wb = Workbook(DASHBOARDS_FILE)
self.assertIsNotNone(wb)
self.assertEqual(wb.dashboards, ['setTest'])
0