How to use the tableauserverclient.DatasourceItem 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_datasource.py View on Github external
def test_publish(self):
        response_xml = read_xml_asset(PUBLISH_XML)
        with requests_mock.mock() as m:
            m.post(self.baseurl, text=response_xml)
            new_datasource = TSC.DatasourceItem('SampleDS', 'ee8c6e70-43b6-11e6-af4f-f7b0d8e20760')
            publish_mode = self.server.PublishMode.CreateNew

            new_datasource = self.server.datasources.publish(new_datasource,
                                                             asset('SampleDS.tds'),
                                                             mode=publish_mode)

        self.assertEqual('e76a1461-3b1d-4588-bf1b-17551a879ad9', new_datasource.id)
        self.assertEqual('SampleDS', new_datasource.name)
        self.assertEqual('SampleDS', new_datasource.content_url)
        self.assertEqual('dataengine', new_datasource.datasource_type)
        self.assertEqual('2016-08-11T21:22:40Z', format_datetime(new_datasource.created_at))
        self.assertEqual('2016-08-17T23:37:08Z', format_datetime(new_datasource.updated_at))
        self.assertEqual('ee8c6e70-43b6-11e6-af4f-f7b0d8e20760', new_datasource.project_id)
        self.assertEqual('default', new_datasource.project_name)
        self.assertEqual('5de011f8-5aa9-4d5b-b991-f462c8dd6bb7', new_datasource.owner_id)
github tableau / server-client-python / test / test_datasource.py View on Github external
def test_publish_invalid_file_type(self):
        new_datasource = TSC.DatasourceItem('test', 'ee8c6e70-43b6-11e6-af4f-f7b0d8e20760')
        self.assertRaises(ValueError, self.server.datasources.publish, new_datasource,
                          asset('SampleWB.twbx'), self.server.PublishMode.Append)
github tableau / server-client-python / test / test_datasource.py View on Github external
def test_publish_missing_mode(self):
        new_datasource = TSC.DatasourceItem('test', 'ee8c6e70-43b6-11e6-af4f-f7b0d8e20760')
        self.assertRaises(ValueError, self.server.datasources.publish, new_datasource,
                          asset('SampleDS.tds'), None)
github tableau / server-client-python / test / test_datasource.py View on Github external
def test_populate_connections(self):
        response_xml = read_xml_asset(POPULATE_CONNECTIONS_XML)
        with requests_mock.mock() as m:
            m.get(self.baseurl + '/9dbd2263-16b5-46e1-9c43-a76bb8ab65fb/connections', text=response_xml)
            single_datasource = TSC.DatasourceItem('test', '1d0304cd-3796-429f-b815-7258370b9b74')
            single_datasource.owner_id = 'dd2239f6-ddf1-4107-981a-4cf94e415794'
            single_datasource._id = '9dbd2263-16b5-46e1-9c43-a76bb8ab65fb'
            self.server.datasources.populate_connections(single_datasource)
            self.assertEqual('9dbd2263-16b5-46e1-9c43-a76bb8ab65fb', single_datasource.id)
            connections = single_datasource.connections

        self.assertTrue(connections)
        ds1, ds2 = connections
        self.assertEqual('be786ae0-d2bf-4a4b-9b34-e2de8d2d4488', ds1.id)
        self.assertEqual('textscan', ds1.connection_type)
        self.assertEqual('forty-two.net', ds1.server_address)
        self.assertEqual('duo', ds1.username)
        self.assertEqual(True, ds1.embed_password)
        self.assertEqual('970e24bc-e200-4841-a3e9-66e7d122d77e', ds2.id)
        self.assertEqual('sqlserver', ds2.connection_type)
        self.assertEqual('database.com', ds2.server_address)
github tableau / server-client-python / test / test_datasource.py View on Github external
def test_update_copy_fields(self):
        with open(asset(UPDATE_XML), 'rb') as f:
            response_xml = f.read().decode('utf-8')
        with requests_mock.mock() as m:
            m.put(self.baseurl + '/9dbd2263-16b5-46e1-9c43-a76bb8ab65fb', text=response_xml)
            single_datasource = TSC.DatasourceItem('test', '1d0304cd-3796-429f-b815-7258370b9b74')
            single_datasource._id = '9dbd2263-16b5-46e1-9c43-a76bb8ab65fb'
            single_datasource._project_name = 'Tester'
            updated_datasource = self.server.datasources.update(single_datasource)

        self.assertEqual(single_datasource.tags, updated_datasource.tags)
        self.assertEqual(single_datasource._project_name, updated_datasource._project_name)
