Skip to content

Improve test coverage #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tableaudocumentapi/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# dropped, remove this and change the basestring references below to str
try:
basestring
except NameError:
except NameError: # pragma: no cover
basestring = str
########

Expand Down
6 changes: 4 additions & 2 deletions tableaudocumentapi/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ def __init__(self, column_xml=None, metadata_xml=None):

if column_xml is not None:
self._initialize_from_column_xml(column_xml)
if metadata_xml is not None:
self.apply_metadata(metadata_xml)
# This isn't currently never called because of the way we get the data from the xml,
# but during the refactor, we might need it. This is commented out as a reminder
# if metadata_xml is not None:
# self.apply_metadata(metadata_xml)

elif metadata_xml is not None:
self._initialize_from_metadata_xml(metadata_xml)
Expand Down
8 changes: 1 addition & 7 deletions tableaudocumentapi/multilookup_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def _resolve_value(key, value):
if retval is None:
retval = getattr(value, key, None)
except AttributeError:
# We should never hit this.
retval = None
return retval

Expand Down Expand Up @@ -50,13 +51,6 @@ def _get_real_key(self, key):
def __setitem__(self, key, value):
real_key = self._get_real_key(key)

alias = _resolve_value('alias', value)
caption = _resolve_value('caption', value)
if alias is not None:
self._indexes['alias'][alias] = real_key
if caption is not None:
self._indexes['caption'][caption] = real_key

dict.__setitem__(self, real_key, value)

def get(self, key, default_value=_no_default_value):
Expand Down
Binary file added test/assets/BadZip.zip
Binary file not shown.
8 changes: 8 additions & 0 deletions test/bvt.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ def test_can_extract_datasource(self):
self.assertEqual(wb.datasources[0].name,
'sqlserver.17u3bqc16tjtxn14e2hxh19tyvpo')

def test_can_get_worksheets(self):
wb = Workbook(self.workbook_file.name)
self.assertIsNotNone(wb.worksheets)

def test_has_filename(self):
wb = Workbook(self.workbook_file.name)
self.assertEqual(wb.filename, self.workbook_file.name)

def test_can_update_datasource_connection_and_save(self):
original_wb = Workbook(self.workbook_file.name)
original_wb.datasources[0].connections[0].dbname = 'newdb.test.tsi.lan'
Expand Down
29 changes: 29 additions & 0 deletions test/test_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import unittest
import os.path

from tableaudocumentapi import Datasource, Field
from tableaudocumentapi.field import _find_metadata_record

TEST_ASSET_DIR = os.path.join(
os.path.dirname(__file__),
'assets'
)
TEST_TDS_FILE = os.path.join(
TEST_ASSET_DIR,
'datasource_test.tds'
)


class FieldsUnitTest(unittest.TestCase):
def test_field_throws_if_no_data_passed_in(self):
with self.assertRaises(AttributeError):
Field()


class FindMetaDataRecordEdgeTest(unittest.TestCase):
class MockXmlWithNoFind(object):
def find(self, *args, **kwargs):
return None

def test_find_metadata_record_returns_none(self):
self.assertIsNone(_find_metadata_record(self.MockXmlWithNoFind(), 'foo'))
8 changes: 8 additions & 0 deletions test/test_multidict.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def setUp(self):
}
})

def test_multilookupdict_can_be_empty(self):
mld = MultiLookupDict()
self.assertIsNotNone(mld)

def test_multilookupdict_name_only(self):
actual = self.mld['[baz]']
self.assertEqual(3, actual['value'])
Expand Down Expand Up @@ -70,3 +74,7 @@ def test_multilookupdict_can_set_item(self):
def test_multilookupdict_can_set_new_item(self):
self.mld['wakka'] = 1
self.assertEqual(1, self.mld['wakka'])

def test_multilookupdict_can_set_with_alias(self):
self.mld['bar'] = 2
self.assertEqual(2, self.mld['[foo]'])
19 changes: 19 additions & 0 deletions test/test_xfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os.path
import unittest
import zipfile
from tableaudocumentapi.xfile import find_file_in_zip

TEST_ASSET_DIR = os.path.join(
os.path.dirname(__file__),
'assets'
)
BAD_ZIP_FILE = os.path.join(
TEST_ASSET_DIR,
'BadZip.zip'
)


class XFileEdgeTests(unittest.TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!!

I noticed this one and was lazy about making a bad zip

def test_find_file_in_zip_no_xml_file(self):
badzip = zipfile.ZipFile(BAD_ZIP_FILE)
self.assertIsNone(find_file_in_zip(badzip))
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy