21
21
</connection>
22
22
</datasource>'''
23
23
24
- TABLEAU_CONNECTION_XML = ET .fromstring ('''<connection authentication='sspi' class='sqlserver' dbname='TestV1' odbc-native-protocol='yes' one-time-sql='' server='mssql2012.test.tsi.lan' username=''></connection>''' )
24
+ TABLEAU_CONNECTION_XML = ET .fromstring (
25
+ '''<connection authentication='sspi' class='sqlserver' dbname='TestV1' odbc-native-protocol='yes' one-time-sql='' server='mssql2012.test.tsi.lan' username=''>
10000
</connection>''' )
26
+
25
27
26
28
class HelperMethodTests (unittest .TestCase ):
27
29
@@ -35,18 +37,26 @@ def test_is_valid_file_with_invalid_inputs(self):
35
37
self .assertFalse (Workbook ._is_valid_file ('file1.tds2' ))
36
38
self .assertFalse (Workbook ._is_valid_file ('file2.twb3' ))
37
39
38
- class WorkbookModelTests (unittest .TestCase ):
40
+
41
+ class ConnectionModelTests (unittest .TestCase ):
39
42
40
43
def setUp (self ):
41
- self .workbook_file = tempfile .NamedTemporaryFile (suffix = '.twb' )
42
- self .workbook_file .write (TABLEAU_93_WORKBOOK .encode ('utf8' ))
43
- self .workbook_file .seek (0 )
44
+ self .connection = TABLEAU_CONNECTION_XML
45
+
46
+ def test_can_read_attributes_from_connection (self ):
47
+ conn = Connection (self .connection )
48
+ self .assertEqual (conn .dbname , 'TestV1' )
49
+ self .assertEqual (conn .username , '' )
50
+ self .assertEqual (conn .server , 'mssql2012.test.tsi.lan' )
51
+
52
+ def test_can_write_attributes_to_connection (self ):
53
+ conn = Connection (self .connection )
54
+ conn .dbname = 'BubblesInMyDrink'
55
+ conn .server = 'mssql2014.test.tsi.lan'
56
+ self .assertEqual (conn .dbname , 'BubblesInMyDrink' )
57
+ self .assertEqual (conn .username , '' )
58
+ self .assertEqual (conn .server , 'mssql2014.test.tsi.lan' )
44
59
45
- def test_can_extract_datasource (self ):
46
- wb = Workbook (self .workbook_file .name )
47
- self .assertEqual (len (wb .datasources ), 1 )
48
- self .assertIsInstance (wb .datasources [0 ], Datasource )
49
- self .assertEqual (wb .datasources [0 ].name , 'sqlserver.17u3bqc16tjtxn14e2hxh19tyvpo' )
50
60
51
61
class DatasourceModelTests (unittest .TestCase ):
52
62
@@ -63,28 +73,30 @@ def test_can_extract_datasource_from_file(self):
63
73
def test_can_extract_connection (self ):
64
74
ds = Datasource .from_file (self .tds_file .name )
65
75
self .assertIsInstance (ds .connection , Connection )
66
- self .assertEqual (ds .connection .dbname , 'TestV1' )
67
- self .assertEqual (ds .connection .server , 'mssql2012.test.tsi.lan' )
68
- self .assertEqual (ds .connection .username , '' )
69
76
70
- class ConnectionModelTests (unittest .TestCase ):
77
+
78
+ class WorkbookModelTests (unittest .TestCase ):
71
79
72
80
def setUp (self ):
73
- self .connection = TABLEAU_CONNECTION_XML
81
+ self .workbook_file = tempfile .NamedTemporaryFile (suffix = '.twb' )
82
+ self .workbook_file .write (TABLEAU_93_WORKBOOK .encode ('utf8' ))
83
+ self .workbook_file .seek (0 )
74
84
75
- def test_can_read_attributes_from_connection (self ):
76
- conn = Connection (self .connection )
77
- self .assertEqual (conn .dbname , 'TestV1' )
78
- self .assertEqual (conn .username , '' )
79
- self .assertEqual (conn .server , 'mssql2012.test.tsi.lan' )
85
+ def test_can_extract_datasource (self ):
86
+ wb = Workbook (self .workbook_file .name )
87
+ self .assertEqual (len (wb .datasources ), 1 )
88
+ self .assertIsInstance (wb .datasources [0 ], Datasource )
89
+ self .assertEqual (wb .datasources [0 ].name ,
90
+ 'sqlserver.17u3bqc16tjtxn14e2hxh19tyvpo' )
91
+
92
+ def test_can_update_datasource_connection_and_save (self ):
93
+ original_wb = Workbook (self .workbook_file .name )
94
+ original_wb .datasources [0 ].connection .dbname = 'newdb.test.tsi.lan'
95
+ original_wb .save ()
96
+
97
+ new_wb = Workbook (self .workbook_file .name )
98
+ self .assertEqual (new_wb .datasources [0 ].connection .dbname , 'newdb.test.tsi.lan' )
80
99
81
- def test_can_write_attributes_to_connection (self ):
82
- conn = Connection (self .connection )
83
- conn .dbname = 'BubblesInMyDrink'
84
- conn .server = 'mssql2014.test.tsi.lan'
85
- self .assertEqual (conn .dbname , 'BubblesInMyDrink' )
86
- self .assertEqual (conn .username , '' )
87
- self .assertEqual (conn .server , 'mssql2014.test.tsi.lan' )
88
100
89
101
if __name__ == '__main__' :
90
102
unittest .main ()
0 commit comments