Commit caf1f2ea authored by Priscila Manhaes's avatar Priscila Manhaes

implemented new method to test run_convert

parent 67d9ee33
This diff is collapsed.
...@@ -4,6 +4,7 @@ from os import environ ...@@ -4,6 +4,7 @@ from os import environ
from ConfigParser import ConfigParser from ConfigParser import ConfigParser
from xmlrpclib import ServerProxy, Fault from xmlrpclib import ServerProxy, Fault
from magic import Magic from magic import Magic
from types import DictType
from base64 import encodestring, decodestring from base64 import encodestring, decodestring
config = ConfigParser() config = ConfigParser()
...@@ -26,6 +27,10 @@ class TestCase(unittest.TestCase): ...@@ -26,6 +27,10 @@ class TestCase(unittest.TestCase):
self.env_path = config.get("app:main", "env-path") self.env_path = config.get("app:main", "env-path")
self.proxy = ServerProxy(("http://%s:%s/RPC2" % (self.hostname, self.port)),\ self.proxy = ServerProxy(("http://%s:%s/RPC2" % (self.hostname, self.port)),\
allow_none=True) allow_none=True)
self.afterSetUp()
def afterSetUp(self):
"""Must be overwrite into subclass in case of need """
def _getFileType(self, output_data): def _getFileType(self, output_data):
mime = Magic(mime=True) mime = Magic(mime=True)
...@@ -74,6 +79,24 @@ class TestCase(unittest.TestCase): ...@@ -74,6 +79,24 @@ class TestCase(unittest.TestCase):
for key,value in metadata_dict.iteritems(): for key,value in metadata_dict.iteritems():
self.assertEquals(new_metadata_dict[key], value) self.assertEquals(new_metadata_dict[key], value)
def _testRunConvert(self, filename, data, expected_response_code,
response_dict_data,response_dict_keys,
expected_response_message, response_dict_meta=None):
"""Generic test for run_convert"""
response_code, response_dict, response_message = \
self.proxy.run_convert(filename, encodestring(data))
self.assertEquals(response_code, expected_response_code)
self.assertEquals(type(response_dict), DictType)
if expected_response_code == 402:
self.assertEquals(response_dict, {})
self.assertTrue(response_message.endswith(expected_response_message),
"%s != %s" % (response_message, expected_response_message))
else:
self.assertNotEquals(response_dict['data'], response_dict_data)
self.assertEquals(sorted(response_dict.keys()), response_dict_keys)
self.assertEquals(response_message, expected_response_message)
self.assertEquals(response_dict['meta']['MIMEType'], response_dict_meta)
def ConversionScenarioList(self): def ConversionScenarioList(self):
""" """
Method used to convert files Method used to convert files
...@@ -129,3 +152,13 @@ class TestCase(unittest.TestCase): ...@@ -129,3 +152,13 @@ class TestCase(unittest.TestCase):
for scenario in scenarios: for scenario in scenarios:
self._testFaultGetMetadata(*scenario) self._testFaultGetMetadata(*scenario)
def ConvertScenarioList(self):
"""
Method to verify run_convert
must be overwrited into subclasses
"""
return []
def runConvertScenarioList(self, scenarios):
for scenario in scenarios:
self._testRunConvert(*scenario)
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