Commit c80f4e47 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

tests: make testFormPrintoutAsODG and testFormPrintoutAsODT work on LibreOffice 4.4.

parent 9d6c0b16
...@@ -325,16 +325,18 @@ class TestFormPrintoutAsODG(TestFormPrintoutMixin): ...@@ -325,16 +325,18 @@ class TestFormPrintoutAsODG(TestFormPrintoutMixin):
self._validate(odf_document) self._validate(odf_document)
builder = OOoBuilder(odf_document) builder = OOoBuilder(odf_document)
content_xml = builder.extract("content.xml") content_xml = builder.extract("content.xml")
self.assertTrue(content_xml.find("Pictures/0.png") > 0) content = etree.XML(content_xml)
image_element_list = content.xpath('//draw:image', namespaces=content.nsmap)
self.assertTrue(len(image_element_list) > 0)
# check the image is in the odg file # check the image is in the odg file
try: try:
image_data = builder.extract("Pictures/0.png") image_path = image_element_list[0].get('{http://www.w3.org/1999/xlink}href')
image_data = builder.extract(image_path)
except KeyError: except KeyError:
self.fail('image "Pictures/0.png" not found in odg document') self.fail('image %r not found in odg document' % image_path)
self.assertEqual(image.getData(), image_data, self.assertEqual(image.getData(), image_data,
'%s != %s' % (len(image.getData()), len(image_data))) '%s != %s' % (len(image.getData()), len(image_data)))
content = etree.XML(content_xml)
image_frame_xpath = '//draw:frame[@draw:name="image_view"]' image_frame_xpath = '//draw:frame[@draw:name="image_view"]'
image_frame_list = content.xpath(image_frame_xpath, namespaces=content.nsmap) image_frame_list = content.xpath(image_frame_xpath, namespaces=content.nsmap)
self.assertTrue(len(image_frame_list) > 0) self.assertTrue(len(image_frame_list) > 0)
...@@ -355,7 +357,9 @@ class TestFormPrintoutAsODG(TestFormPrintoutMixin): ...@@ -355,7 +357,9 @@ class TestFormPrintoutAsODG(TestFormPrintoutMixin):
builder = OOoBuilder(odf_document) builder = OOoBuilder(odf_document)
content_xml = builder.extract("content.xml") content_xml = builder.extract("content.xml")
# confirming the image was removed # confirming the image was removed
self.assertFalse(content_xml.find("Pictures/0.png") > 0) content = etree.XML(content_xml)
image_element_list = content.xpath('//draw:image', namespaces=content.nsmap)
self.assertFalse(len(image_element_list) > 0)
self._validate(odf_document) self._validate(odf_document)
def test_04_ProxyField(self): def test_04_ProxyField(self):
......
...@@ -534,8 +534,12 @@ class TestFormPrintoutAsODT(TestFormPrintoutMixin): ...@@ -534,8 +534,12 @@ class TestFormPrintoutAsODT(TestFormPrintoutMixin):
content_xml = builder.extract("content.xml") content_xml = builder.extract("content.xml")
content_tree = etree.XML(content_xml) content_tree = etree.XML(content_xml)
#Check that foo_1 is inside table, with the same style #Check that foo_1 is inside table, with the same style
xpath_style_name_expression = '//table:table[@table:name="listbox2"]/table:table-row/table:table-cell/text:p[@text:style-name="P4"]/text()' xpath_style_name_expression = '//table:table[@table:name="listbox2"]/table:table-row/table:table-cell/text:p[starts-with(@text:style-name, "P")]'
self.assertEqual(['foo_1', 'foo_2'], content_tree.xpath(xpath_style_name_expression, namespaces=content_tree.nsmap)) element_list = content_tree.xpath(xpath_style_name_expression, namespaces=content_tree.nsmap)
self.assertEqual(len(element_list), 2)
self.assertEqual(element_list[0].get('{%s}style-name' % content_tree.nsmap['text']),
element_list[1].get('{%s}style-name' % content_tree.nsmap['text']))
self.assertEqual(['foo_1', 'foo_2'], [x.text for x in element_list])
#Check that each listbox values are inside ODT table cells #Check that each listbox values are inside ODT table cells
xpath_result_expression = '//table:table[@table:name="listbox2"]/table:table-row/table:table-cell/text:p/text()' xpath_result_expression = '//table:table[@table:name="listbox2"]/table:table-row/table:table-cell/text:p/text()'
self.assertEqual(['foo_1', 'foo_title_5', '0.0', 'foo_2', 'foo_2', '0.0', '1234.5'], content_tree.xpath(xpath_result_expression, namespaces=content_tree.nsmap)) self.assertEqual(['foo_1', 'foo_title_5', '0.0', 'foo_2', 'foo_2', '0.0', '1234.5'], content_tree.xpath(xpath_result_expression, namespaces=content_tree.nsmap))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment