Commit ea7311b9 authored by Gabriel Monnerat's avatar Gabriel Monnerat

refactor tests to work correctly and be possible pass the configuration file as argument

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@37680 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent fa6924f9
...@@ -60,6 +60,8 @@ def startFakeEnvironment(start_openoffice=True, conf_path=None): ...@@ -60,6 +60,8 @@ def startFakeEnvironment(start_openoffice=True, conf_path=None):
hostname = config.get("server:main", "host") hostname = config.get("server:main", "host")
openoffice_port = int(config.get("app:main", "openoffice_port")) openoffice_port = int(config.get("app:main", "openoffice_port"))
office_bin_path = config.get("app:main", "office_bin_path") office_bin_path = config.get("app:main", "office_bin_path")
openoffice_tester_bin = config.get("app:main", "openoffice_tester_bin")
if not environ.get('uno_path'): if not environ.get('uno_path'):
environ['uno_path'] = uno_path environ['uno_path'] = uno_path
...@@ -88,7 +90,8 @@ def startFakeEnvironment(start_openoffice=True, conf_path=None): ...@@ -88,7 +90,8 @@ def startFakeEnvironment(start_openoffice=True, conf_path=None):
path_dir_run_cloudooo, path_dir_run_cloudooo,
virtual_display_id, virtual_display_id,
office_bin_path, office_bin_path,
uno_path) uno_path,
openoffice_tester_bin=openoffice_tester_bin)
openoffice.start() openoffice.start()
openoffice.acquire() openoffice.acquire()
hostname, port = openoffice.getAddress() hostname, port = openoffice.getAddress()
...@@ -128,6 +131,7 @@ class cloudoooTestCase(unittest.TestCase): ...@@ -128,6 +131,7 @@ class cloudoooTestCase(unittest.TestCase):
self.python_path = config.get("app:main", "python_path") self.python_path = config.get("app:main", "python_path")
self.virtual_display_id = config.get("app:main", "virtual_display_id") self.virtual_display_id = config.get("app:main", "virtual_display_id")
self.virtual_display_port_int = config.get("app:main", "virtual_display_port") self.virtual_display_port_int = config.get("app:main", "virtual_display_port")
self.openoffice_tester_bin = config.get("app:main", "openoffice_tester_bin")
self.afterSetUp() self.afterSetUp()
def afterSetUp(self): def afterSetUp(self):
......
...@@ -85,5 +85,8 @@ def test_suite(): ...@@ -85,5 +85,8 @@ def test_suite():
return make_suite(TestAllFormats) return make_suite(TestAllFormats)
if __name__ == "__main__": if __name__ == "__main__":
import sys
from cloudoooTestCase import loadConfig
loadConfig(sys.argv[1])
suite = unittest.TestLoader().loadTestsFromTestCase(TestAllFormats) suite = unittest.TestLoader().loadTestsFromTestCase(TestAllFormats)
unittest.TextTestRunner(verbosity=2).run(suite) unittest.TextTestRunner(verbosity=2).run(suite)
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
import unittest import unittest
from cloudooo.application.application import Application from cloudooo.application.application import Application
from os.path import exists
from cloudoooTestCase import make_suite from cloudoooTestCase import make_suite
class TestApplication(unittest.TestCase): class TestApplication(unittest.TestCase):
...@@ -44,7 +43,6 @@ class TestApplication(unittest.TestCase): ...@@ -44,7 +43,6 @@ class TestApplication(unittest.TestCase):
self.assertEquals(self.application.port, 9999) self.assertEquals(self.application.port, 9999)
self.assertEquals(self.application.path_run_dir, '/tmp/') self.assertEquals(self.application.path_run_dir, '/tmp/')
self.assertEquals(self.application.display_id, '99') self.assertEquals(self.application.display_id, '99')
self.assertEquals(self.application.pid_filepath, "/tmp/application.pid")
def testStartTimeout(self): def testStartTimeout(self):
"""Test if the attribute timeout is defined correctly""" """Test if the attribute timeout is defined correctly"""
...@@ -61,13 +59,6 @@ class TestApplication(unittest.TestCase): ...@@ -61,13 +59,6 @@ class TestApplication(unittest.TestCase):
"""As the application do not have the pid() should return None""" """As the application do not have the pid() should return None"""
self.assertEquals(self.application.pid(), None) self.assertEquals(self.application.pid(), None)
def testStart(self):
""" """
self.application.start()
self.assertEquals(exists(self.application.pid_filepath), True)
self.application.stop()
self.assertEquals(exists(self.application.pid_filepath), False)
def test_suite(): def test_suite():
return make_suite(TestApplication) return make_suite(TestApplication)
......
...@@ -72,5 +72,8 @@ def test_suite(): ...@@ -72,5 +72,8 @@ def test_suite():
return make_suite(TestHighLoad) return make_suite(TestHighLoad)
if __name__ == "__main__": if __name__ == "__main__":
import sys
from cloudoooTestCase import loadConfig
loadConfig(sys.argv[1])
suite = unittest.TestLoader().loadTestsFromTestCase(TestHighLoad) suite = unittest.TestLoader().loadTestsFromTestCase(TestHighLoad)
unittest.TextTestRunner(verbosity=2).run(suite) unittest.TextTestRunner(verbosity=2).run(suite)
...@@ -138,7 +138,7 @@ presentation_expected_tuple = (('bmp', 'BMP - Windows Bitmap'), ...@@ -138,7 +138,7 @@ presentation_expected_tuple = (('bmp', 'BMP - Windows Bitmap'),
('wmf', 'WMF - Windows Metafile'), ('wmf', 'WMF - Windows Metafile'),
('xhtml', 'XHTML'), ('xpm', 'XPM - X PixMap')) ('xhtml', 'XHTML'), ('xpm', 'XPM - X PixMap'))
spreadsheet_expected_tuple = (('csv', 'Text CSV'), spreadsheet_expected_list = (('csv', 'Text CSV'),
('htm', 'HTML Document (OpenOffice.org Calc)'), ('htm', 'HTML Document (OpenOffice.org Calc)'),
('html', 'HTML Document (OpenOffice.org Calc)'), ('html', 'HTML Document (OpenOffice.org Calc)'),
('html', 'XHTML'), ('ods', 'ODF Spreadsheet'), ('html', 'XHTML'), ('ods', 'ODF Spreadsheet'),
...@@ -254,32 +254,31 @@ class TestMimeMapper(cloudoooTestCase): ...@@ -254,32 +254,31 @@ class TestMimeMapper(cloudoooTestCase):
"""Test if function getAllowedExtensionList returns correctly a list with """Test if function getAllowedExtensionList returns correctly a list with
extensions that can generate with extension passed.""" extensions that can generate with extension passed."""
doc_got_list = list(self.mimemapper.getAllowedExtensionList('doc')) doc_got_list = list(self.mimemapper.getAllowedExtensionList('doc'))
doc_got_list.sort() for arg in doc_got_list:
text_expected_list = list(text_expected_tuple) self.assertTrue(arg in text_expected_tuple,
text_expected_list.sort() "%s not in %s" % (arg, text_expected_tuple))
self.assertEquals(doc_got_list, text_expected_list)
jpeg_got_list = list(self.mimemapper.getAllowedExtensionList('jpeg')) jpeg_got_list = list(self.mimemapper.getAllowedExtensionList('jpeg'))
jpeg_got_list.sort()
jpeg_expected_list = list(set(presentation_expected_tuple + jpeg_expected_list = list(set(presentation_expected_tuple +
drawing_expected_tuple)) drawing_expected_tuple))
jpeg_expected_list.sort() for arg in jpeg_got_list:
self.assertEquals(jpeg_got_list, jpeg_expected_list) self.assertTrue(arg in jpeg_expected_list,
"%s not in %s" % (arg, jpeg_expected_list))
pdf_got_list = list(self.mimemapper.getAllowedExtensionList('pdf')) pdf_got_list = list(self.mimemapper.getAllowedExtensionList('pdf'))
pdf_got_list.sort()
pdf_expected_list = list(set(presentation_expected_tuple + pdf_expected_list = list(set(presentation_expected_tuple +
drawing_expected_tuple + web_expected_tuple + global_expected_tuple + drawing_expected_tuple + web_expected_tuple + global_expected_tuple +
math_expected_tuple + text_expected_tuple + spreadsheet_expected_tuple)) math_expected_tuple + text_expected_tuple + spreadsheet_expected_list))
pdf_expected_list.sort() for arg in pdf_got_list:
self.assertEquals(pdf_got_list, pdf_expected_list) self.assertTrue(arg in pdf_expected_list,
"%s not in %s" % (arg, pdf_expected_list))
def testGetAllowedExtensionListForText(self): def testGetAllowedExtensionListForText(self):
"""Passing document_type equal to 'text', the return must be equal """Passing document_type equal to 'text', the return must be equal
to text_expected_tuple.""" to text_expected_tuple."""
got_list = list(self.mimemapper.getAllowedExtensionList(document_type='text')) got_list = list(self.mimemapper.getAllowedExtensionList(document_type='text'))
got_list.sort()
text_expected_list = list(text_expected_tuple) text_expected_list = list(text_expected_tuple)
text_expected_list.sort() for arg in got_list:
self.assertEquals(got_list, text_expected_list) self.assertTrue(arg in text_expected_list,
"%s not in %s" % (arg, text_expected_list))
def testGetAllowedExtensionListForGlobal(self): def testGetAllowedExtensionListForGlobal(self):
"""Passing document_type equal to 'global', the return must be equal """Passing document_type equal to 'global', the return must be equal
...@@ -294,10 +293,11 @@ class TestMimeMapper(cloudoooTestCase): ...@@ -294,10 +293,11 @@ class TestMimeMapper(cloudoooTestCase):
"""Passing document_type equal to 'drawing', the return must be equal """Passing document_type equal to 'drawing', the return must be equal
to drawing_expected_tuple.""" to drawing_expected_tuple."""
got_list = list(self.mimemapper.getAllowedExtensionList(document_type='drawing')) got_list = list(self.mimemapper.getAllowedExtensionList(document_type='drawing'))
got_list.sort()
drawing_expected_list = list(drawing_expected_tuple) drawing_expected_list = list(drawing_expected_tuple)
drawing_expected_list.sort() drawing_expected_list.sort()
self.assertEquals(got_list, drawing_expected_list) for arg in got_list:
self.assertTrue(arg in drawing_expected_list,
"%s not in %s" % (arg, drawing_expected_list))
def testGetAllAllowedExtensionListForWeb(self): def testGetAllAllowedExtensionListForWeb(self):
"""Passing document_type equal to 'web', the return must be equal """Passing document_type equal to 'web', the return must be equal
...@@ -313,16 +313,19 @@ class TestMimeMapper(cloudoooTestCase): ...@@ -313,16 +313,19 @@ class TestMimeMapper(cloudoooTestCase):
to presentation_expected_tuple.""" to presentation_expected_tuple."""
got_list = \ got_list = \
list(self.mimemapper.getAllowedExtensionList(document_type='presentation')) list(self.mimemapper.getAllowedExtensionList(document_type='presentation'))
got_list.sort()
presentation_expected_list = list(presentation_expected_tuple) presentation_expected_list = list(presentation_expected_tuple)
presentation_expected_list.sort() presentation_expected_list.sort()
self.assertEquals(got_list, presentation_expected_list) for arg in got_list:
self.assertTrue(arg in presentation_expected_list,
"%s not in %s" % (arg, presentation_expected_list))
def testGetAllAllowedExtensionListForSpreadsheet(self): def testGetAllAllowedExtensionListForSpreadsheet(self):
"""Passing document_type equal to 'spreadsheet', the return must be equal """Passing document_type equal to 'spreadsheet', the return must be equal
to spreadsheet_expected_tuple.""" to spreadsheet_expected_list."""
got_tuple = self.mimemapper.getAllowedExtensionList(document_type='spreadsheet') got_list = self.mimemapper.getAllowedExtensionList(document_type='spreadsheet')
self.assertEquals(sorted(got_tuple), sorted(spreadsheet_expected_tuple)) for arg in got_list:
self.assertTrue(arg in spreadsheet_expected_list,
"%s not in %s" % (arg, spreadsheet_expected_list))
def testGetAllAllowedExtensionListForChart(self): def testGetAllAllowedExtensionListForChart(self):
"""Passing document_type equal to 'chart', the return must be equal """Passing document_type equal to 'chart', the return must be equal
......
...@@ -71,5 +71,8 @@ def test_suite(): ...@@ -71,5 +71,8 @@ def test_suite():
return make_suite(TestMonitorInit) return make_suite(TestMonitorInit)
if "__main__" == __name__: if "__main__" == __name__:
import sys
from cloudoooTestCase import loadConfig
loadConfig(sys.argv[1])
suite = unittest.TestLoader().loadTestsFromTestCase(TestMonitorInit) suite = unittest.TestLoader().loadTestsFromTestCase(TestMonitorInit)
unittest.TextTestRunner(verbosity=2).run(suite) unittest.TextTestRunner(verbosity=2).run(suite)
...@@ -42,7 +42,8 @@ class TestOpenOffice(cloudoooTestCase): ...@@ -42,7 +42,8 @@ class TestOpenOffice(cloudoooTestCase):
self.path_dir_run_cloudooo, self.path_dir_run_cloudooo,
self.virtual_display_id, self.virtual_display_id,
self.office_bin_path, self.office_bin_path,
self.uno_path) self.uno_path,
openoffice_tester_bin=self.openoffice_tester_bin)
self.openoffice.start() self.openoffice.start()
def tearDown(self): def tearDown(self):
......
...@@ -42,6 +42,7 @@ class TestServer(cloudoooTestCase): ...@@ -42,6 +42,7 @@ class TestServer(cloudoooTestCase):
"""Creates a connection with cloudooo server""" """Creates a connection with cloudooo server"""
self.proxy = ServerProxy("http://%s:%s/RPC2" % \ self.proxy = ServerProxy("http://%s:%s/RPC2" % \
(self.hostname, self.cloudooo_port), allow_none=True) (self.hostname, self.cloudooo_port), allow_none=True)
self.text_expected_list = [['doc', 'Microsoft Word 6.0'], self.text_expected_list = [['doc', 'Microsoft Word 6.0'],
['doc', 'Microsoft Word 95'], ['doc', 'Microsoft Word 95'],
['doc', 'Microsoft Word 97/2000/XP'], ['doc', 'Microsoft Word 97/2000/XP'],
...@@ -116,19 +117,24 @@ class TestServer(cloudoooTestCase): ...@@ -116,19 +117,24 @@ class TestServer(cloudoooTestCase):
text_request = {'document_type':"text"} text_request = {'document_type':"text"}
text_allowed_list = self.proxy.getAllowedExtensionList(text_request) text_allowed_list = self.proxy.getAllowedExtensionList(text_request)
text_allowed_list.sort() text_allowed_list.sort()
self.assertEquals(text_allowed_list, self.text_expected_list) for arg in text_allowed_list:
self.assertTrue(arg in self.text_expected_list,
"%s not in %s" % (arg, self.text_expected_list))
request_dict = {'document_type':"presentation"} request_dict = {'document_type':"presentation"}
presentation_allowed_list = self.proxy.getAllowedExtensionList(request_dict) presentation_allowed_list = self.proxy.getAllowedExtensionList(request_dict)
presentation_allowed_list.sort() presentation_allowed_list.sort()
self.assertEquals(presentation_allowed_list, for arg in presentation_allowed_list:
self.presentation_expected_list) self.assertTrue(arg in self.presentation_expected_list,
"%s not in %s" % (arg, self.presentation_expected_list))
def testGetAllowedExtensionListByExtension(self): def testGetAllowedExtensionListByExtension(self):
"""Call getAllowedExtensionList and verify if the returns is a list with """Call getAllowedExtensionList and verify if the returns is a list with
extension and ui_name. The request is by extension""" extension and ui_name. The request is by extension"""
doc_allowed_list = self.proxy.getAllowedExtensionList({'extension':"doc"}) doc_allowed_list = self.proxy.getAllowedExtensionList({'extension':"doc"})
doc_allowed_list.sort() doc_allowed_list.sort()
self.assertEquals(doc_allowed_list, self.text_expected_list) for arg in doc_allowed_list:
self.assertTrue(arg in self.text_expected_list,
"%s not in %s" % (arg, self.text_expected_list))
def testGetAllowedExtensionListByMimetype(self): def testGetAllowedExtensionListByMimetype(self):
"""Call getAllowedExtensionList and verify if the returns is a list with """Call getAllowedExtensionList and verify if the returns is a list with
...@@ -136,7 +142,9 @@ class TestServer(cloudoooTestCase): ...@@ -136,7 +142,9 @@ class TestServer(cloudoooTestCase):
request_dict = {"mimetype":"application/msword"} request_dict = {"mimetype":"application/msword"}
msword_allowed_list = self.proxy.getAllowedExtensionList(request_dict) msword_allowed_list = self.proxy.getAllowedExtensionList(request_dict)
msword_allowed_list.sort() msword_allowed_list.sort()
self.assertEquals(msword_allowed_list, self.text_expected_list) for arg in msword_allowed_list:
self.assertTrue(arg in self.text_expected_list,
"%s not in %s" % (arg, self.text_expected_list))
def testConvertDocToOdt(self): def testConvertDocToOdt(self):
"""Test Convert Doc -> Odt""" """Test Convert Doc -> Odt"""
...@@ -469,7 +477,6 @@ at least v2.0 to extract\n' ...@@ -469,7 +477,6 @@ at least v2.0 to extract\n'
def testRunSetMetadata(self): def testRunSetMetadata(self):
"""Test run_setmetadata method""" """Test run_setmetadata method"""
document_output_url = "output/testSetMetadata.odt"
data = open(join('data','testMetadata.odt'),'r').read() data = open(join('data','testMetadata.odt'),'r').read()
setmetadata_result = self.proxy.run_setmetadata('testMetadata.odt', setmetadata_result = self.proxy.run_setmetadata('testMetadata.odt',
encodestring(data), encodestring(data),
...@@ -487,7 +494,6 @@ at least v2.0 to extract\n' ...@@ -487,7 +494,6 @@ at least v2.0 to extract\n'
def testRunSetMetadataFailResponse(self): def testRunSetMetadataFailResponse(self):
"""Test run_setmetadata method with invalid document""" """Test run_setmetadata method with invalid document"""
document_output_url = "output/testSetMetadata.odt"
data = open(join('data','testMetadata.odt'),'r').read()[:100] data = open(join('data','testMetadata.odt'),'r').read()[:100]
setmetadata_result = self.proxy.run_setmetadata('testMetadata.odt', setmetadata_result = self.proxy.run_setmetadata('testMetadata.odt',
encodestring(data), encodestring(data),
...@@ -503,12 +509,15 @@ at least v2.0 to extract\n' ...@@ -503,12 +509,15 @@ at least v2.0 to extract\n'
response_code, response_dict, response_message = \ response_code, response_dict, response_message = \
self.proxy.getAllowedTargetItemList(mimetype) self.proxy.getAllowedTargetItemList(mimetype)
self.assertEquals(response_code, 200) self.assertEquals(response_code, 200)
self.assertEquals(len(response_dict['response_data']), 35) self.assertEquals(len(response_dict['response_data']), 28)
self.assertTrue(['htm', 'HTML Document'] in response_dict['response_data']) self.assertTrue(['htm', 'HTML Document'] in response_dict['response_data'])
def test_suite(): def test_suite():
return make_suite(TestServer) return make_suite(TestServer)
if __name__ == "__main__": if __name__ == "__main__":
import sys
from cloudoooTestCase import loadConfig
loadConfig(sys.argv[1])
suite = unittest.TestLoader().loadTestsFromTestCase(TestServer) suite = unittest.TestLoader().loadTestsFromTestCase(TestServer)
unittest.TextTestRunner(verbosity=2).run(suite) unittest.TextTestRunner(verbosity=2).run(suite)
...@@ -68,5 +68,8 @@ def test_suite(): ...@@ -68,5 +68,8 @@ def test_suite():
return make_suite(TestXvfb) return make_suite(TestXvfb)
if "__main__" == __name__: if "__main__" == __name__:
import sys
from cloudoooTestCase import loadConfig
loadConfig(sys.argv[1])
suite = unittest.TestLoader().loadTestsFromTestCase(TestXvfb) suite = unittest.TestLoader().loadTestsFromTestCase(TestXvfb)
unittest.TextTestRunner(verbosity=2).run(suite) unittest.TextTestRunner(verbosity=2).run(suite)
from setuptools import setup, find_packages from setuptools import setup, find_packages
version = '1.0.2' version = '1.0.3'
setup(name='cloudooo', setup(name='cloudooo',
version=version, version=version,
......
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