| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -72,7 +72,7 @@ def save(self): | |||
| 72 | 72 | """ | |
| 73 | 73 | ||
| 74 | 74 | # save the file | |
| 75 | - self._datasourceTree.write(self._filename) | ||
| 75 | + self._datasourceTree.write(self._filename, encoding="utf-8", xml_declaration=True) | ||
| 76 | 76 | ||
| 77 | 77 | def save_as(self, new_filename): | |
| 78 | 78 | """ | |
@@ -85,7 +85,7 @@ def save_as(self, new_filename): | |||
| 85 | 85 | Nothing. | |
| 86 | 86 | ||
| 87 | 87 | """ | |
| 88 | - self._datasourceTree.write(new_filename) | ||
| 88 | + self._datasourceTree.write(new_filename, encoding="utf-8", xml_declaration=True) | ||
| 89 | 89 | ||
| 90 | 90 | ########### | |
| 91 | 91 | # name | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -76,7 +76,7 @@ def save(self): | |||
| 76 | 76 | """ | |
| 77 | 77 | ||
| 78 | 78 | # save the file | |
| 79 | - self._workbookTree.write(self._filename) | ||
| 79 | + self._workbookTree.write(self._filename, encoding="utf-8", xml_declaration=True) | ||
| 80 | 80 | ||
| 81 | 81 | def save_as(self, new_filename): | |
| 82 | 82 | """ | |
@@ -90,7 +90,7 @@ def save_as(self, new_filename): | |||
| 90 | 90 | ||
| 91 | 91 | """ | |
| 92 | 92 | ||
| 93 | - self._workbookTree.write(new_filename) | ||
| 93 | + self._workbookTree.write(new_filename, encoding="utf-8", xml_declaration=True) | ||
| 94 | 94 | ||
| 95 | 95 | ########################################################################### | |
| 96 | 96 | # | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,7 @@ | |||
| 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() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments