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

added support to run unit tests on an existing Data.fs, just pass the path to

the Data.fs and the id of the portal. catalog will be recreated unless you pass
--recreate_catalog=0 argument.
Note that DemoStorage cannot use read only FileStorage as a base and that
FileStorage uses a lock file, so it's impossible to run tests on a Data.fs
that's already in use.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10077 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f6053bb5
......@@ -146,6 +146,29 @@ portal_name = 'erp5_portal'
# prevent replaying the same failing setup step for each test.
failed_portal_installation = {}
def _getConnectionStringDict():
"""Returns the connection strings used for this test.
"""
connection_string_dict = {}
erp5_sql_connection_string = os.environ.get(
'erp5_sql_connection_string')
if erp5_sql_connection_string:
connection_string_dict['erp5_sql_connection_string'] = \
erp5_sql_connection_string
cmf_activity_sql_connection_string = os.environ.get(
'cmf_activity_sql_connection_string',
os.environ.get('erp5_sql_connection_string'))
if cmf_activity_sql_connection_string:
connection_string_dict['cmf_activity_sql_connection_string'] = \
cmf_activity_sql_connection_string
erp5_sql_deferred_connection_string = os.environ.get(
'erp5_sql_deferred_connection_string',
os.environ.get('erp5_sql_connection_string'))
if erp5_sql_deferred_connection_string:
connection_string_dict['erp5_sql_deferred_connection_string'] = \
erp5_sql_deferred_connection_string
return connection_string_dict
class ERP5TypeTestCase(PortalTestCase):
def getTitle(self):
......@@ -158,7 +181,12 @@ class ERP5TypeTestCase(PortalTestCase):
Return the name of a portal for this test case.
This is necessary for each test case to use a different portal built by
different business templates.
The test runner can set `erp5_tests_portal_id` environnement variable
to force a portal id.
"""
forced_portal_id = os.environ.get('erp5_tests_portal_id')
if forced_portal_id:
return str(forced_portal_id)
m = md5.new()
m.update(repr(self.getBusinessTemplateList())+ self.getTitle())
uid = m.hexdigest()
......@@ -271,6 +299,8 @@ class ERP5TypeTestCase(PortalTestCase):
create_activities=create_activities,
hot_reindexing=hot_reindexing)
PortalTestCase.setUp(self)
self._updateConnectionStrings()
self._recreateCatalog()
def afterSetUp(self):
'''Called after setUp() has completed. This is
......@@ -291,6 +321,39 @@ class ERP5TypeTestCase(PortalTestCase):
ZopeTestCase._print('\n%s ' % message)
LOG('Testing ... ', DEBUG, message)
def _updateConnectionStrings(self):
"""Update connection strings with values passed by the testRunner
"""
portal = self.getPortal()
# update connection strings
for connection_string_name, connection_string in\
_getConnectionStringDict().items():
connection_name = connection_string_name.replace('_string', '')
getattr(portal, connection_name).edit('', connection_string)
def _recreateCatalog(self, quiet=0):
"""Clear activities and catalog and recatalog everything.
Test runner can set `erp5_tests_recreate_catalog` environnement variable,
in that case we have to clear catalog. """
portal = self.getPortal()
if int(os.environ.get('erp5_tests_recreate_catalog', 0)):
try:
self.login()
_start = time.time()
if not quiet:
ZopeTestCase._print('\nRecreating catalog ... ')
portal.portal_activities.manageClearActivities()
portal.portal_catalog.manage_catalogClear()
get_transaction().commit()
portal.ERP5Site_reindexAll()
get_transaction().commit()
self.tic()
if not quiet:
ZopeTestCase._print('done (%.3fs)\n' % (time.time() - _start,))
finally:
os.environ['erp5_tests_recreate_catalog'] = '0'
noSecurityManager()
# Utility methods specific to ERP5Type
def getTemplateTool(self):
return getToolByName(self.getPortal(), 'portal_templates', None)
......@@ -389,7 +452,7 @@ def setupERP5Site( business_template_list=(),
'''
Creates an ERP5 site.
business_template_list must be specified correctly
(e.g. '("erp5_common", )').
(e.g. '("erp5_base", )').
'''
if portal_name in failed_portal_installation:
raise RuntimeError, 'Installation of %s already failed, giving up'\
......@@ -417,24 +480,7 @@ def setupERP5Site( business_template_list=(),
if not quiet:
ZopeTestCase._print('Adding %s ERP5 Site ... ' % portal_name)
extra_constructor_kw = {}
erp5_sql_connection_string = os.environ.get(
'erp5_sql_connection_string')
if erp5_sql_connection_string:
extra_constructor_kw['erp5_sql_connection_string'] = \
erp5_sql_connection_string
cmf_activity_sql_connection_string = os.environ.get(
'cmf_activity_sql_connection_string',
os.environ.get('erp5_sql_connection_string'))
if cmf_activity_sql_connection_string:
extra_constructor_kw['cmf_activity_sql_connection_string'] = \
cmf_activity_sql_connection_string
erp5_sql_deferred_connection_string = os.environ.get(
'erp5_sql_deferred_connection_string',
os.environ.get('erp5_sql_connection_string'))
if erp5_sql_deferred_connection_string:
extra_constructor_kw['erp5_sql_deferred_connection_string'] = \
erp5_sql_deferred_connection_string
extra_constructor_kw = _getConnectionStringDict()
email_from_address = os.environ.get('email_from_address')
if email_from_address is not None:
extra_constructor_kw['email_from_address'] = email_from_address
......@@ -517,6 +563,8 @@ def setupERP5Site( business_template_list=(),
ZopeTestCase._print(f.getvalue())
f.close()
failed_portal_installation[portal_name] = 1
ZopeTestCase._print('Ran Unit test of %s (installation failed)\n'
% title) # run_unit_test depends on this string.
raise
def optimize():
......
import ZODB
import os
from ZODB.DemoStorage import DemoStorage
from ZODB.FileStorage import FileStorage
data_fs_path = os.environ.get('erp5_tests_data_fs_path')
if data_fs_path:
Storage = DemoStorage(base=FileStorage(data_fs_path), quota=(1<<20))
else:
Storage = DemoStorage(quota=(1<<20))
Storage = DemoStorage(quota=(1<<20))
......@@ -10,6 +10,15 @@ usage: %(program)s [options] [UnitTest1[:TestClass1[:TestClass2]] [UnitTest2]]
Options:
-v, --verbose produce verbose output
-h, --help this help screen
--portal_id=STRING force id of the portal. Usefull when using
--data_fs_path to run tests on an existing
Data.fs
--data_fs_path=STRING Path to the orginal Data.fs to run tests on an
existing environment. The Data.fs is openned read
only
--recreate_catalog=0 or 1 recreate the content of the sql catalog. Defaults
is to recreate, when using an existing Data.fs
--erp5_sql_connection_string=STRING
ZSQL Connection string for erp5_sql_connection, by
default, it will use "test test"
......@@ -177,7 +186,8 @@ def usage(stream, msg=None):
def main():
try:
opts, args = getopt.getopt(sys.argv[1:],
"hv", ["help", "verbose", "erp5_sql_connection_string=",
"hv", ["help", "verbose", "portal_id=", "data_fs_path=",
"recreate_catalog=", "erp5_sql_connection_string=",
"cmf_activity_sql_connection_string=",
"erp5_deferred_sql_connection_string=",
"email_from_address="] )
......@@ -185,12 +195,21 @@ def main():
usage(sys.stderr, msg)
sys.exit(2)
os.environ["erp5_tests_recreate_catalog"] = "0"
for opt, arg in opts:
if opt in ("-v", "--verbose"):
os.environ['VERBOSE'] = "1"
elif opt in ("-h", "--help"):
usage(sys.stdout)
sys.exit()
elif opt == '--portal_id':
os.environ["erp5_tests_portal_id"] = arg
elif opt == '--data_fs_path':
os.environ["erp5_tests_data_fs_path"] = arg
os.environ["erp5_tests_recreate_catalog"] = "1"
elif opt == '--recreate_catalog':
os.environ["erp5_tests_recreate_catalog"] = arg
elif opt == "--erp5_sql_connection_string":
os.environ["erp5_sql_connection_string"] = arg
elif opt == "--cmf_activity_sql_connection_string":
......
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