Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_exception_when_datasource_given_twbx(self):
with self.assertRaises(TableauInvalidFileException):
ds = Datasource.from_file(TABLEAU_10_TWBX)
def test_exception_when_workbook_given_tdsx(self):
with self.assertRaises(TableauInvalidFileException):
wb = Workbook(TABLEAU_10_TDSX)
def test_exception_when_datasource_given_twbx(self):
with self.assertRaises(TableauInvalidFileException):
ds = Datasource.from_file(TABLEAU_10_TWBX)
def test_exception_when_workbook_given_tdsx(self):
with self.assertRaises(TableauInvalidFileException):
wb = Workbook(TABLEAU_10_TDSX)
# Is the file a zip (.twbx or .tdsx)
if zipfile.is_zipfile(filename):
tree = get_xml_from_archive(filename)
else:
tree = ET.parse(filename)
# Is the file a supported version
tree_root = tree.getroot()
file_version = Version(tree_root.attrib.get('version', '0.0'))
if file_version < MIN_SUPPORTED_VERSION:
raise TableauVersionNotSupportedException(file_version)
# Does the root tag match the object type (workbook or data source)
if expected_root and (expected_root != tree_root.tag):
raise TableauInvalidFileException(
"'{}'' is not a valid '{}' file".format(filename, expected_root))
return tree