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

Support using different sql connection strings on the command line



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@8943 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4855ab62
...@@ -401,36 +401,64 @@ def setupERP5Site( business_template_list=(), ...@@ -401,36 +401,64 @@ def setupERP5Site( business_template_list=(),
# Add ERP5 Site # Add ERP5 Site
reindex = 1 reindex = 1
if hot_reindexing: if hot_reindexing:
setattr(app,'isIndexable',0) setattr(app, 'isIndexable', 0)
reindex = 0 reindex = 0
if not quiet: if not quiet:
ZopeTestCase._print('Adding %s ERP5 Site ... ' % portal_name) ZopeTestCase._print('Adding %s ERP5 Site ... ' % portal_name)
factory = app.manage_addProduct['ERP5'] # Not needed by ERP5Type
factory.manage_addERP5Site(portal_name,light_install=light_install, sql_connections_dict = {}
reindex=reindex,create_activities=create_activities) erp5_sql_connection_string = os.environ.get(
'erp5_sql_connection_string')
if erp5_sql_connection_string:
sql_connections_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:
sql_connections_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:
sql_connections_dict['erp5_sql_deferred_connection_string'] = \
erp5_sql_deferred_connection_string
factory = app.manage_addProduct['ERP5']
factory.manage_addERP5Site(portal_name,
light_install=light_install,
reindex=reindex,
create_activities=create_activities,
**sql_connections_dict )
if not quiet: if not quiet:
ZopeTestCase._print('done (%.3fs)\n' % (time.time() - _start)) ZopeTestCase._print('done (%.3fs)\n' % (time.time() - _start))
# Release locks # Release locks
get_transaction().commit() get_transaction().commit()
portal=app[portal_name] portal = app[portal_name]
# Remove all local PropertySheets, Documents # Remove all local PropertySheets, Documents
for id in getLocalPropertySheetList(): for id_ in getLocalPropertySheetList():
removeLocalPropertySheet(id) removeLocalPropertySheet(id_)
for id in getLocalDocumentList(): for id_ in getLocalDocumentList():
removeLocalDocument(id) removeLocalDocument(id_)
for id in getLocalConstraintList(): for id_ in getLocalConstraintList():
removeLocalConstraint(id) removeLocalConstraint(id_)
# Disable reindexing before adding templates # Disable reindexing before adding templates
# VERY IMPORTANT: Add some business templates # VERY IMPORTANT: Add some business templates
for url, id in business_template_list: for url, id_ in business_template_list:
start = time.time() start = time.time()
ZopeTestCase._print('Adding %s business template ... ' % id) if not quiet:
portal.portal_templates.download(url, id=id) ZopeTestCase._print('Adding %s business template ... ' % id_)
portal.portal_templates[id].install(light_install=light_install) portal.portal_templates.download(url, id=id_)
portal.portal_templates[id_].install(light_install=light_install)
# Release locks # Release locks
get_transaction().commit() get_transaction().commit()
if not quiet:
ZopeTestCase._print('done (%.3fs)\n' % (time.time() - start)) ZopeTestCase._print('done (%.3fs)\n' % (time.time() - start))
# Enbable reindexing
# Enable reindexing
# Do hot reindexing # Does not work # Do hot reindexing # Does not work
if hot_reindexing: if hot_reindexing:
setattr(app,'isIndexable', 1) setattr(app,'isIndexable', 1)
...@@ -451,28 +479,27 @@ def setupERP5Site( business_template_list=(), ...@@ -451,28 +479,27 @@ def setupERP5Site( business_template_list=(),
[('/'.join(m.object_path), m.method_id, [('/'.join(m.object_path), m.method_id,
m.processing_node, m.priority) m.processing_node, m.priority)
for m in portal_activities.getMessageList()],) for m in portal_activities.getMessageList()],)
# Reset aq dynamic, so all unit tests will start again # Reset aq dynamic, so all unit tests will start again
from Products.ERP5Type.Base import _aq_reset from Products.ERP5Type.Base import _aq_reset
_aq_reset() _aq_reset()
# Log out # Log out
if not quiet: if not quiet:
ZopeTestCase._print('Logout ... \n') ZopeTestCase._print('Logout ... \n')
noSecurityManager() noSecurityManager()
if not quiet: if not quiet:
ZopeTestCase._print('done (%.3fs)\n' % (time.time()-_start,)) ZopeTestCase._print('done (%.3fs)\n' % (time.time()-_start,))
if not quiet:
ZopeTestCase._print('Ran Unit test of %s\n' % title) ZopeTestCase._print('Ran Unit test of %s\n' % title)
finally: finally:
get_transaction().commit() get_transaction().commit()
ZopeTestCase.close(app) ZopeTestCase.close(app)
pass
except: except:
f = StringIO() f = StringIO()
traceback.print_exc(file=f) traceback.print_exc(file=f)
ZopeTestCase._print(f.getvalue()) ZopeTestCase._print(f.getvalue())
f.close() f.close()
def optimize(): def optimize():
'''Significantly reduces portal creation time.''' '''Significantly reduces portal creation time.'''
def __init__(self, text): def __init__(self, text):
......
#!/usr/bin/python #!/usr/bin/python
#
# Runs the tests passed on the command line
#
import os import os
import sys import sys
import getopt import getopt
...@@ -11,14 +8,23 @@ __doc__ = """%(program)s: unit test runner for the ERP5 Project ...@@ -11,14 +8,23 @@ __doc__ = """%(program)s: unit test runner for the ERP5 Project
usage: %(program)s [options] [UnitTest1[:TestClass1[:TestClass2]] [UnitTest2]] usage: %(program)s [options] [UnitTest1[:TestClass1[:TestClass2]] [UnitTest2]]
Options: Options:
-v/--verbose -- produce verbose output -v, --verbose produce verbose output
-h, --help this help screen
--erp5_sql_connection_string=STRING
ZSQL Connection string for erp5_sql_connection, by
default, it will use "test test"
--cmf_activity_sql_connection_string=STRING
ZSQL Connection string for
cmf_activity_sql_connection (if unset, defaults to
erp5_sql_connection_string)
--erp5_sql_deferred_connection_string=STRING
ZSQL Connection string for
erp5_sql_deferred_connection (if unset, defaults
to erp5_sql_connection_string)
""" """
def getUnitTestFile() :
return os.path.abspath(__file__)
def initializeInstanceHome(tests_framework_home, def initializeInstanceHome(tests_framework_home,
real_instance_home, real_instance_home,
instance_home): instance_home):
...@@ -159,7 +165,8 @@ def usage(stream, msg=None): ...@@ -159,7 +165,8 @@ def usage(stream, msg=None):
def main(): def main():
try: try:
opts, args = getopt.getopt(sys.argv[1:], opts, args = getopt.getopt(sys.argv[1:],
"hv", ["help", "verbose", ] ) "hv", ["help", "verbose", "erp5_sql_connection_string=",
"cmf_activity_sql_connection_string=", "erp5_deferred_sql_connection_string="] )
except getopt.GetoptError, msg: except getopt.GetoptError, msg:
usage(sys.stderr, msg) usage(sys.stderr, msg)
sys.exit(2) sys.exit(2)
...@@ -167,9 +174,16 @@ def main(): ...@@ -167,9 +174,16 @@ def main():
for opt, arg in opts: for opt, arg in opts:
if opt in ("-v", "--verbose"): if opt in ("-v", "--verbose"):
os.environ['VERBOSE'] = "1" os.environ['VERBOSE'] = "1"
if opt in ("-h", "--help"): elif opt in ("-h", "--help"):
usage(sys.stdout) usage(sys.stdout)
sys.exit() sys.exit()
elif opt == "--erp5_sql_connection_string":
os.environ["erp5_sql_connection_string"] = arg
print "set to ", arg
elif opt == "--cmf_activity_sql_connection_string":
os.environ["cmf_activity_sql_connection_string"] = arg
elif opt == "--erp5_sql_deferred_connection_string":
os.environ["erp5_sql_deferred_connection_string"] = arg
test_list = args test_list = args
if not test_list: if not test_list:
......
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