From f0630b7682f3944f0433652e8c501ef10e73d86c Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 27 Jan 2018 17:36:28 +0000 Subject: Find parts related to main document using main document relationships --- tests/docx/docx_tests.py | 50 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) (limited to 'tests/docx') 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("""\ @@ -114,16 +153,15 @@ class TestPartPaths(object): "word/_rels/document.xml.rels": textwrap.dedent("""\ - + - """), + """.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("""\ @@ -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): -- cgit v1.2.3