1717TABLEAU_CONNECTION_XML = ET .fromstring (
1818 '''<connection authentication='sspi' class='sqlserver' dbname='TestV1' odbc-native-protocol='yes' one-time-sql='' server='mssql2012.test.tsi.lan' username=''></connection>''' )
1919
20+
2021class HelperMethodTests (unittest .TestCase ):
2122
2223 def test_is_valid_file_with_valid_inputs (self ):
@@ -39,7 +40,6 @@ def test_can_extract_legacy_connection(self):
3940 self .assertIsInstance (connections [0 ], Connection )
4041 self .assertEqual (connections [0 ].dbname , 'TestV1' )
4142
42-
4343 def test_can_extract_federated_connections (self ):
4444 parser = ConnectionParser (ET .fromstring (TABLEAU_10_TDS ), '10.0' )
4545 connections = parser .get_connections ()
@@ -97,6 +97,17 @@ def test_can_save_tds(self):
9797 new_tds = Datasource .from_file (self .tds_file .name )
9898 self .assertEqual (new_tds .connections [0 ].dbname , 'newdb.test.tsi.lan' )
9999
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+
100111
101112class WorkbookModelTests (unittest .TestCase ):
102113
@@ -122,7 +133,8 @@ def test_can_update_datasource_connection_and_save(self):
122133 original_wb .save ()
123134
124135 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' )
126138
127139
128140class WorkbookModelV10Tests (unittest .TestCase ):
@@ -152,7 +164,19 @@ def test_can_update_datasource_connection_and_saveV10(self):
152164 original_wb .save ()
153165
154166 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'?>" )
156180
157181if __name__ == '__main__' :
158182 unittest .main ()
0 commit comments