github tableau / server-client-python / test / test_datasource_model.py View on Github external
def test_invalid_project_id(self):
        self.assertRaises(ValueError, TSC.DatasourceItem, None)
        datasource = TSC.DatasourceItem("10")
        with self.assertRaises(ValueError):
            datasource.project_id = None
github dataiku / dataiku-contrib / tableau-hyper-export / python-exporters / tableau-hyper_upload / exporter.py View on Github external
def close(self):
        """
        Perform any necessary cleanup
        """
        self.e.close()
        tableau_auth = TSC.TableauAuth(self.username, self.password, site_id=self.site_id)
        server = TSC.Server(self.server_url, use_server_version=True)
        
        server.auth.sign_in(tableau_auth)
        
        try:
            if self.datasource:
                server.datasources.publish(self.datasource, self.output_file, 'Overwrite', connection_credentials=None)
            else:
                new_datasource = TSC.DatasourceItem(self.project.id, name=self.output_table)
                new_datasource = server.datasources.publish(new_datasource, self.output_file, 'CreateNew')
        except:
            raise
        finally:
            server.auth.sign_out()
            os.remove(self.output_file)
github tableau / server-client-python / samples / tabcmd.py View on Github external
##### Connection credentials
        if (db_username and db_password):
            connection_credentials = TSC.ConnectionCredentials(db_username, db_password, embed, save_oauth)

        ## Append
        if args.append:
            publish_mode = TSC.Server.PublishMode.Append
        
        ###################################
        # Logic for different file types
        ###################################
        ##### Datasource
        if our_file_type == self.TableauFileType.Datasource:
            print('Processing a datasource...')

            datasource_item = TSC.DatasourceItem(target_project.id, name)

            if publish_mode == TSC.Server.PublishMode.Overwrite:
                # Use a filter to get the existing workbook
                request_options = TSC.RequestOptions()
                request_options.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, name))

                all_datasources = list(TSC.Pager(server.datasources, request_options))
                datasource_item = all_datasources[0]

            server.datasources.publish(datasource_item, our_file, publish_mode, connection_credentials)
        
        ##### Extract
        elif our_file_type == self.TableauFileType.Extract:
            print('Processing an extract...')

            ## Replace
github tableau / server-client-python / samples / tabcmd.py View on Github external
request_options.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, name))

                all_datasources = list(TSC.Pager(server.datasources, request_options))
                datasource_item = all_datasources[0]

            server.datasources.publish(datasource_item, our_file, publish_mode, connection_credentials)
        
        ##### Extract
        elif our_file_type == self.TableauFileType.Extract:
            print('Processing an extract...')

            ## Replace
            if args.replace:
                publish_mode = TSC.Server.PublishMode.Overwrite
                
            extract_item = TSC.DatasourceItem(target_project.id, name)

            server.datasources.publish(extract_item, our_file, publish_mode)
        
        ##### Workbook
        elif our_file_type == self.TableauFileType.Workbook:
            print('Processing a workbook...')

            workbook_item = TSC.WorkbookItem(target_project.id, name, tabbed)

            if publish_mode == TSC.Server.PublishMode.Overwrite:
                # Use a filter to get the existing workbook
                request_options = TSC.RequestOptions()
                request_options.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, name))

                all_workbooks = list(TSC.Pager(server.workbooks, request_options))
                workbook_item = all_workbooks[0]
github tableau / server-client-python / samples / initialize_server.py View on Github external
def publish_datasources_to_site(server_object, project, folder):
    path = folder + '/*.tds*'

    for fname in glob.glob(path):
        new_ds = TSC.DatasourceItem(project.id)
        new_ds = server_object.datasources.publish(new_ds, fname, server_object.PublishMode.Overwrite)
        print("Datasource published. ID: {0}".format(new_ds.id))