From 9ea995a9647c03b6d146120208d1bd660db75d5d Mon Sep 17 00:00:00 2001 From: T8y8 Date: Tue, 26 Jul 2016 00:22:32 -0700 Subject: [PATCH 1/2] Basic connection retargeting. That is, you can change the database type. Other attributes are not yet supported --- tableaudocumentapi/connection.py | 64 ++++++++++++++++++++++++++++++++ test/bvt.py | 7 ++++ 2 files changed, 71 insertions(+) diff --git a/tableaudocumentapi/connection.py b/tableaudocumentapi/connection.py index 3e64c1b..fb889fd 100644 --- a/tableaudocumentapi/connection.py +++ b/tableaudocumentapi/connection.py @@ -4,6 +4,61 @@ # ############################################################################### +KNOWN_DB_CLASSES = ('msaccess', + 'msolap', + 'bigquery', + 'asterncluster', + 'bigsql', + 'aurora', + 'awshadoophive', + 'dataengine', + 'DataStax', + 'db2', + 'essbase', + 'exasolution', + 'excel', + 'excel-direct', + 'excel-reader', + 'firebird', + 'powerpivot', + 'genericodbc', + 'google-analytics', + 'googlecloudsql', + 'google-sheets', + 'greenplum', + 'saphana', + 'hadoophive', + 'hortonworkshadoophive', + 'maprhadoophive', + 'marklogic', + 'memsql', + 'mysql', + 'netezza', + 'oracle', + 'paraccel', + 'postgres', + 'progressopenedge', + 'redshift', + 'snowflake', + 'spark', + 'splunk', + 'kognitio', + 'sqlserver', + 'salesforce', + 'sapbw', + 'sybasease', + 'sybaseiq', + 'tbio', + 'teradata', + 'vectorwise', + 'vertica', + 'denormalized-cube', + 'csv', + 'textscan', + 'webdata', + 'webdata-direct', + 'cubeextract') + class Connection(object): """ @@ -111,3 +166,12 @@ def authentication(self): @property def dbclass(self): return self._class + + @dbclass.setter + def dbclass(self, value): + + if value not in KNOWN_DB_CLASSES: + raise AttributeError("'{}' is not a valid database type") + + self._class = value + self._connectionXML.set('dbclass', value) diff --git a/test/bvt.py b/test/bvt.py index 6a7cdf8..d26b91a 100644 --- a/test/bvt.py +++ b/test/bvt.py @@ -64,6 +64,13 @@ def test_can_write_attributes_to_connection(self): self.assertEqual(conn.username, 'bob') self.assertEqual(conn.server, 'mssql2014.test.tsi.lan') + def test_bad_dbclass_rasies_attribute_error(self): + conn = Connection(self.connection) + conn.dbclass = 'sqlserver' + self.assertEqual(conn.dbclass, 'sqlserver') + with self.assertRaises(AttributeError): + conn.dbclass = 'NotReal' + class DatasourceModelTests(unittest.TestCase): From b1571ef255a65c74f6279ca3cf00d6207e354e0f Mon Sep 17 00:00:00 2001 From: T8y8 Date: Tue, 26 Jul 2016 08:58:51 -0700 Subject: [PATCH 2/2] Move giant tuple and validating function into a new dbclass file --- tableaudocumentapi/connection.py | 60 ++------------------------------ tableaudocumentapi/dbclass.py | 60 ++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 57 deletions(-) create mode 100644 tableaudocumentapi/dbclass.py diff --git a/tableaudocumentapi/connection.py b/tableaudocumentapi/connection.py index fb889fd..ab4dcbb 100644 --- a/tableaudocumentapi/connection.py +++ b/tableaudocumentapi/connection.py @@ -3,61 +3,7 @@ # Connection - A class for writing connections to Tableau files # ############################################################################### - -KNOWN_DB_CLASSES = ('msaccess', - 'msolap', - 'bigquery', - 'asterncluster', - 'bigsql', - 'aurora', - 'awshadoophive', - 'dataengine', - 'DataStax', - 'db2', - 'essbase', - 'exasolution', - 'excel', - 'excel-direct', - 'excel-reader', - 'firebird', - 'powerpivot', - 'genericodbc', - 'google-analytics', - 'googlecloudsql', - 'google-sheets', - 'greenplum', - 'saphana', - 'hadoophive', - 'hortonworkshadoophive', - 'maprhadoophive', - 'marklogic', - 'memsql', - 'mysql', - 'netezza', - 'oracle', - 'paraccel', - 'postgres', - 'progressopenedge', - 'redshift', - 'snowflake', - 'spark', - 'splunk', - 'kognitio', - 'sqlserver', - 'salesforce', - 'sapbw', - 'sybasease', - 'sybaseiq', - 'tbio', - 'teradata', - 'vectorwise', - 'vertica', - 'denormalized-cube', - 'csv', - 'textscan', - 'webdata', - 'webdata-direct', - 'cubeextract') +from tableaudocumentapi.dbclass import is_valid_dbclass class Connection(object): @@ -170,8 +116,8 @@ def dbclass(self): @dbclass.setter def dbclass(self, value): - if value not in KNOWN_DB_CLASSES: - raise AttributeError("'{}' is not a valid database type") + if not is_valid_dbclass(value): + raise AttributeError("'{}' is not a valid database type".format(value)) self._class = value self._connectionXML.set('dbclass', value) diff --git a/tableaudocumentapi/dbclass.py b/tableaudocumentapi/dbclass.py new file mode 100644 index 0000000..b466452 --- /dev/null +++ b/tableaudocumentapi/dbclass.py @@ -0,0 +1,60 @@ + + +KNOWN_DB_CLASSES = ('msaccess', + 'msolap', + 'bigquery', + 'asterncluster', + 'bigsql', + 'aurora', + 'awshadoophive', + 'dataengine', + 'DataStax', + 'db2', + 'essbase', + 'exasolution', + 'excel', + 'excel-direct', + 'excel-reader', + 'firebird', + 'powerpivot', + 'genericodbc', + 'google-analytics', + 'googlecloudsql', + 'google-sheets', + 'greenplum', + 'saphana', + 'hadoophive', + 'hortonworkshadoophive', + 'maprhadoophive', + 'marklogic', + 'memsql', + 'mysql', + 'netezza', + 'oracle', + 'paraccel', + 'postgres', + 'progressopenedge', + 'redshift', + 'snowflake', + 'spark', + 'splunk', + 'kognitio', + 'sqlserver', + 'salesforce', + 'sapbw', + 'sybasease', + 'sybaseiq', + 'tbio', + 'teradata', + 'vectorwise', + 'vertica', + 'denormalized-cube', + 'csv', + 'textscan', + 'webdata', + 'webdata-direct', + 'cubeextract') + + +def is_valid_dbclass(dbclass): + return dbclass in KNOWN_DB_CLASSES