Skip to content

Commit

Permalink
Basic connection class retargeting (#65)
Browse files Browse the repository at this point in the history
- Allow modification of dbclass attribute
- Only allow updates to a valid (known) dbclass type.

That is, you can change the database type. 
Other attributes (like ssl and all the various auth modes are not yet supported)

Now you can take: mysql-test-db.yourcompany.com, and move it to postgres-prod-db.yourcompany.com and update the dbclass to match!
  • Loading branch information
t8y8 authored Jul 27, 2016
1 parent aa93eef commit 44ca620
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tableaudocumentapi/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Connection - A class for writing connections to Tableau files
#
###############################################################################
from tableaudocumentapi.dbclass import is_valid_dbclass


class Connection(object):
Expand Down Expand Up @@ -111,3 +112,12 @@ def authentication(self):
@property
def dbclass(self):
return self._class

@dbclass.setter
def dbclass(self, value):

if not is_valid_dbclass(value):
raise AttributeError("'{}' is not a valid database type".format(value))

self._class = value
self._connectionXML.set('dbclass', value)
60 changes: 60 additions & 0 deletions tableaudocumentapi/dbclass.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions test/bvt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down

0 comments on commit 44ca620

Please sign in to comment.