Commit e751239c authored by Jérome Perrin's avatar Jérome Perrin

testOOoServer: reorganize/modernize test

Split into several test classes for easier maintainance
parent df013e4a
...@@ -39,8 +39,9 @@ import magic ...@@ -39,8 +39,9 @@ import magic
from cloudooo.handler.ooo.tests.testOooMimemapper import text_expected_tuple, presentation_expected_tuple from cloudooo.handler.ooo.tests.testOooMimemapper import text_expected_tuple, presentation_expected_tuple
class TestServer(TestCase): """Tests for XmlRpc Server. Needs cloudooo server started"""
"""Test XmlRpc Server. Needs cloudooo server started"""
class TestAllowedExtensions(TestCase):
def testGetAllowedTextExtensionListByType(self): def testGetAllowedTextExtensionListByType(self):
"""Verify if getAllowedExtensionList returns is a list with extension and """Verify if getAllowedExtensionList returns is a list with extension and
...@@ -83,6 +84,10 @@ class TestServer(TestCase): ...@@ -83,6 +84,10 @@ class TestServer(TestCase):
self.assertEquals(sorted([(a, b) for a, b in msword_allowed_list if a not in ("doc", "docy")]), self.assertEquals(sorted([(a, b) for a, b in msword_allowed_list if a not in ("doc", "docy")]),
sorted(list(filter(lambda (a, b): a not in ("doc", "docy"), text_expected_tuple)))) sorted(list(filter(lambda (a, b): a not in ("doc", "docy"), text_expected_tuple))))
class TestConversion(TestCase):
"""Test that conversion of some test documents to various destination format does not fail.
"""
def ConversionScenarioList(self): def ConversionScenarioList(self):
return [ return [
# Test Convert Doc -> Odt # Test Convert Doc -> Odt
...@@ -129,7 +134,24 @@ class TestServer(TestCase): ...@@ -129,7 +134,24 @@ class TestServer(TestCase):
"opendocument.presentation"), "opendocument.presentation"),
]) ])
def ConvertScenarioList(self):
return [
# Test run_convert method
('test.doc', open(join('data', 'test.doc')).read(), 200, '',
['data', 'meta', 'mime'], '', 'application/vnd.oasis.opendocument.text'
),
# Test run_convert method with invalid file
('test.doc', open(join('data', 'test.doc')).read()[:30], 200, '',
['data', 'meta', 'mime'], '', 'application/vnd.oasis.opendocument.text'
),
]
def testRunConvertMethod(self):
"""Test run_convert method"""
self.runConvertScenarioList(self.ConvertScenarioList())
class TestGetMetadata(TestCase):
def GetMetadataScenarioList(self): def GetMetadataScenarioList(self):
return [ return [
# Test method getFileMetadataItemList. Without data converted # Test method getFileMetadataItemList. Without data converted
...@@ -191,21 +213,6 @@ class TestServer(TestCase): ...@@ -191,21 +213,6 @@ class TestServer(TestCase):
self.assertEquals(metadata_dict.get("Reference"), "new value") self.assertEquals(metadata_dict.get("Reference"), "new value")
self.assertEquals(metadata_dict.get("Something"), "ABC") self.assertEquals(metadata_dict.get("Something"), "ABC")
def ConvertScenarioList(self):
return [
# Test run_convert method
('test.doc', open(join('data', 'test.doc')).read(), 200, '',
['data', 'meta', 'mime'], '', 'application/vnd.oasis.opendocument.text'
),
# Test run_convert method with invalid file
('test.doc', open(join('data', 'test.doc')).read()[:30], 200, '',
['data', 'meta', 'mime'], '', 'application/vnd.oasis.opendocument.text'
),
]
def testRunConvertMethod(self):
"""Test run_convert method"""
self.runConvertScenarioList(self.ConvertScenarioList())
# XXX: This is a test for ERP5 Backward compatibility, # XXX: This is a test for ERP5 Backward compatibility,
# and the support to this kind of tests will be dropped. # and the support to this kind of tests will be dropped.
...@@ -222,6 +229,8 @@ class TestServer(TestCase): ...@@ -222,6 +229,8 @@ class TestServer(TestCase):
self.assertNotEquals(response_dict['data'], '') self.assertNotEquals(response_dict['data'], '')
self.assertEquals(response_dict['mime'], 'application/pdf') self.assertEquals(response_dict['mime'], 'application/pdf')
class TestGenerate(TestCase):
# XXX: This is a test for ERP5 Backward compatibility, # XXX: This is a test for ERP5 Backward compatibility,
# and the support to this kind of tests will be dropped. # and the support to this kind of tests will be dropped.
def testRunGenerateMethodConvertOdsToHTML(self): def testRunGenerateMethodConvertOdsToHTML(self):
...@@ -337,6 +346,8 @@ class TestServer(TestCase): ...@@ -337,6 +346,8 @@ class TestServer(TestCase):
self.assertEquals(response_dict, {}) self.assertEquals(response_dict, {})
self.assertTrue(response_message.startswith('Traceback')) self.assertTrue(response_message.startswith('Traceback'))
class TestSetMetadata(TestCase):
def testRunSetMetadata(self): def testRunSetMetadata(self):
"""Test run_setmetadata method, updating the same metadata""" """Test run_setmetadata method, updating the same metadata"""
setmetadata_result = self.proxy.run_setmetadata('testMetadata.odt', setmetadata_result = self.proxy.run_setmetadata('testMetadata.odt',
...@@ -377,6 +388,8 @@ class TestServer(TestCase): ...@@ -377,6 +388,8 @@ class TestServer(TestCase):
self.assertEquals(response_dict, {}) self.assertEquals(response_dict, {})
self.assertTrue(response_message.startswith('Traceback')) self.assertTrue(response_message.startswith('Traceback'))
class TestGetAllowedTargetItemList(TestCase):
def testGetAllowedTargetItemList(self): def testGetAllowedTargetItemList(self):
"""Test if filter name returns correctly with ERP5 API""" """Test if filter name returns correctly with ERP5 API"""
mimetype = 'application/vnd.oasis.opendocument.text' mimetype = 'application/vnd.oasis.opendocument.text'
...@@ -390,6 +403,8 @@ class TestServer(TestCase): ...@@ -390,6 +403,8 @@ class TestServer(TestCase):
sorted([(a, b) for a, b in response_dict['response_data'] if a not in ("odt", "docy")]), sorted([(a, b) for a, b in response_dict['response_data'] if a not in ("odt", "docy")]),
sorted(list(filter(lambda (a, b): a not in ("odt", "docy"), text_expected_tuple)))) sorted(list(filter(lambda (a, b): a not in ("odt", "docy"), text_expected_tuple))))
class TestGetTableItemList(TestCase):
def testGetTableItemListFromOdt(self): def testGetTableItemListFromOdt(self):
"""Test if getTableItemList can get the table item list from odt file""" """Test if getTableItemList can get the table item list from odt file"""
table_list = [['Developers', ''], table_list = [['Developers', ''],
...@@ -476,6 +491,8 @@ class TestServer(TestCase): ...@@ -476,6 +491,8 @@ class TestServer(TestCase):
['Phone', '+55 (22) 9999-9999'], ['Phone', '+55 (22) 9999-9999'],
['Email', 'rafael@tiolive.com']], line_item_list) ['Email', 'rafael@tiolive.com']], line_item_list)
class TestImagetItemList(TestCase):
def testGetImageItemListFromOdt(self): def testGetImageItemListFromOdt(self):
"""Test if getImageItemList can get the list of images items from odt file""" """Test if getImageItemList can get the list of images items from odt file"""
data = encodestring(open("./data/granulate_test.odt").read()) data = encodestring(open("./data/granulate_test.odt").read())
...@@ -519,6 +536,8 @@ class TestServer(TestCase): ...@@ -519,6 +536,8 @@ class TestServer(TestCase):
geted_image = decodestring(self.proxy.getImage(data, image_id, "doc")) geted_image = decodestring(self.proxy.getImage(data, image_id, "doc"))
self.assertEquals(original_image, geted_image) self.assertEquals(original_image, geted_image)
class TestParagraphItemList(TestCase):
def testGetParagraphItemList(self): def testGetParagraphItemList(self):
"""Test if getParagraphItemList can get paragraphs correctly from document""" """Test if getParagraphItemList can get paragraphs correctly from document"""
data = encodestring(open("./data/granulate_test.odt").read()) data = encodestring(open("./data/granulate_test.odt").read())
...@@ -537,6 +556,8 @@ class TestServer(TestCase): ...@@ -537,6 +556,8 @@ class TestServer(TestCase):
paragraph = self.proxy.getParagraph(data, 1, "odt") paragraph = self.proxy.getParagraph(data, 1, "odt")
self.assertEquals(['', 'P1'], paragraph) self.assertEquals(['', 'P1'], paragraph)
class TestChapterItemList(TestCase):
def testGetChapterItemList(self): def testGetChapterItemList(self):
"""Test if getChapterItemList can get the chapters list correctly from document""" """Test if getChapterItemList can get the chapters list correctly from document"""
data = encodestring(open("./data/granulate_chapters_test.odt").read()) data = encodestring(open("./data/granulate_chapters_test.odt").read())
......
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