Commit ae2759f3 authored by Gabriel Monnerat's avatar Gabriel Monnerat

refactor and clean up tests

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@38567 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9f575385
......@@ -29,7 +29,7 @@
import unittest
from subprocess import Popen, PIPE
from base64 import decodestring
from os.path import exists, join
from os import path
from os import remove
from zipfile import ZipFile, is_zipfile
from cloudooo.document import FileSystemDocument
......@@ -54,17 +54,17 @@ class TestFileSystemDocument(unittest.TestCase):
original state"""
old_document_url = self.fsdocument.getUrl()
document_filename = "document"
document_test_url = join(self.fsdocument.directory_name, document_filename)
document_test_url = path.join(self.fsdocument.directory_name, document_filename)
open(document_test_url,'wb').write(decodestring("Test Document"))
self.fsdocument.reload(document_test_url)
self.assertEquals(exists(old_document_url), False)
self.assertEquals(path.exists(old_document_url), False)
self.assertNotEquals(self.fsdocument.original_data,
self.fsdocument.getContent())
old_document_url = self.fsdocument.getUrl()
self.fsdocument.restoreOriginal()
self.assertEquals(exists(old_document_url), False)
self.assertEquals(path.exists(old_document_url), False)
self.assertNotEquals(old_document_url, self.fsdocument.getUrl())
self.assertEquals(exists(self.fsdocument.getUrl()), True)
self.assertEquals(path.exists(self.fsdocument.getUrl()), True)
self.assertEquals(self.fsdocument.getContent(), self.data)
def testgetContent(self):
......@@ -74,7 +74,7 @@ class TestFileSystemDocument(unittest.TestCase):
def testgetUrl(self):
"""Check if the url is correct"""
url = self.fsdocument.getUrl()
self.assertEquals(exists(url), True)
self.assertEquals(path.exists(url), True)
def testLoadDocumentFile(self):
"""Test if the document is created correctly"""
......@@ -82,30 +82,30 @@ class TestFileSystemDocument(unittest.TestCase):
tmp_document = open(url,'r').read()
self.assertEquals(self.data, tmp_document)
self.fsdocument.trash()
self.assertEquals(exists(url), False)
self.assertEquals(path.exists(url), False)
def testReload(self):
"""Change url and check if occurs correctly"""
old_document_url = self.fsdocument.getUrl()
document_filename = "document"
document_test_url = join(self.fsdocument.directory_name, document_filename)
document_test_url = path.join(self.fsdocument.directory_name, document_filename)
open(document_test_url,'wb').write(self.data)
self.fsdocument.reload(document_test_url)
url = self.fsdocument.getUrl()
self.assertEquals(exists(old_document_url), False)
self.assertEquals(path.exists(old_document_url), False)
self.assertEquals(self.fsdocument.getContent(), self.data)
self.fsdocument.trash()
self.assertEquals(exists(url), False)
self.assertEquals(path.exists(url), False)
def testZipDocumentList(self):
"""Tests if the zip file is returned correctly"""
zip_output_url = 'output/ziptest.zip'
open(join(self.fsdocument.directory_name, 'document2'), 'w').write('test')
zip_output_url = path.join(self.tmp_url, 'ziptest.zip')
open(path.join(self.fsdocument.directory_name, 'document2'), 'w').write('test')
zip_file = self.fsdocument.getContent(True)
open(zip_output_url, 'w').write(zip_file)
stdout, stderr = Popen("file %s" % zip_output_url,
shell=True, stdout=PIPE).communicate()
self.assertEquals(stdout, 'output/ziptest.zip: Zip archive data, at least v2.0 to extract\n')
self.assertEquals(stdout, '/tmp/ziptest.zip: Zip archive data, at least v2.0 to extract\n')
ziptest = ZipFile(zip_output_url, 'r')
self.assertEquals(len(ziptest.filelist), 2)
for file in ziptest.filelist:
......@@ -118,14 +118,18 @@ class TestFileSystemDocument(unittest.TestCase):
def testSendZipFile(self):
"""Tests if the htm is extrated from zipfile"""
zip_input_url = 'data/test.zip'
zip_output_url = 'output/zipdocument.zip'
data = open(zip_input_url).read()
zipdocument = FileSystemDocument(self.tmp_url, data, 'zip')
open(zip_output_url, 'w').write(zipdocument.getContent(True))
self.assertEquals(is_zipfile(zip_output_url), True)
zipfile = ZipFile(zip_output_url)
self.assertEquals(sorted(zipfile.namelist()),
zip_output_url = path.join(self.tmp_url, 'zipdocument.zip')
try:
data = open(zip_input_url).read()
zipdocument = FileSystemDocument(self.tmp_url, data, 'zip')
open(zip_output_url, 'w').write(zipdocument.getContent(True))
self.assertEquals(is_zipfile(zip_output_url), True)
zipfile = ZipFile(zip_output_url)
self.assertEquals(sorted(zipfile.namelist()),
sorted(['logo.gif','test.htm']))
finally:
if path.exists(zip_output_url):
remove(zip_output_url)
def test_suite():
return make_suite(TestFileSystemDocument)
......
......@@ -180,7 +180,6 @@ class TestMimeMapper(cloudoooTestCase):
hostname, port = openoffice.getAddress()
self.mimemapper.loadFilterList(hostname,
port,
unomimemapper_bin=self.unomimemapper_bin,
python_path=self.python_path)
openoffice.release()
......
......@@ -51,18 +51,12 @@ class TestOOHandler(cloudoooTestCase):
True,
"\nStdout: %sMsg: %s" % (stdout, msg))
def afterSetUp(self):
""" """
self.kw = dict(unoconverter_bin=self.unoconverter_bin,
python_path=self.python_path)
def testConvertOdtToDoc(self):
"""Test convert ODT to DOC"""
data = encodestring(open("data/test.odt").read())
handler = OOHandler(self.tmp_url,
decodestring(data),
'odt',
**self.kw)
'odt')
doc_exported = handler.convert("doc")
document_output_url = path.join(self.tmp_url, "testExport.doc")
self._save_document(document_output_url, doc_exported)
......@@ -74,8 +68,7 @@ class TestOOHandler(cloudoooTestCase):
data = encodestring(open("data/test.doc").read())
handler = OOHandler(self.tmp_url,
decodestring(data),
'doc',
**self.kw)
'doc')
doc_exported = handler.convert("odt")
document_output_url = path.join(self.tmp_url, "testConvert.odt")
self._save_document(document_output_url, doc_exported)
......@@ -87,8 +80,7 @@ class TestOOHandler(cloudoooTestCase):
data = encodestring(open("data/test.odt").read())
handler = OOHandler(self.tmp_url,
decodestring(data),
'odt',
**self.kw)
'odt')
metadata = handler.getMetadata()
self.assertEquals(metadata.get('Data'), '')
self.assertEquals(metadata.has_key('Data'), True)
......@@ -103,13 +95,11 @@ class TestOOHandler(cloudoooTestCase):
data = encodestring(open("data/test.odt").read())
handler = OOHandler(self.tmp_url,
decodestring(data),
'odt',
**self.kw)
'odt')
new_data = handler.setMetadata({"Title": "cloudooo Test -"})
new_handler = OOHandler(self.tmp_url,
new_data,
'odt',
**self.kw)
'odt')
metadata = new_handler.getMetadata()
self.assertEquals(metadata.get('Title'), "cloudooo Test -")
......@@ -119,8 +109,7 @@ class TestOOHandler(cloudoooTestCase):
data = encodestring(open("data/test.doc").read())
handler = OOHandler(self.tmp_url,
decodestring(data),
'doc',
**self.kw)
'doc')
doc_exported = handler.convert("odt")
document_output_url = path.join(self.tmp_url, "testConvert.odt")
self._save_document(document_output_url, doc_exported)
......@@ -133,8 +122,7 @@ class TestOOHandler(cloudoooTestCase):
data = encodestring(open("data/test.odt").read())
handler = OOHandler(self.tmp_url,
decodestring(data),
'odt',
**self.kw)
'odt')
metadata = handler.getMetadata()
self.assertEquals(metadata.get('Title'), 'title')
self.assertEquals(metadata.get('MIMEType'),
......@@ -146,13 +134,11 @@ class TestOOHandler(cloudoooTestCase):
data = encodestring(open("data/test.doc").read())
handler = OOHandler(self.tmp_url,
decodestring(data),
'doc',
**self.kw)
'doc')
new_data = handler.setMetadata({"Title": "cloudooo Test -"})
new_handler = OOHandler(self.tmp_url,
new_data,
'doc',
**self.kw)
'doc')
metadata = new_handler.getMetadata()
self.assertEquals(metadata.get('Title'), "cloudooo Test -")
......
......@@ -42,8 +42,7 @@ class TestOpenOffice(cloudoooTestCase):
self.working_path,
self.virtual_display_id,
self.office_binary_path,
self.uno_path,
openoffice_tester_bin=self.openoffice_tester_bin)
self.uno_path)
self.openoffice.start()
def tearDown(self):
......
......@@ -462,7 +462,6 @@ class TestServer(cloudoooTestCase):
else:
self.fail("Not exists one file with 'impr.html' format")
def testRunGenerateMethodFailResponse(self):
"""Test run_generate method with invalid document"""
data = open(join('data','test.odt'), 'r').read()[:100]
......
......@@ -27,7 +27,7 @@
##############################################################################
import unittest
import jsonpickle
import jsonpickle, pkg_resources
from subprocess import Popen, PIPE
from os.path import exists
from cloudoooTestCase import cloudoooTestCase, make_suite
......@@ -56,8 +56,8 @@ class TestUnoConverter(cloudoooTestCase):
"""Test script unoconverter"""
mimemapper_pickled = jsonpickle.encode(mimemapper)
command = [self.python_path,
"-c",
"'from cloudooo.bin.unoconverter import main;main()'",
pkg_resources.resource_filename("cloudooo",
"helper/unoconverter.py"),
"'--convert'",
"'--uno_path=%s'" % self.uno_path,
"'--office_binary_path=%s'" % self.office_binary_path,
......@@ -82,37 +82,6 @@ class TestUnoConverter(cloudoooTestCase):
self.document.trash()
self.assertEquals(exists(output_url), False)
def _testUnoConverterWithoutMimemapper(self):
"""Test script unoconverter without mimemapper serialized"""
command = [self.python_path,
"-c",
"'from cloudooo.bin.unoconverter import main;main()'",
"'--convert'",
"'--uno_path=%s'" % self.uno_path,
"'--office_binary_path=%s'" % self.office_binary_path,
"'--hostname=%s'" % self.hostname,
"'--port=%s'" % self.port,
"'--document_url=%s'" % self.document.getUrl(),
"'--destination_format=%s'" % "doc",
"'--source_format=%s'" % "odt",
"'--unomimemapper_bin=%s'" % self.unomimemapper_bin]
stdout, stderr = Popen(' '.join(command), shell=True,
stdout=PIPE, stderr=PIPE).communicate()
if not stdout:
self.fail(stderr)
output_url = stdout.replace('\n', '')
self.assertEquals(exists(output_url), True)
stdout, stderr = Popen("file %s" % output_url, shell=True,
stdout=PIPE, stderr=PIPE).communicate()
self.assertEquals(self.file_msg_list[1] in stdout \
or \
self.file_msg_list[0] in stdout,
True,
"%s don't have %s" % (self.file_msg_list, stdout))
self.document.trash()
self.assertEquals(exists(output_url), False)
def test_suite():
return make_suite(TestUnoConverter)
......
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