Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
self.ds = Datasource.from_file(TEST_TDS_FILE)
self.to_delete = set()
def test_can_open_tdsx_and_save_changes(self):
original_tdsx = Datasource.from_file(self.tdsx_file.name)
original_tdsx.connections[0].server = 'newdb'
original_tdsx.save()
new_tdsx = Datasource.from_file(self.tdsx_file.name)
self.assertEqual(new_tdsx.connections[
0].server, 'newdb')
def test_can_open_tdsx_and_save_as_changes(self):
new_tdsx_filename = 'newtdsx.tdsx'
original_wb = Datasource.from_file(self.tdsx_file.name)
original_wb.connections[0].server = 'newdb'
original_wb.save_as(new_tdsx_filename)
new_wb = Datasource.from_file(new_tdsx_filename)
self.assertEqual(new_wb.connections[
0].server, 'newdb')
os.unlink(new_tdsx_filename)
def test_can_extract_datasource(self):
wb = Workbook(self.workbook_file.name)
self.assertEqual(len(wb.datasources), 1)
self.assertIsInstance(wb.datasources[0], Datasource)
self.assertEqual(wb.datasources[0].name,
'sqlserver.17u3bqc16tjtxn14e2hxh19tyvpo')
def test_can_extract_datasource(self):
wb = Workbook(self.workbook_file.name)
self.assertEqual(len(wb.datasources), 1)
self.assertIsInstance(wb.datasources[0], Datasource)
self.assertEqual(wb.datasources[0].name,
'sqlserver.17u3bqc16tjtxn14e2hxh19tyvpo')
def test_description_unicode(self):
ds = Datasource.from_file(TEST_UNICODE_FILE)
self.assertIsNotNone(ds.fields['A'].description)
############################################################
# Step 1) Use Datasource object from the Document API
############################################################
from tableaudocumentapi import Datasource
############################################################
# Step 2) Open the .tds we want to replicate
############################################################
sourceTDS = Datasource.from_file('world.tds')
############################################################
# Step 3) List out info from the TDS
############################################################
print('----------------------------------------------------------')
print('-- Info for our .tds:')
print('-- name:\t{0}'.format(sourceTDS.name))
print('-- version:\t{0}'.format(sourceTDS.version))
print('----------------------------------------------------------')
############################################################
# Step 1) Use Datasource object from the Document API
############################################################
from tableaudocumentapi import Datasource
############################################################
# Step 2) Open the .tds we want to inspect
############################################################
sourceTDS = Datasource.from_file('World.tds')
############################################################
# Step 3) Print out all of the fields and what type they are
############################################################
print('----------------------------------------------------------')
print('--- {} total fields in this datasource'.format(len(sourceTDS.fields)))
print('----------------------------------------------------------')
for count, field in enumerate(sourceTDS.fields.values()):
print('{:>4}: {} is a {}'.format(count+1, field.name, field.datatype))
blank_line = False
if field.calculation:
print(' the formula is {}'.format(field.calculation))
blank_line = True
if field.default_aggregation:
print(' the default aggregation is {}'.format(field.default_aggregation))
blank_line = True