diff options
| author | Michael Williamson <mike@zwobble.org> | 2018-01-27 17:36:28 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2018-01-27 17:36:28 +0000 |
| commit | f0630b7682f3944f0433652e8c501ef10e73d86c (patch) | |
| tree | a2fed3f17cc47740666ff9cfe05dbabfbe4d342a /tests | |
| parent | 3cbdaaedc226456a41825db84c303da205951d19 (diff) | |
Find parts related to main document using main document relationships
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/docx/docx_tests.py | 50 |
1 files changed, 44 insertions, 6 deletions
diff --git a/tests/docx/docx_tests.py b/tests/docx/docx_tests.py index 64a3b81..830f334 100644 --- a/tests/docx/docx_tests.py +++ b/tests/docx/docx_tests.py @@ -103,6 +103,45 @@ class TestPartPaths(object): @istest def comments_part_is_found_using_main_document_relationships(self): + self._assert_path_is_found_using_main_document_relationships("comments") + + @istest + def when_relationship_for_comments_cannot_be_found_then_fallback_is_used(self): + self._assert_when_relationship_for_part_cannot_be_found_then_fallback_is_used("comments") + + @istest + def endnotes_part_is_found_using_main_document_relationships(self): + self._assert_path_is_found_using_main_document_relationships("endnotes") + + @istest + def when_relationship_for_endnotes_cannot_be_found_then_fallback_is_used(self): + self._assert_when_relationship_for_part_cannot_be_found_then_fallback_is_used("endnotes") + + @istest + def footnotes_part_is_found_using_main_document_relationships(self): + self._assert_path_is_found_using_main_document_relationships("footnotes") + + @istest + def when_relationship_for_footnotes_cannot_be_found_then_fallback_is_used(self): + self._assert_when_relationship_for_part_cannot_be_found_then_fallback_is_used("footnotes") + + @istest + def numbering_part_is_found_using_main_document_relationships(self): + self._assert_path_is_found_using_main_document_relationships("numbering") + + @istest + def when_relationship_for_numbering_cannot_be_found_then_fallback_is_used(self): + self._assert_when_relationship_for_part_cannot_be_found_then_fallback_is_used("numbering") + + @istest + def styles_part_is_found_using_main_document_relationships(self): + self._assert_path_is_found_using_main_document_relationships("styles") + + @istest + def when_relationship_for_styles_cannot_be_found_then_fallback_is_used(self): + self._assert_when_relationship_for_part_cannot_be_found_then_fallback_is_used("styles") + + def _assert_path_is_found_using_main_document_relationships(self, name): fileobj = _create_zip({ "_rels/.rels": textwrap.dedent("""\ <?xml version="1.0" encoding="utf-8"?> @@ -114,16 +153,15 @@ class TestPartPaths(object): "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"/> + <Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/{name}" Target="target-path.xml" Id="rId2"/> </Relationships> - """), + """.format(name=name)), "word/target-path.xml": " " }) part_paths = self._find_part_paths(fileobj) - assert_equal("word/target-path.xml", part_paths.comments) + assert_equal("word/target-path.xml", getattr(part_paths, name)) - @istest - def when_relationship_for_comments_cannot_be_found_then_fallback_is_used(self): + def _assert_when_relationship_for_part_cannot_be_found_then_fallback_is_used(self, name): fileobj = _create_zip({ "_rels/.rels": textwrap.dedent("""\ <?xml version="1.0" encoding="utf-8"?> @@ -134,7 +172,7 @@ class TestPartPaths(object): "word/document.xml": " ", }) part_paths = self._find_part_paths(fileobj) - assert_equal("word/comments.xml", part_paths.comments) + assert_equal("word/{0}.xml".format(name), getattr(part_paths, name)) def _find_part_paths(self, fileobj): |
