Commit e71c163a authored by Nicolas Delaby's avatar Nicolas Delaby

Test refresh argument of OOoHandler

add lxml as dependency used inside test


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@40599 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 16bab6ca
......@@ -34,14 +34,22 @@ from cloudoooTestCase import cloudoooTestCase
from cloudooo.handler.oohandler import OOHandler
from cloudooo.application.openoffice import openoffice
from cloudoooTestCase import make_suite
import os
from lxml import etree
from zipfile import ZipFile
class TestOOHandler(cloudoooTestCase):
"""Test OOHandler and manipulation of OOo Instance"""
_file_path_list = []
def _save_document(self, document_output_url, data):
"""Create document in file system"""
open(document_output_url, "w").write(data)
new_file = open(document_output_url, "w")
new_file.write(data)
new_file.close()
self._file_path_list.append(document_output_url)
def _assert_document_output(self, document_output_url, msg):
"""Check if the document was created correctly"""
......@@ -52,6 +60,16 @@ class TestOOHandler(cloudoooTestCase):
True,
"\nStdout: %sMsg: %s" % (stdout, msg))
def tearDown(self):
"""Cleanup temp files
"""
while self._file_path_list:
file_path = self._file_path_list.pop()
if os.path.exists(file_path):
os.remove(file_path)
cloudoooTestCase.tearDown(self)
def testConvertOdtToDoc(self):
"""Test convert ODT to DOC"""
data = encodestring(open("data/test.odt").read())
......@@ -152,6 +170,35 @@ class TestOOHandler(cloudoooTestCase):
metadata = new_handler.getMetadata()
self.assertEquals(metadata.get('Title'), "cloudooo Test -")
def testRefreshOdt(self):
"""Test refresh argument"""
# Check when refreshing is disabled
data = encodestring(open("data/test_fields.odt").read())
handler = OOHandler(self.tmp_url,
decodestring(data),
'odt',
refresh=False)
doc_exported = handler.convert("odt")
document_output_url = path.join(self.tmp_url, "testExport.odt")
self._save_document(document_output_url, doc_exported)
zip_handler = ZipFile(document_output_url)
content_tree = etree.fromstring(zip_handler.read('content.xml'))
self.assertFalse(content_tree.xpath('//text:variable-get[text() = "DISPLAY ME"]',
namespaces=content_tree.nsmap))
# Check when refreshing is enabled
data = encodestring(open("data/test_fields.odt").read())
handler = OOHandler(self.tmp_url,
decodestring(data),
'odt',
refresh=True)
doc_exported = handler.convert("odt")
document_output_url = path.join(self.tmp_url, "testExport.odt")
self._save_document(document_output_url, doc_exported)
zip_handler = ZipFile(document_output_url)
content_tree = etree.fromstring(zip_handler.read('content.xml'))
self.assertTrue(content_tree.xpath('//text:variable-get[text() = "DISPLAY ME"]',
namespaces=content_tree.nsmap))
def test_suite():
return make_suite(TestOOHandler)
......
......@@ -33,6 +33,7 @@ setup(name='cloudooo',
'WSGIUtils',
'jsonpickle',
'psutil',
'lxml',
],
entry_points="""
[paste.app_factory]
......
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