17
17
TABLEAU_CONNECTION_XML = ET .fromstring (
18
18
'''<connection authentication='sspi' class='sqlserver' dbname='TestV1' odbc-native-protocol='yes' one-time-sql='' server='mssql2012.test.tsi.lan' username=''></connection>''' )
19
19
20
+
20
21
class HelperMethodTests (unittest .TestCase ):
21
22
22
23
def test_is_valid_file_with_valid_inputs (self ):
@@ -39,7 +40,6 @@ def test_can_extract_legacy_connection(self):
39
40
self .assertIsInstance (connections [0 ], Connection )
40
41
self .assertEqual (connections [0 ].dbname , 'TestV1' )
41
42
42
-
43
43
def test_can_extract_federated_connections (self ):
44
44
parser = ConnectionParser (ET .fromstring (TABLEAU_10_TDS ), '10.0' )
45
45
connections = parser .get_connections ()
@@ -97,6 +97,17 @@ def test_can_save_tds(self):
97
97
new_tds = Datasource .from_file (self .tds_file .name )
98
98
self .assertEqual (new_tds .connections [0 ].dbname , 'newdb.test.tsi.lan' )
99
99
100
+ def test_save_has_xml_declaration (self ):
101
+ original_tds = Datasource .from_file (self .tds_file .name )
102
+ original_tds .connections [0 ].dbname = 'newdb.test.tsi.lan'
103
+
104
+ original_tds .save ()
105
+
106
+ with open (self .tds_file .name ) as f :
107
+ first_line = f .readline ().strip () # first line should be xml tag
108
+ self .assertEqual (
109
+ first_line , "<?xml version='1.0' encoding='utf-8'?>" )
110
+
100
111
101
112
class WorkbookModelTests (unittest .TestCase ):
102
113
@@ -122,7 +133,8 @@ def test_can_update_datasource_connection_and_save(self):
122
133
original_wb .save ()
123
134
124
135
new_wb = Workbook (self .workbook_file .name )
125
- self .assertEqual (new_wb .datasources [0 ].connections [0 ].dbname , 'newdb.test.tsi.lan' )
136
+ self .assertEqual (new_wb .datasources [0 ].connections [
137
+ 0 ].dbname , 'newdb.test.tsi.lan' )
126
138
127
139
128
140
class WorkbookModelV10Tests (unittest .TestCase ):
@@ -152,7 +164,19 @@ def test_can_update_datasource_connection_and_saveV10(self):
152
164
original_wb .save ()
153
165
154
166
new_wb = Workbook (self .workbook_file .name )
155
- self .assertEqual (new_wb .datasources [0 ].connections [0 ].dbname , 'newdb.test.tsi.lan' )
167
+ self .assertEqual (new_wb .datasources [0 ].connections [
168
+ 0 ].dbname , 'newdb.test.tsi.lan' )
169
+
170
+ def test_save_has_xml_declaration (self ):
171
+ original_wb = Workbook (self .workbook_file .name )
172
+ original_wb .datasources [0 ].connections [0 ].dbname = 'newdb.test.tsi.lan'
173
+
174
+ original_wb .save ()
175
+
176
+ with open (self .workbook_file .name ) as f :
177
+ first_line = f .readline ().strip () # first line should be xml tag
178
+ self .assertEqual (
179
+ first_line , "<?xml version='1.0' encoding='utf-8'?>" )
156
180
157
181
if __name__ == '__main__' :
158
182
unittest .main ()
0 commit comments