diff options
| author | Michael Williamson <mike@zwobble.org> | 2018-01-19 19:52:53 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2018-01-19 19:52:53 +0000 |
| commit | dcca2c6ffe71e399caeeac6c2d44070c097a9cc5 (patch) | |
| tree | 1a40291eb0a62d61616645fbc2ea251d9c9e12d3 /tests/docx/relationships_xml_tests.py | |
| parent | 882f1aff778b56bbc15222baa0555616f8e102ac (diff) | |
Read relationship types
Diffstat (limited to 'tests/docx/relationships_xml_tests.py')
| -rw-r--r-- | tests/docx/relationships_xml_tests.py | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/tests/docx/relationships_xml_tests.py b/tests/docx/relationships_xml_tests.py index c3d0af0..5e52142 100644 --- a/tests/docx/relationships_xml_tests.py +++ b/tests/docx/relationships_xml_tests.py @@ -5,16 +5,57 @@ from mammoth.docx.relationships_xml import read_relationships_xml_element @istest -def target_is_read_from_relationship_element(): +def relationship_targets_can_be_found_by_id(): element = xml_element("relationships:Relationships", {}, [ xml_element("relationships:Relationship", { "Id": "rId8", "Type": "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", "Target": "http://example.com", - }) + }), + xml_element("relationships:Relationship", { + "Id": "rId2", + "Type": "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", + "Target": "http://example.net", + }), ]) relationships = read_relationships_xml_element(element) assert_equal( "http://example.com", relationships.find_target_by_relationship_id("rId8"), ) + + +@istest +def relationship_targets_can_be_found_by_type(): + element = xml_element("relationships:Relationships", {}, [ + xml_element("relationships:Relationship", { + "Id": "rId2", + "Target": "docProps/core.xml", + "Type": "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties", + }), + xml_element("relationships:Relationship", { + "Id": "rId1", + "Target": "word/document.xml", + "Type": "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", + }), + xml_element("relationships:Relationship", { + "Id": "rId3", + "Target": "word/document2.xml", + "Type": "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", + }), + ]) + relationships = read_relationships_xml_element(element) + assert_equal( + ["word/document.xml", "word/document2.xml"], + relationships.find_targets_by_type("http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"), + ) + + +@istest +def when_there_are_no_relationships_of_requested_type_then_empty_list_is_returned(): + element = xml_element("relationships:Relationships", {}, []) + relationships = read_relationships_xml_element(element) + assert_equal( + [], + relationships.find_targets_by_type("http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"), + ) |
