Commit a92728b3 authored by Priscila Manhaes's avatar Priscila Manhaes

modified for verifing connetion, added make_suite for running all tests into file

parent d36c8223
import unittest import unittest
import sys
from os import environ
from ConfigParser import ConfigParser
from xmlrpclib import ServerProxy from xmlrpclib import ServerProxy
from magic import Magic from magic import Magic
from base64 import encodestring, decodestring
config = ConfigParser()
def make_suite(test_case):
"""Function is used to run all tests together"""
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(test_case))
return suite
class TestCase(unittest.TestCase): class TestCase(unittest.TestCase):
def getConnection(self): def setUp(self):
proxy_address = "http://%s:%s" % (HOSTNAME, PORT) server_cloudooo_conf = environ.get("server_cloudooo_conf", None)
proxy = ServerProxy(proxy_address, allow_none=True) if server_cloudooo_conf is not None:
return proxy config.read(server_cloudooo_conf)
self.hostname = config.get("server:main", "host")
self.port = config.get("server:main", "port")
self.proxy = ServerProxy(("http://%s:%s/RPC2" % (self.hostname, self.port)),\
allow_none=True)
def _getFileType(self, output_data): def _getFileType(self, output_data):
mime = Magic(mime=True) mime = Magic(mime=True)
mimetype = mime.from_buffer(decodestring(output_data)) mimetype = mime.from_buffer(decodestring(output_data))
return mimetype
def _testConvertFile(self, input_url, source_format, destination_format, def _testConvertFile(self, input_url, source_format, destination_format,
destination_mimetype): destination_mimetype):
""" Generic test for converting file """ """ Generic test for converting file """
output_data = proxy.convertFile(encodestring(open(input_url).read()), output_data = self.proxy.convertFile(encodestring(open(input_url).read()),
source_format, source_format,
destination_format) destination_format)
file_type = self._getFileType(output_data) file_type = self._getFileType(output_data)
self.assertEquals(mimetype, destination_mimetype) self.assertEquals(file_type, destination_mimetype)
def _testGetMetadata(self, input_url, source_format, key, value): def _testGetMetadata(self, input_url, source_format, key, value):
""" Generic tes for getting metadata file""" """ Generic tes for getting metadata file"""
metadata_dict = proxy.getFileMetadataItemList( metadata_dict = self.proxy.getFileMetadataItemList(
encodestring(open(input_url).read()), encodestring(open(input_url).read()),
source_format) source_format)
self.assertEquals(metadata_dict[key], value) self.assertEquals(metadata_dict[key], value)
def _testUpdateMetadata(self, input_url, source_format, metadata_dict): def _testUpdateMetadata(self, input_url, source_format, metadata_dict):
""" Generic test for setting metadata for file """ """ Generic test for setting metadata for file """
output_data = proxy.updateFileMetadata(encodestring(open(input_url).read()), output_data = self.proxy.updateFileMetadata(encodestring(open(input_url).read()),
source_format, source_format,
metadata_dict) metadata_dict)
new_metadata_dict = proxy.getFileMetadataItemList( new_metadata_dict = proxy.getFileMetadataItemList(
...@@ -43,23 +60,23 @@ class TestCase(unittest.TestCase): ...@@ -43,23 +60,23 @@ class TestCase(unittest.TestCase):
"""This method must be overwrited into subclasses""" """This method must be overwrited into subclasses"""
return [] return []
def getConversionList(self): def runConversionList(self, scenarios):
for scenario in self.getConversionScenarioList(): for scenario in scenarios:
self._testConvertFile(*scenario) self._testConvertFile(*scenario)
def getGetMetadataScenarioList(self): def getGetMetadataScenarioList(self):
"""This method must be overwrited into subclasses""" """This method must be overwrited into subclasses"""
return [] return []
def getGetMetadataList(self): def runGetMetadataList(self, scenarios):
for scenario in self.getGetMetadataScenarioList(): for scenario in scenarios:
self._testGetMetadata(*scenario) self._testGetMetadata(*scenario)
def getUpdateMetadataScenarioList(self): def getUpdateMetadataScenarioList(self):
"""This method must be overwrited into subclasses""" """This method must be overwrited into subclasses"""
return [] return []
def getUpdateMetadataList(self): def runtUpdateMetadataList(self, scenarios):
for scenario in self.getUpdateMetadataScenarioList(): for scenario in scenarios:
self._testUpdateMetadata(*scenario) self._testUpdateMetadata(*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