How to use the tableauserverclient.WorkbookItem function in tableauserverclient

To help you get started, we’ve selected a few tableauserverclient examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tableau / server-client-python / test / test_workbook.py View on Github external
def test_update(self):
        with open(UPDATE_XML, 'rb') as f:
            response_xml = f.read().decode('utf-8')
        with requests_mock.mock() as m:
            m.put(self.baseurl + '/1f951daf-4061-451a-9df1-69a8062664f2', text=response_xml)
            single_workbook = TSC.WorkbookItem('1d0304cd-3796-429f-b815-7258370b9b74', show_tabs=True)
            single_workbook._id = '1f951daf-4061-451a-9df1-69a8062664f2'
            single_workbook.owner_id = 'dd2239f6-ddf1-4107-981a-4cf94e415794'
            single_workbook.name = 'renamedWorkbook'
            single_workbook.materialized_views_config = {'materialized_views_enabled': True,
                                                         'run_materialization_now': False}
            single_workbook = self.server.workbooks.update(single_workbook)

        self.assertEqual('1f951daf-4061-451a-9df1-69a8062664f2', single_workbook.id)
        self.assertEqual(True, single_workbook.show_tabs)
        self.assertEqual('1d0304cd-3796-429f-b815-7258370b9b74', single_workbook.project_id)
        self.assertEqual('dd2239f6-ddf1-4107-981a-4cf94e415794', single_workbook.owner_id)
        self.assertEqual('renamedWorkbook', single_workbook.name)
        self.assertEqual(True, single_workbook.materialized_views_config['materialized_views_enabled'])
        self.assertEqual(False, single_workbook.materialized_views_config['run_materialization_now'])
github tableau / server-client-python / test / test_workbook.py View on Github external
def test_update_missing_id(self):
        single_workbook = TSC.WorkbookItem('test')
        self.assertRaises(TSC.MissingRequiredFieldError, self.server.workbooks.update, single_workbook)
github tableau / server-client-python / test / test_workbook.py View on Github external
def test_populate_views_missing_id(self):
        single_workbook = TSC.WorkbookItem('test')
        self.assertRaises(TSC.MissingRequiredFieldError, self.server.workbooks.populate_views, single_workbook)
github tableau / server-client-python / test / test_workbook.py View on Github external
def test_update_copy_fields(self):
        with open(POPULATE_CONNECTIONS_XML, 'rb') as f:
            connection_xml = f.read().decode('utf-8')
        with open(UPDATE_XML, 'rb') as f:
            update_xml = f.read().decode('utf-8')
        with requests_mock.mock() as m:
            m.get(self.baseurl + '/1f951daf-4061-451a-9df1-69a8062664f2/connections', text=connection_xml)
            m.put(self.baseurl + '/1f951daf-4061-451a-9df1-69a8062664f2', text=update_xml)
            single_workbook = TSC.WorkbookItem('1d0304cd-3796-429f-b815-7258370b9b74')
            single_workbook._id = '1f951daf-4061-451a-9df1-69a8062664f2'
            self.server.workbooks.populate_connections(single_workbook)
            updated_workbook = self.server.workbooks.update(single_workbook)

        self.assertEqual(single_workbook._connections, updated_workbook._connections)
        self.assertEqual(single_workbook._views, updated_workbook._views)
        self.assertEqual(single_workbook.tags, updated_workbook.tags)
        self.assertEqual(single_workbook._initial_tags, updated_workbook._initial_tags)
        self.assertEqual(single_workbook._preview_image, updated_workbook._preview_image)
github tableau / server-client-python / test / test_workbook.py View on Github external
def test_populate_preview_image(self):
        with open(POPULATE_PREVIEW_IMAGE, 'rb') as f:
            response = f.read()
        with requests_mock.mock() as m:
            m.get(self.baseurl + '/1f951daf-4061-451a-9df1-69a8062664f2/previewImage', content=response)
            single_workbook = TSC.WorkbookItem('test')
            single_workbook._id = '1f951daf-4061-451a-9df1-69a8062664f2'
            self.server.workbooks.populate_preview_image(single_workbook)

            self.assertEqual(response, single_workbook.preview_image)
