[Erp5-report] r10077 - /erp5/trunk/products/ERP5Type/tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Mon Sep 18 10:52:56 CEST 2006
Author: jerome
Date: Mon Sep 18 10:52:54 2006
New Revision: 10077
URL: http://svn.erp5.org?rev=10077&view=rev
Log:
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.
Modified:
erp5/trunk/products/ERP5Type/tests/ERP5TypeTestCase.py
erp5/trunk/products/ERP5Type/tests/custom_zodb.py
erp5/trunk/products/ERP5Type/tests/runUnitTest.py
Modified: erp5/trunk/products/ERP5Type/tests/ERP5TypeTestCase.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/ERP5TypeTestCase.py?rev=10077&r1=10076&r2=10077&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/ERP5TypeTestCase.py (original)
+++ erp5/trunk/products/ERP5Type/tests/ERP5TypeTestCase.py Mon Sep 18 10:52:54 2006
@@ -146,6 +146,29 @@
# 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 @@
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 @@
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 @@
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 @@
'''
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 @@
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 @@
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():
Modified: erp5/trunk/products/ERP5Type/tests/custom_zodb.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/custom_zodb.py?rev=10077&r1=10076&r2=10077&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/custom_zodb.py (original)
+++ erp5/trunk/products/ERP5Type/tests/custom_zodb.py Mon Sep 18 10:52:54 2006
@@ -1,4 +1,11 @@
import ZODB
+import os
from ZODB.DemoStorage import DemoStorage
+from ZODB.FileStorage import FileStorage
-Storage = DemoStorage(quota=(1<<20))
+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))
+
Modified: erp5/trunk/products/ERP5Type/tests/runUnitTest.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/runUnitTest.py?rev=10077&r1=10076&r2=10077&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/runUnitTest.py (original)
+++ erp5/trunk/products/ERP5Type/tests/runUnitTest.py Mon Sep 18 10:52:54 2006
@@ -10,6 +10,15 @@
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 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 @@
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":
More information about the Erp5-report
mailing list