Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_publish_single_connection(self):
new_workbook = TSC.WorkbookItem(name='Sample', show_tabs=False,
project_id='ee8c6e70-43b6-11e6-af4f-f7b0d8e20760')
connection_creds = TSC.ConnectionCredentials('test', 'secret', True)
response = RequestFactory.Workbook._generate_xml(new_workbook, connection_credentials=connection_creds)
# Can't use ConnectionItem parser due to xml namespace problems
credentials = ET.fromstring(response).findall('.//connectionCredentials')
self.assertEqual(len(credentials), 1)
self.assertEqual(credentials[0].get('name', None), 'test')
self.assertEqual(credentials[0].get('password', None), 'secret')
self.assertEqual(credentials[0].get('embed', None), 'true')
def test_publish_single_connection(self):
new_datasource = TSC.DatasourceItem(name='Sample', project_id='ee8c6e70-43b6-11e6-af4f-f7b0d8e20760')
connection_creds = TSC.ConnectionCredentials('test', 'secret', True)
response = RequestFactory.Datasource._generate_xml(new_datasource, connection_credentials=connection_creds)
# Can't use ConnectionItem parser due to xml namespace problems
credentials = ET.fromstring(response).findall('.//connectionCredentials')
self.assertEqual(len(credentials), 1)
self.assertEqual(credentials[0].get('name', None), 'test')
self.assertEqual(credentials[0].get('password', None), 'secret')
self.assertEqual(credentials[0].get('embed', None), 'true')
def test_publish_multi_connection(self):
new_datasource = TSC.DatasourceItem(name='Sample', project_id='ee8c6e70-43b6-11e6-af4f-f7b0d8e20760')
connection1 = TSC.ConnectionItem()
connection1.server_address = 'mysql.test.com'
connection1.connection_credentials = TSC.ConnectionCredentials('test', 'secret', True)
connection2 = TSC.ConnectionItem()
connection2.server_address = 'pgsql.test.com'
connection2.connection_credentials = TSC.ConnectionCredentials('test', 'secret', True)
response = RequestFactory.Datasource._generate_xml(new_datasource, connections=[connection1, connection2])
# Can't use ConnectionItem parser due to xml namespace problems
connection_results = ET.fromstring(response).findall('.//connection')
self.assertEqual(connection_results[0].get('serverAddress', None), 'mysql.test.com')
self.assertEqual(connection_results[0].find('connectionCredentials').get('name', None), 'test')
self.assertEqual(connection_results[1].get('serverAddress', None), 'pgsql.test.com')
self.assertEqual(connection_results[1].find('connectionCredentials').get('password', None), 'secret')
def test_credentials_and_multi_connect_raises_exception(self):
new_datasource = TSC.DatasourceItem(name='Sample', project_id='ee8c6e70-43b6-11e6-af4f-f7b0d8e20760')
connection_creds = TSC.ConnectionCredentials('test', 'secret', True)
connection1 = TSC.ConnectionItem()
connection1.server_address = 'mysql.test.com'
connection1.connection_credentials = TSC.ConnectionCredentials('test', 'secret', True)
with self.assertRaises(RuntimeError):
response = RequestFactory.Datasource._generate_xml(new_datasource,
connection_credentials=connection_creds,
connections=[connection1])
def test_publish_multi_connection(self):
new_workbook = TSC.WorkbookItem(name='Sample', show_tabs=False,
project_id='ee8c6e70-43b6-11e6-af4f-f7b0d8e20760')
connection1 = TSC.ConnectionItem()
connection1.server_address = 'mysql.test.com'
connection1.connection_credentials = TSC.ConnectionCredentials('test', 'secret', True)
connection2 = TSC.ConnectionItem()
connection2.server_address = 'pgsql.test.com'
connection2.connection_credentials = TSC.ConnectionCredentials('test', 'secret', True)
response = RequestFactory.Workbook._generate_xml(new_workbook, connections=[connection1, connection2])
# Can't use ConnectionItem parser due to xml namespace problems
connection_results = ET.fromstring(response).findall('.//connection')
self.assertEqual(connection_results[0].get('serverAddress', None), 'mysql.test.com')
self.assertEqual(connection_results[0].find('connectionCredentials').get('name', None), 'test')
self.assertEqual(connection_results[1].get('serverAddress', None), 'pgsql.test.com')
self.assertEqual(connection_results[1].find('connectionCredentials').get('password', None), 'secret')
def test_credentials_and_multi_connect_raises_exception(self):
new_datasource = TSC.DatasourceItem(name='Sample', project_id='ee8c6e70-43b6-11e6-af4f-f7b0d8e20760')
connection_creds = TSC.ConnectionCredentials('test', 'secret', True)
connection1 = TSC.ConnectionItem()
connection1.server_address = 'mysql.test.com'
connection1.connection_credentials = TSC.ConnectionCredentials('test', 'secret', True)
with self.assertRaises(RuntimeError):
response = RequestFactory.Datasource._generate_xml(new_datasource,
connection_credentials=connection_creds,
connections=[connection1])
def test_credentials_and_multi_connect_raises_exception(self):
new_workbook = TSC.WorkbookItem(name='Sample', show_tabs=False,
project_id='ee8c6e70-43b6-11e6-af4f-f7b0d8e20760')
connection_creds = TSC.ConnectionCredentials('test', 'secret', True)
connection1 = TSC.ConnectionItem()
connection1.server_address = 'mysql.test.com'
connection1.connection_credentials = TSC.ConnectionCredentials('test', 'secret', True)
with self.assertRaises(RuntimeError):
response = RequestFactory.Workbook._generate_xml(new_workbook,
connection_credentials=connection_creds,
connections=[connection1])
def test_publish_multi_connection(self):
new_workbook = TSC.WorkbookItem(name='Sample', show_tabs=False,
project_id='ee8c6e70-43b6-11e6-af4f-f7b0d8e20760')
connection1 = TSC.ConnectionItem()
connection1.server_address = 'mysql.test.com'
connection1.connection_credentials = TSC.ConnectionCredentials('test', 'secret', True)
connection2 = TSC.ConnectionItem()
connection2.server_address = 'pgsql.test.com'
connection2.connection_credentials = TSC.ConnectionCredentials('test', 'secret', True)
response = RequestFactory.Workbook._generate_xml(new_workbook, connections=[connection1, connection2])
# Can't use ConnectionItem parser due to xml namespace problems
connection_results = ET.fromstring(response).findall('.//connection')
self.assertEqual(connection_results[0].get('serverAddress', None), 'mysql.test.com')
self.assertEqual(connection_results[0].find('connectionCredentials').get('name', None), 'test')
self.assertEqual(connection_results[1].get('serverAddress', None), 'pgsql.test.com')
self.assertEqual(connection_results[1].find('connectionCredentials').get('password', None), 'secret')
oauth_username = args.oauth_username
##### Save Oauth
if args.save_oauth:
save_oauth = True
# Change user name if oauth
if save_oauth:
db_username = oauth_username
if save_oauth:
embed = save_oauth
##### 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