| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 94d1f82 commit cb0de80
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -137,6 +137,7 @@ def __init__(self, dsxml, filename=None): | |||
| 137 | 137 | self._name = self._datasourceXML.get('name') or self._datasourceXML.get( | |
| 138 | 138 | 'formatted-name') # TDS files don't have a name attribute | |
| 139 | 139 | self._version = self._datasourceXML.get('version') | |
| 140 | + self._caption = self._datasourceXML.get('caption', '') | ||
| 140 | 141 | self._connection_parser = ConnectionParser( | |
| 141 | 142 | self._datasourceXML, version=self._version) | |
| 142 | 143 | self._connections = self._connection_parser.get_connections() | |
@@ -207,6 +208,20 @@ def name(self): | |||
| 207 | 208 | def version(self): | |
| 208 | 209 | return self._version | |
| 209 | 210 | ||
| 211 | + @property | ||
| 212 | + def caption(self): | ||
| 213 | + return self._caption | ||
| 214 | + | ||
| 215 | + @caption.setter | ||
| 216 | + def caption(self, value): | ||
| 217 | + self._datasourceXML.set('caption', value) | ||
| 218 | + self._caption = value | ||
| 219 | + | ||
| 220 | + @caption.deleter | ||
| 221 | + def caption(self): | ||
| 222 | + del self._datasourceXML.attrib['caption'] | ||
| 223 | + self._caption = '' | ||
| 224 | + | ||
| 210 | 225 | ########### | |
| 211 | 226 | # connections | |
| 212 | 227 | ########### | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | <?xml version='1.0' encoding='utf-8' ?> | |
| 2 | - <datasource formatted-name='postgres.1of3kl00aoax5d1a1ejma1397430' inline='true' source-platform='mac' version='9.3' xmlns:user='http://www.tableausoftware.com/xml/user'> | ||
| 2 | + <datasource caption='foo' formatted-name='postgres.1of3kl00aoax5d1a1ejma1397430' inline='true' source-platform='mac' | ||
| 3 | + version='9.3' xmlns:user='http://www.tableausoftware.com/xml/user'> | ||
| 3 | 4 | <repository-location /> | |
| 4 | 5 | <connection authentication='username-password' class='postgres' dbname='TestV1' odbc-native-protocol='yes' port='5432' server='postgres91.test.tsi.lan' username='test'> | |
| 5 | 6 | <relation name='xy' table='[public].[xy]' type='table' /> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,9 @@ | |||
| 1 | - import unittest | ||
| 1 | + import os | ||
| 2 | 2 | import os.path | |
| 3 | + import shutil | ||
| 4 | + import tempfile | ||
| 5 | + import unittest | ||
| 6 | + | ||
| 3 | 7 | ||
| 4 | 8 | from tableaudocumentapi import Datasource, Workbook | |
| 5 | 9 | ||
@@ -22,6 +26,19 @@ class DataSourceFieldsTDS(unittest.TestCase): | |||
| 22 | 26 | ||
| 23 | 27 | def setUp(self): | |
| 24 | 28 | self.ds = Datasource.from_file(TEST_TDS_FILE) | |
| 29 | + self.to_delete = set() | ||
| 30 | + | ||
| 31 | + def cleanUp(self): | ||
| 32 | + for path in self.to_delete: | ||
| 33 | + if os.path.isdir(path): | ||
| 34 | + shutil.rmtree(path, ignore_errors=True) | ||
| 35 | + elif os.path.isfile(path): | ||
| 36 | + os.unlink(path) | ||
| 37 | + | ||
| 38 | + def get_temp_file(self, filename): | ||
| 39 | + tempdir = tempfile.mkdtemp('tda-datasource') | ||
| 40 | + self.to_delete.add(tempdir) | ||
| 41 | + return os.path.join(tempdir, filename) | ||
| 25 | 42 | ||
| 26 | 43 | def test_datasource_returns_correct_fields(self): | |
| 27 | 44 | self.assertIsNotNone(self.ds.fields) | |
@@ -63,6 +80,30 @@ def test_datasource_field_description(self): | |||
| 63 | 80 | self.assertIsNotNone(actual) | |
| 64 | 81 | self.assertTrue(u'muted gray' in actual) | |
| 65 | 82 | ||
| 83 | + def test_datasource_caption(self): | ||
| 84 | + actual = self.ds.caption | ||
| 85 | + self.assertIsNotNone(actual) | ||
| 86 | + self.assertEqual(actual, 'foo') | ||
| 87 | + | ||
| 88 | + def test_datasource_can_set_caption(self): | ||
| 89 | + filename = self.get_temp_file('test_datasource_can_set_caption') | ||
| 90 | + self.ds.caption = 'bar' | ||
| 91 | + self.ds.save_as(filename) | ||
| 92 | + | ||
| 93 | + actual = Datasource.from_file(filename) | ||
| 94 | + self.assertIsNotNone(actual) | ||
| 95 | + self.assertIsNotNone(actual.caption) | ||
| 96 | + self.assertEqual(actual.caption, 'bar') | ||
| 97 | + | ||
| 98 | + def test_datasource_can_remove_caption(self): | ||
| 99 | + filename = self.get_temp_file('test_datasource_can_remove_caption') | ||
| 100 | + del self.ds.caption | ||
| 101 | + self.ds.save_as(filename) | ||
| 102 | + | ||
| 103 | + actual = Datasource.from_file(filename) | ||
| 104 | + self.assertIsNotNone(actual) | ||
| 105 | + self.assertEqual(actual.caption, '') | ||
| 106 | + | ||
| 66 | 107 | def test_datasource_clear_repository_location(self): | |
| 67 | 108 | filename = os.path.join(TEST_ASSET_DIR, 'clear-repository-test.tds') | |
| 68 | 109 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments