aboutsummaryrefslogtreecommitdiff
path: root/tests/docx
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2018-01-27 17:31:41 +0000
committerMichael Williamson <mike@zwobble.org>2018-01-27 17:31:41 +0000
commit3cbdaaedc226456a41825db84c303da205951d19 (patch)
treefa1c6b704b48e6b0d5a407b4ef522586204a2ec2 /tests/docx
parentf4adcf24ec4b7e2ec321718f6cfdb9870a8ed4a2 (diff)
Find comments part using document relationships
Diffstat (limited to 'tests/docx')
-rw-r--r--tests/docx/docx_tests.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/docx/docx_tests.py b/tests/docx/docx_tests.py
index a474b17..64a3b81 100644
--- a/tests/docx/docx_tests.py
+++ b/tests/docx/docx_tests.py
@@ -101,6 +101,42 @@ class TestPartPaths(object):
part_paths = self._find_part_paths(fileobj)
assert_equal("word/document.xml", part_paths.main_document)
+ @istest
+ def comments_part_is_found_using_main_document_relationships(self):
+ fileobj = _create_zip({
+ "_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/document.xml" Id="rId1"/>
+ </Relationships>
+ """),
+ "word/document.xml": " ",
+ "word/_rels/document.xml.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/comments" Target="target-path.xml" Id="rId2"/>
+ </Relationships>
+ """),
+ "word/target-path.xml": " "
+ })
+ part_paths = self._find_part_paths(fileobj)
+ assert_equal("word/target-path.xml", part_paths.comments)
+
+ @istest
+ def when_relationship_for_comments_cannot_be_found_then_fallback_is_used(self):
+ fileobj = _create_zip({
+ "_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/document.xml" Id="rId1"/>
+ </Relationships>
+ """),
+ "word/document.xml": " ",
+ })
+ part_paths = self._find_part_paths(fileobj)
+ assert_equal("word/comments.xml", part_paths.comments)
+
+
def _find_part_paths(self, fileobj):
return docx._find_part_paths(zips.open_zip(fileobj, "r"))