FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add caption support for datasources by graysonarts · Pull Request #99 · tableau/document-api-python · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .tds  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
15 changes: 15 additions & 0 deletions tableaudocumentapi/datasource.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def __init__(self, dsxml, filename=None):
self._name = self._datasourceXML.get('name') or self._datasourceXML.get(
'formatted-name') # TDS files don't have a name attribute
self._version = self._datasourceXML.get('version')
self._caption = self._datasourceXML.get('caption', '')
self._connection_parser = ConnectionParser(
self._datasourceXML, version=self._version)
self._connections = self._connection_parser.get_connections()
Expand Down Expand Up @@ -207,6 +208,20 @@ def name(self):
def version(self):
return self._version

@property
def caption(self):
return self._caption

@caption.setter

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Are all datasources guaranteed to have a caption or would you ever want to remove it?

We could apply the None strategy like we do for port

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think it's more idiomatic to do del ds.caption

def caption(self, value):
self._datasourceXML.set('caption', value)
self._caption = value

@caption.deleter
def caption(self):
del self._datasourceXML.attrib['caption']
self._caption = ''

###########
# connections
###########
Expand Down
3 changes: 2 additions & 1 deletion test/assets/datasource_test.tds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version='1.0' encoding='utf-8' ?>
<datasource formatted-name='postgres.1of3kl00aoax5d1a1ejma1397430' inline='true' source-platform='mac' version='9.3' xmlns:user='http://www.tableausoftware.com/xml/user'>
<datasource caption='foo' formatted-name='postgres.1of3kl00aoax5d1a1ejma1397430' inline='true' source-platform='mac'
version='9.3' xmlns:user='http://www.tableausoftware.com/xml/user'>
<repository-location />
<connection authentication='username-password' class='postgres' dbname='TestV1' odbc-native-protocol='yes' port='5432' server='postgres91.test.tsi.lan' username='test'>
<relation name='xy' table='[public].[xy]' type='table' />
Expand Down
43 changes: 42 additions & 1 deletion test/test_datasource.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import unittest
import os
import os.path
import shutil
import tempfile
import unittest


from tableaudocumentapi import Datasource, Workbook

Expand All @@ -22,6 +26,19 @@ class DataSourceFieldsTDS(unittest.TestCase):

def setUp(self):
self.ds = Datasource.from_file(TEST_TDS_FILE)
self.to_delete = set()

def cleanUp(self):
for path in self.to_delete:
if os.path.isdir(path):
shutil.rmtree(path, ignore_errors=True)
elif os.path.isfile(path):
os.unlink(path)

def get_temp_file(self, filename):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We have 3 ways of doing temp file management now.

xfile.temporary_directory has a context manager that creates and deletes a temp dir
bvt.py does a less advanced version of your cleanup methods here
Then these cleanup methods here.

This can be another PR, maybe we want to unify them, at least across the tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Agreed, I'll do a pass to create a "temp file wrapper that both library code and tests can use" along with the auto clean up base test class.

tempdir = tempfile.mkdtemp('tda-datasource')
self.to_delete.add(tempdir)
return os.path.join(tempdir, filename)

def test_datasource_returns_correct_fields(self):
self.assertIsNotNone(self.ds.fields)
Expand Down Expand Up @@ -63,6 +80,30 @@ def test_datasource_field_description(self):
self.assertIsNotNone(actual)
self.assertTrue(u'muted gray' in actual)

def test_datasource_caption(self):
actual = self.ds.caption
self.assertIsNotNone(actual)
self.assertEqual(actual, 'foo')

def test_datasource_can_set_caption(self):
filename = self.get_temp_file('test_datasource_can_set_caption')
self.ds.caption = 'bar'
self.ds.save_as(filename)

actual = Datasource.from_file(filename)
self.assertIsNotNone(actual)
self.assertIsNotNone(actual.caption)
self.assertEqual(actual.caption, 'bar')

def test_datasource_can_remove_caption(self):
filename = self.get_temp_file('test_datasource_can_remove_caption')
del self.ds.caption
self.ds.save_as(filename)

actual = Datasource.from_file(filename)
self.assertIsNotNone(actual)
self.assertEqual(actual.caption, '')

def test_datasource_clear_repository_location(self):
filename = os.path.join(TEST_ASSET_DIR, 'clear-repository-test.tds')

Expand Down

Back | FazBrowse Home | New Git URL