From 57a0d70f895d6e39ddc2aac46c53c4088f90cc3f Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 6 Dec 2015 14:49:08 +0000 Subject: Read v:imagedata with r:id attribute --- tests/docx/body_xml_tests.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests') diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py index da662d8..d0288bd 100644 --- a/tests/docx/body_xml_tests.py +++ b/tests/docx/body_xml_tests.py @@ -295,6 +295,36 @@ class ReadXmlElementTests(object): assert_equal(None, result.value) + @istest + @funk.with_context + def can_read_imagedata_elements_with_rid_attribute(self, context): + imagedata_element = xml_element("v:imagedata", {"r:id": "rId5", "o:title": "It's a hat"}) + + image_bytes = b"Not an image at all!" + + relationships = Relationships({ + "rId5": Relationship(target="media/hat.png") + }) + + docx_file = context.mock() + funk.allows(docx_file).open("word/media/hat.png").returns(io.BytesIO(image_bytes)) + + content_types = context.mock() + funk.allows(content_types).find_content_type("word/media/hat.png").returns("image/png") + + image = _read_and_get_document_xml_element( + imagedata_element, + content_types=content_types, + relationships=relationships, + docx_file=docx_file, + ) + assert_equal(documents.Image, type(image)) + assert_equal("It's a hat", image.alt_text) + assert_equal("image/png", image.content_type) + with image.open() as image_file: + assert_equal(image_bytes, image_file.read()) + + @istest @funk.with_context def can_read_inline_pictures(self, context): -- cgit v1.2.3