From 3cbdaaedc226456a41825db84c303da205951d19 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 27 Jan 2018 17:31:41 +0000 Subject: Find comments part using document relationships --- tests/docx/docx_tests.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tests/docx') 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("""\ + + + + + """), + "word/document.xml": " ", + "word/_rels/document.xml.rels": textwrap.dedent("""\ + + + + + """), + "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("""\ + + + + + """), + "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")) -- cgit v1.2.3