Commit 60dda98b authored by Priscila Manhaes's avatar Priscila Manhaes

refactor to cloudoootestcase

parent f013ec03
...@@ -26,59 +26,47 @@ ...@@ -26,59 +26,47 @@
# #
############################################################################## ##############################################################################
from xmlrpclib import ServerProxy, Fault from xmlrpclib import Fault
from base64 import encodestring, decodestring from cloudooo.tests.cloudoooTestCase import TestCase, make_suite
from cloudooo.tests.handlerTestCase import HandlerTestCase, make_suite from base64 import encodestring
import magic
file_detector = magic.Magic() class TestAllFormatsERP5Compatibility(TestCase):
DAEMON = True
class TestAllFormatsERP5Compatibility(HandlerTestCase):
""" """
Test XmlRpc Server using ERP5 compatibility API. Test XmlRpc Server using ERP5 compatibility API.
Needs cloudooo server started Needs cloudooo server started
""" """
def afterSetUp(self):
"""Create connection with cloudooo server"""
self.proxy = ServerProxy("http://%s:%s/RPC2" % (self.hostname,
self.cloudooo_port),
allow_none=True)
def testTextFormats(self): def testTextFormats(self):
"""Test all text formats""" """Test all text formats"""
self.runTestForType('odt', 'application/vnd.oasis.opendocument.text', 'data/test.odt') self.runTestForType('data/test.odt', 'odt', 'application/vnd.oasis.opendocument.text')
def testPresentationFormats(self): def testPresentationFormats(self):
"""Test all presentation formats""" """Test all presentation formats"""
self.runTestForType('odp', 'application/vnd.oasis.opendocument.presentation', 'data/test.odp') self.runTestForType('data/test.odp', 'odp', 'application/vnd.oasis.opendocument.presentation')
def testDrawingFormats(self): def testDrawingFormats(self):
"""Test all drawing formats""" """Test all drawing formats"""
self.runTestForType('odg', 'application/vnd.oasis.opendocument.graphics', 'data/test.odg') self.runTestForType('data/test.odg', 'odg', 'application/vnd.oasis.opendocument.graphics')
def testSpreadSheetFormats(self): def testSpreadSheetFormats(self):
"""Test all spreadsheet formats""" """Test all spreadsheet formats"""
self.runTestForType('ods', 'application/vnd.oasis.opendocument.spreadsheet', 'data/test.ods') self.runTestForType('data/test.ods', 'ods', 'application/vnd.oasis.opendocument.spreadsheet')
def runTestForType(self, source_format, mime_type, filename): def runTestForType(self, filename, source_format, source_mimetype):
"""Generic test""" """Generic test"""
data = open(filename, 'r').read() extension_list = self.proxy.getAllowedTargetItemList(source_mimetype)[1]['response_data']
extension_list = self.proxy.getAllowedTargetItemList(mime_type)[1]['response_data']
fault_list = [] fault_list = []
for extension, format in extension_list: for extension, format in extension_list:
try: try:
data_output = self.proxy.run_generate(filename, data_output = self.proxy.run_generate(filename,
encodestring(data), encodestring(
open(filename).read()),
None, None,
extension, extension,
mime_type)[1]['data'] source_mimetype)[1]['data']
magic_result = file_detector.from_buffer(decodestring(data_output)) file_type = self._getFileType(data_output)
file_is_empty = magic_result.endswith(": empty") if file_type.endswith(": empty"):
if file_is_empty: fault_list.append((source_format, extension, file_type))
fault_list.append((source_format, extension, magic_result))
except Fault, err: except Fault, err:
fault_list.append((source_format, extension, err.faultString)) fault_list.append((source_format, extension, err.faultString))
if fault_list: if fault_list:
......
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