10000 Basic connection class retargeting (#65) · onware/document-api-python@44ca620 · GitHub
[go: up one dir, main page]

Skip to content

Commit 44ca620

Browse files
authored
Basic connection class retargeting (tableau#65)
- 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!
1 parent aa93eef commit 44ca620

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

tableaudocumentapi/connection.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Connection - A class for writing connections to Tableau files
44
#
55
###############################################################################
6+
from tableaudocumentapi.dbclass import is_valid_dbclass
67

78

89
class Connection(object):
@@ -111,3 +112,12 @@ def authentication(self):
111112
@property
112113
def dbclass(self):
113114
return self._class
115+
116+
@dbclass.setter
117+
def dbclass(self, value):
118+
119+
if not is_valid_dbclass(value):
120+
raise AttributeError("'{}' is not a valid database type".format(value))
121+
122+
self._class = value
123+
self._connectionXML.set('dbclass', value)

tableaudocumentapi/dbclass.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
3+
KNOWN_DB_CLASSES = ('msaccess',
4+
'msolap',
5+
'bigquery',
6+
'asterncluster',
7+
'bigsql',
8+
'aurora',
9+
'awshadoophive',
10+
'dataengine',
11+
'DataStax',
12+
'db2',
13+
'essbase',
14+
'exasolution',
15+
'excel',
16+
'excel-direct',
17+
'excel-reader',
18+
'firebird',
19+
'powerpivot',
20+
'genericodbc',
21+
'google-analytics',
22+
'googlecloudsql',
23+
'google-sheets',
24+
'greenplum',
25+
'saphana',
26+
'hadoophive',
27+
'hortonworkshadoophive',
28+
'maprhadoophive',
29+
'marklogic',
30+
'memsql',
31+
'mysql',
32+
'netezza',
33+
'oracle',
34+
'paraccel',
35+
'postgres',
36+
'progressopenedge',
37+
'redshift',
38+
'snowflake',
39+
'spark',
40+
'splunk',
41+
'kognitio',
42+
'sqlserver',
43+
'salesforce',
44+
'sapbw',
45+
'sybasease',
46+
'sybaseiq',
47+
'tbio',
48+
'teradata',
49+
'vectorwise',
50+
'vertica',
51+
'denormalized-cube',
52+
'csv',
53+
'textscan',
54+
'webdata',
55+
'webdata-direct',
56+
'cubeextract')
57+
58+
59+
def is_valid_dbclass(dbclass):
60+
return dbclass in KNOWN_DB_CLASSES

test/bvt.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ def test_can_write_attributes_to_connection(self):
6464
self.assertEqual(conn.username, 'bob')
6565
self.assertEqual(conn.server, 'mssql2014.test.tsi.lan')
6666

67+
def test_bad_dbclass_rasies_attribute_error(self):
68+
conn = Connection(self.connection)
69+
conn.dbclass = 'sqlserver'
70+
self.assertEqual(conn.dbclass, 'sqlserver')
71+
with self.assertRaises(AttributeError):
72+
conn.dbclass = 'NotReal'
73+
6774

6875
class DatasourceModelTests(unittest.TestCase):
6976

0 commit comments

Comments
 (0)
0