github tableau / server-client-python / test / test_workbook_model.py View on Github external
def test_invalid_project_id(self):
        self.assertRaises(ValueError, TSC.WorkbookItem, None)
        workbook = TSC.WorkbookItem("10")
        with self.assertRaises(ValueError):
            workbook.project_id = None
github tableau / server-client-python / test / test_workbook.py View on Github external
def test_publish_invalid_file_type(self):
        new_workbook = TSC.WorkbookItem('test', 'ee8c6e70-43b6-11e6-af4f-f7b0d8e20760')
        self.assertRaises(ValueError, self.server.workbooks.publish,
                          new_workbook, os.path.join(TEST_ASSET_DIR, 'SampleDS.tds'),
                          self.server.PublishMode.CreateNew)
github tableau / server-client-python / samples / initialize_server.py View on Github external
def publish_workbooks_to_site(server_object, project, folder):
    path = folder + '/*.twb*'

    for fname in glob.glob(path):
        new_workbook = TSC.WorkbookItem(project.id)
        new_workbook.show_tabs = True
        new_workbook = server_object.workbooks.publish(new_workbook, fname, server_object.PublishMode.Overwrite)
        print("Workbook published. ID: {0}".format(new_workbook.id))
github tableau / server-client-python / samples / move_workbook_sites.py View on Github external
error = "No site named {} found.".format(args.destination_site)
                    raise LookupError(error)

                tableau_auth.site_id = args.destination_site

                # Signing into another site requires another server object
                # because of the different auth token and site ID.
                with dest_server.auth.sign_in(tableau_auth):

                    # Step 5: Find destination site's default project
                    pagination_info, dest_projects = dest_server.projects.get()
                    target_project = next((project for project in dest_projects if project.is_default()), None)

                    # Step 6: If default project is found, form a new workbook item and publish.
                    if target_project is not None:
                        new_workbook = TSC.WorkbookItem(name=args.workbook_name, project_id=target_project.id)
                        new_workbook = dest_server.workbooks.publish(new_workbook, workbook_path,
                                                                     mode=TSC.Server.PublishMode.Overwrite)
                        print("Successfully moved {0} ({1})".format(new_workbook.name, new_workbook.id))
                    else:
                        error = "The default project could not be found."
                        raise LookupError(error)

                # Step 7: Delete workbook from source site and delete temp directory
                source_server.workbooks.delete(all_workbooks[0].id)

            finally:
                shutil.rmtree(tmpdir)
github tableau / server-client-python / samples / explore_workbook.py View on Github external
# SIGN IN
    tableau_auth = TSC.TableauAuth(args.username, password)
    server = TSC.Server(args.server)

    overwrite_true = TSC.Server.PublishMode.Overwrite

    with server.auth.sign_in(tableau_auth):

        # Publish workbook if publish flag is set (-publish, -p)
        if args.publish:
            all_projects, pagination_item = server.projects.get()
            default_project = next((project for project in all_projects if project.is_default()), None)

            if default_project is not None:
                new_workbook = TSC.WorkbookItem(default_project.id)
                new_workbook = server.workbooks.publish(new_workbook, args.publish, overwrite_true)
                print("Workbook published. ID: {}".format(new_workbook.id))
            else:
                print('Publish failed. Could not find the default project.')

        # Gets all workbook items
        all_workbooks, pagination_item = server.workbooks.get()
        print("\nThere are {} workbooks on site: ".format(pagination_item.total_available))
        print([workbook.name for workbook in all_workbooks])

        if all_workbooks:
            # Pick one workbook from the list
            sample_workbook = all_workbooks[0]

            # Populate views
            server.workbooks.populate_views(sample_workbook)