summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2018-01-27 17:17:16 +0000
committerMichael Williamson <mike@zwobble.org>2018-01-27 17:17:16 +0000
commit06b5117f11e1a4265528b15d43e2c6a6ffb7eeee (patch)
tree31ed146f4ae01345195bbadf582b79a59e1ce040
parent5bd0d36e745bdfd83d848bab4d706b79afe32519 (diff)
Add tests for _find_part_paths
-rw-r--r--tests/docx/docx_tests.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/docx/docx_tests.py b/tests/docx/docx_tests.py
index d450424..a474b17 100644
--- a/tests/docx/docx_tests.py
+++ b/tests/docx/docx_tests.py
@@ -4,7 +4,7 @@ import zipfile
from nose.tools import istest, assert_equal
-from mammoth import docx, documents
+from mammoth import docx, documents, zips
from ..testing import assert_raises, test_path
@@ -78,6 +78,32 @@ def error_is_raised_when_main_document_part_does_not_exist():
str(error),
)
+class TestPartPaths(object):
+ @istest
+ def main_document_part_is_found_using_package_relationships(self):
+ fileobj = _create_zip({
+ "word/document2.xml": " ",
+ "_rels/.rels": textwrap.dedent("""\
+ <?xml version="1.0" encoding="utf-8"?>
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
+ <Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="/word/document2.xml" Id="rId1"/>
+ </Relationships>
+ """),
+ })
+ part_paths = self._find_part_paths(fileobj)
+ assert_equal("word/document2.xml", part_paths.main_document)
+
+ @istest
+ def when_relationship_for_main_document_cannot_be_found_then_fallback_is_used(self):
+ fileobj = _create_zip({
+ "word/document.xml": " ",
+ })
+ part_paths = self._find_part_paths(fileobj)
+ assert_equal("word/document.xml", part_paths.main_document)
+
+ def _find_part_paths(self, fileobj):
+ return docx._find_part_paths(zips.open_zip(fileobj, "r"))
+
def _create_zip(files):
fileobj = io.BytesIO()