From f8bf9c97ce5bce8ab3c1bbed87b754c56360990e Mon Sep 17 00:00:00 2001 From: Russell Hay Date: Thu, 29 Sep 2016 15:31:01 -0700 Subject: [PATCH 1/4] Fixing xfile's save_as functionality for non .t*x files --- tableaudocumentapi/xfile.py | 6 +++--- test/bvt.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/tableaudocumentapi/xfile.py b/tableaudocumentapi/xfile.py index 66e5aac..3067781 100644 --- a/tableaudocumentapi/xfile.py +++ b/tableaudocumentapi/xfile.py @@ -105,10 +105,10 @@ def save_into_archive(xml_tree, filename, new_filename=None): def _save_file(container_file, xml_tree, new_filename=None): - if container_file is None: - container_file = new_filename + if new_filename is None: + new_filename = container_file if zipfile.is_zipfile(container_file): save_into_archive(xml_tree, container_file, new_filename) else: - xml_tree.write(container_file, encoding="utf-8", xml_declaration=True) + xml_tree.write(new_filename, encoding="utf-8", xml_declaration=True) diff --git a/test/bvt.py b/test/bvt.py index 60e42c3..21313dd 100644 --- a/test/bvt.py +++ b/test/bvt.py @@ -164,6 +164,24 @@ def test_can_save_tds(self): new_tds = Datasource.from_file(self.tds_file.name) self.assertEqual(new_tds.connections[0].dbname, 'newdb') + def test_can_save_as_tds(self): + new_filename = os.path.join( + os.path.dirname(self.tds_file.name), + "new_{}".format(os.path.basename(self.tds_file.name)) + ) + + try: + original_tds = Datasource.from_file(self.tds_file.name) + original_tds.connections[0].dbname = 'newdb' + + original_tds.save_as(new_filename) + + new_tds = Datasource.from_file(new_filename) + self.assertEqual(new_tds.connections[0].dbname, 'newdb') + finally: + if os.path.exists(new_filename): + os.unlink(new_filename) + class DatasourceModelV10TDSXTests(unittest.TestCase): From c1cd59bf612c1578c6aaf61ace4eed8251aedb7b Mon Sep 17 00:00:00 2001 From: Russell Hay Date: Thu, 29 Sep 2016 15:31:48 -0700 Subject: [PATCH 2/4] Add the ability to clear repository location on the datasource for retargetting --- tableaudocumentapi/connection.py | 1 + tableaudocumentapi/datasource.py | 4 + test/assets/datasource_test.tds | 187 ++++++++++++++++--------------- test/test_datasource.py | 13 +++ 4 files changed, 112 insertions(+), 93 deletions(-) diff --git a/tableaudocumentapi/connection.py b/tableaudocumentapi/connection.py index 8e9eb58..8cfdd87 100644 --- a/tableaudocumentapi/connection.py +++ b/tableaudocumentapi/connection.py @@ -118,6 +118,7 @@ def username(self, value): def authentication(self): return self._authentication + ########### # dbclass ########### diff --git a/tableaudocumentapi/datasource.py b/tableaudocumentapi/datasource.py index 69318ed..24c58f7 100644 --- a/tableaudocumentapi/datasource.py +++ b/tableaudocumentapi/datasource.py @@ -213,6 +213,10 @@ def version(self): def connections(self): return self._connections + def clear_repository_location(self): + tag = self._datasourceXML.find('./repository-location') + self._datasourceXML.remove(tag) + ########### # fields ########### diff --git a/test/assets/datasource_test.tds b/test/assets/datasource_test.tds index bfab77b..5f280eb 100644 --- a/test/assets/datasource_test.tds +++ b/test/assets/datasource_test.tds @@ -1,93 +1,94 @@ - - - - - - - a - 130 - [a] - [xy] - a - 1 - string - Count - 255 - true - - "SQL_WVARCHAR" - "SQL_C_WCHAR" - "true" - - - - Today's Date - 130 - [Today's Date] - [xy] - a - 1 - string - Count - 255 - true - - "SQL_WVARCHAR" - "SQL_C_WCHAR" - "true" - - - - x - 3 - [x] - [xy] - x - 2 - integer - Sum - 10 - true - - "SQL_INTEGER" - "SQL_C_SLONG" - - - - y - 3 - [y] - [xy] - y - 3 - integer - Sum - 10 - true - - "SQL_INTEGER" - "SQL_C_SLONG" - - - - - - - - - - - - A thing - Something will go here too, in a muted gray - - - - - - - - - - - + + + + + + + + a + 130 + [a] + [xy] + a + 1 + string + Count + 255 + true + + "SQL_WVARCHAR" + "SQL_C_WCHAR" + "true" + + + + Today's Date + 130 + [Today's Date] + [xy] + a + 1 + string + Count + 255 + true + + "SQL_WVARCHAR" + "SQL_C_WCHAR" + "true" + + + + x + 3 + [x] + [xy] + x + 2 + integer + Sum + 10 + true + + "SQL_INTEGER" + "SQL_C_SLONG" + + + + y + 3 + [y] + [xy] + y + 3 + integer + Sum + 10 + true + + "SQL_INTEGER" + "SQL_C_SLONG" + + + + + + + + + + + + A thing + Something will go here too, in a muted gray + + + + + + + + + + + diff --git a/test/test_datasource.py b/test/test_datasource.py index 66b3f79..baf5bc3 100644 --- a/test/test_datasource.py +++ b/test/test_datasource.py @@ -63,6 +63,19 @@ def test_datasource_field_description(self): self.assertIsNotNone(actual) self.assertTrue(u'muted gray' in actual) + def test_datasource_clear_repository_location(self): + filename = os.path.join(TEST_ASSET_DIR, 'clear-repository-test.tds') + + self.assertIsNotNone(self.ds._datasourceXML.find('.//repository-location')) + self.ds.clear_repository_location() + try: + self.ds.save_as(filename) + with open(filename, 'r') as newfile: + self.assertFalse('repository-location' in newfile.read()) + finally: + if os.path.exists(filename): + os.unlink(filename) + class DataSourceFieldsTWB(unittest.TestCase): From bd3dda62b3d8bec07bb6ee3b79b314965b729c45 Mon Sep 17 00:00:00 2001 From: Russell Hay Date: Thu, 29 Sep 2016 15:34:41 -0700 Subject: [PATCH 3/4] fixing a pep8 issue that was missed --- tableaudocumentapi/connection.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tableaudocumentapi/connection.py b/tableaudocumentapi/connection.py index 8cfdd87..8e9eb58 100644 --- a/tableaudocumentapi/connection.py +++ b/tableaudocumentapi/connection.py @@ -118,7 +118,6 @@ def username(self, value): def authentication(self): return self._authentication - ########### # dbclass ########### From 49713a8f51cdef054fbdb6995388250b7cf7f980 Mon Sep 17 00:00:00 2001 From: Russell Hay Date: Tue, 4 Oct 2016 11:09:19 -0700 Subject: [PATCH 4/4] Adding None check for repository-location in case it doesn't exist --- tableaudocumentapi/datasource.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tableaudocumentapi/datasource.py b/tableaudocumentapi/datasource.py index 24c58f7..88a2b29 100644 --- a/tableaudocumentapi/datasource.py +++ b/tableaudocumentapi/datasource.py @@ -215,7 +215,8 @@ def connections(self): def clear_repository_location(self): tag = self._datasourceXML.find('./repository-location') - self._datasourceXML.remove(tag) + if tag is not None: + self._datasourceXML.remove(tag) ########### # fields pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy