Commit dba0b9ac authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

support setUpOnce() method that is only called once par setting up ERP5 site....

support setUpOnce() method that is only called once par setting up ERP5 site. its result will be saved with --save.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@19499 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 785e7292
...@@ -351,14 +351,12 @@ class ERP5TypeTestCase(PortalTestCase): ...@@ -351,14 +351,12 @@ class ERP5TypeTestCase(PortalTestCase):
light_install = self.enableLightInstall() light_install = self.enableLightInstall()
create_activities = self.enableActivityTool() create_activities = self.enableActivityTool()
hot_reindexing = self.enableHotReindexing() hot_reindexing = self.enableHotReindexing()
setupERP5Site(business_template_list=new_template_list, self.setUpERP5Site(business_template_list=new_template_list,
light_install=light_install, light_install=light_install,
portal_name=self.getPortalName(), create_activities=create_activities,
title=self.getTitle(), quiet=install_bt5_quiet,
create_activities=create_activities, hot_reindexing=hot_reindexing,
quiet=install_bt5_quiet, erp5_catalog_storage=erp5_catalog_storage)
hot_reindexing=hot_reindexing,
erp5_catalog_storage=erp5_catalog_storage)
PortalTestCase.setUp(self) PortalTestCase.setUp(self)
global current_app global current_app
current_app = self.app current_app = self.app
...@@ -557,224 +555,239 @@ class ERP5TypeTestCase(PortalTestCase): ...@@ -557,224 +555,239 @@ class ERP5TypeTestCase(PortalTestCase):
self.assertEqual(object.getSimulationState(), reference_workflow_state) self.assertEqual(object.getSimulationState(), reference_workflow_state)
return workflow_error_message return workflow_error_message
def setupERP5Site( business_template_list=(), def setUpERP5Site(self,
app=None, business_template_list=(),
portal_name=portal_name, app=None,
title='', quiet=0,
quiet=0, light_install=1,
light_install=1, create_activities=1,
create_activities=1, hot_reindexing=1,
hot_reindexing=1, erp5_catalog_storage='erp5_mysql_innodb_catalog'):
erp5_catalog_storage='erp5_mysql_innodb_catalog'): '''
''' Creates an ERP5 site.
Creates an ERP5 site. business_template_list must be specified correctly
business_template_list must be specified correctly (e.g. '("erp5_base", )').
(e.g. '("erp5_base", )'). '''
''' portal_name = self.getPortalName()
from Products.ERP5Type.Base import _aq_reset title = self.getTitle()
if portal_name in failed_portal_installation: from Products.ERP5Type.Base import _aq_reset
raise RuntimeError, 'Installation of %s already failed, giving up'\ if portal_name in failed_portal_installation:
% portal_name raise RuntimeError, 'Installation of %s already failed, giving up'\
try: % portal_name
if app is None: try:
app = ZopeTestCase.app() if app is None:
# this app will be closed after setUp, but keep an reference anyway, to app = ZopeTestCase.app()
# make it's REQUEST available during setup # this app will be closed after setUp, but keep an reference anyway, to
global current_app # make it's REQUEST available during setup
current_app = app global current_app
current_app = app
global setup_done
if not (hasattr(aq_base(app), portal_name) and global setup_done
setup_done.get(tuple(business_template_list))): if not (hasattr(aq_base(app), portal_name) and
setup_done[tuple(business_template_list)] = 1 setup_done.get(tuple(business_template_list))):
try: setup_done[tuple(business_template_list)] = 1
_start = time.time() try:
# Add user and log in _start = time.time()
if not quiet: # Add user and log in
ZopeTestCase._print('\nAdding ERP5TypeTestCase user ... \n')
uf = app.acl_users
uf._doAddUser('ERP5TypeTestCase', '', ['Manager', 'Member', 'Assignee',
'Assignor', 'Author', 'Auditor', 'Associate'], [])
user = uf.getUserById('ERP5TypeTestCase').__of__(uf)
newSecurityManager(None, user)
# Add ERP5 Site
reindex = 1
if hot_reindexing:
setattr(app, 'isIndexable', 0)
reindex = 0
portal = getattr(app, portal_name, None)
if portal is None:
if not quiet: if not quiet:
ZopeTestCase._print('Adding %s ERP5 Site ... ' % portal_name) ZopeTestCase._print('\nAdding ERP5TypeTestCase user ... \n')
uf = app.acl_users
extra_constructor_kw = _getConnectionStringDict() uf._doAddUser('ERP5TypeTestCase', '', ['Manager', 'Member', 'Assignee',
email_from_address = os.environ.get('email_from_address') 'Assignor', 'Author', 'Auditor', 'Associate'], [])
if email_from_address is not None: user = uf.getUserById('ERP5TypeTestCase').__of__(uf)
extra_constructor_kw['email_from_address'] = email_from_address newSecurityManager(None, user)
# Add ERP5 Site
factory = app.manage_addProduct['ERP5'] reindex = 1
factory.manage_addERP5Site(portal_name, if hot_reindexing:
erp5_catalog_storage=erp5_catalog_storage, setattr(app, 'isIndexable', 0)
light_install=light_install, reindex = 0
reindex=reindex,
create_activities=create_activities, portal = getattr(app, portal_name, None)
**extra_constructor_kw ) if portal is None:
portal = app[portal_name] if not quiet:
ZopeTestCase._print('Adding %s ERP5 Site ... ' % portal_name)
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
factory = app.manage_addProduct['ERP5']
factory.manage_addERP5Site(portal_name,
erp5_catalog_storage=erp5_catalog_storage,
light_install=light_install,
reindex=reindex,
create_activities=create_activities,
**extra_constructor_kw )
portal = app[portal_name]
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()
if os.environ.get('erp5_load_data_fs'): if os.environ.get('erp5_load_data_fs'):
# Import local PropertySheets, Documents # Import local PropertySheets, Documents
for id_ in getLocalPropertySheetList(): for id_ in getLocalPropertySheetList():
importLocalPropertySheet(id_) importLocalPropertySheet(id_)
for id_ in getLocalDocumentList(): for id_ in getLocalDocumentList():
importLocalDocument(id_) importLocalDocument(id_)
for id_ in getLocalConstraintList(): for id_ in getLocalConstraintList():
importLocalConstraint(id_) importLocalConstraint(id_)
else:
# Remove all local PropertySheets, Documents
for id_ in getLocalPropertySheetList():
removeLocalPropertySheet(id_)
for id_ in getLocalDocumentList():
removeLocalDocument(id_)
for id_ in getLocalConstraintList():
removeLocalConstraint(id_)
update_business_templates = os.environ.get('update_business_templates') is not None
BusinessTemplate_getModifiedObject = aq_base(getattr(portal, 'BusinessTemplate_getModifiedObject', None))
# Disable reindexing before adding templates
# VERY IMPORTANT: Add some business templates
for url, bt_title in business_template_list:
start = time.time()
get_install_kw = False
if bt_title in [x.getTitle() for x in portal.portal_templates.getInstalledBusinessTemplateList()]:
if update_business_templates:
if not quiet:
ZopeTestCase._print('Updating %s business template ... ' % bt_title)
if BusinessTemplate_getModifiedObject is not None:
get_install_kw = True
else:
continue
else: else:
# Remove all local PropertySheets, Documents
for id_ in getLocalPropertySheetList():
removeLocalPropertySheet(id_)
for id_ in getLocalDocumentList():
removeLocalDocument(id_)
for id_ in getLocalConstraintList():
removeLocalConstraint(id_)
update_business_templates = os.environ.get('update_business_templates') is not None
BusinessTemplate_getModifiedObject = aq_base(getattr(portal, 'BusinessTemplate_getModifiedObject', None))
# Disable reindexing before adding templates
# VERY IMPORTANT: Add some business templates
for url, bt_title in business_template_list:
start = time.time()
get_install_kw = False
if bt_title in [x.getTitle() for x in portal.portal_templates.getInstalledBusinessTemplateList()]:
if update_business_templates:
if not quiet:
ZopeTestCase._print('Updating %s business template ... ' % bt_title)
if BusinessTemplate_getModifiedObject is not None:
get_install_kw = True
else:
continue
else:
if not quiet:
ZopeTestCase._print('Adding %s business template ... ' % bt_title)
bt = portal.portal_templates.download(url)
if not quiet: if not quiet:
ZopeTestCase._print('Adding %s business template ... ' % bt_title) ZopeTestCase._print('(imported in %.3fs) ' % (time.time() - start))
bt = portal.portal_templates.download(url) install_kw = None
if not quiet: if get_install_kw:
ZopeTestCase._print('(imported in %.3fs) ' % (time.time() - start)) listbox_object_list = BusinessTemplate_getModifiedObject.__of__(bt)()
install_kw = None for listbox_line in listbox_object_list:
if get_install_kw: install_kw[listbox_line.object_id] = listbox_line.choice_item_list[0][1]
listbox_object_list = BusinessTemplate_getModifiedObject.__of__(bt)() bt.install(light_install=light_install, object_to_update=install_kw)
for listbox_line in listbox_object_list: # Release locks
install_kw[listbox_line.object_id] = listbox_line.choice_item_list[0][1] get_transaction().commit()
bt.install(light_install=light_install, object_to_update=install_kw) if not quiet:
# Release locks ZopeTestCase._print('done (%.3fs)\n' % (time.time() - start))
setup_once = getattr(self, 'setUpOnce', None)
if setup_once is not None and \
not getattr(portal, 'set_up_once_called', 0):
portal.set_up_once_called = 1
if not quiet:
ZopeTestCase._print('Executing setUpOnce ... ')
start = time.time()
# setUpOnce method may use self.app and self.portal
self.app = app
self.portal = portal
setup_once()
if not quiet:
ZopeTestCase._print('done (%.3fs)\n' % (time.time() - start))
# Enable reindexing
# Do hot reindexing # Does not work
if hot_reindexing:
setattr(app,'isIndexable', 1)
portal.portal_catalog.manage_hotReindexAll()
get_transaction().commit() get_transaction().commit()
if not quiet:
ZopeTestCase._print('done (%.3fs)\n' % (time.time() - start))
# Enable reindexing portal_activities = getattr(portal, 'portal_activities', None)
# Do hot reindexing # Does not work if portal_activities is not None:
if hot_reindexing: if not quiet:
setattr(app,'isIndexable', 1) ZopeTestCase._print('Executing pending activities ... ')
portal.portal_catalog.manage_hotReindexAll() start = time.time()
count = 1000
message_count = len(portal_activities.getMessageList())
while message_count > 0:
portal_activities.distribute()
portal_activities.tic()
get_transaction().commit()
new_message_count = len(portal_activities.getMessageList())
if new_message_count != message_count:
if not quiet:
ZopeTestCase._print('%i ' % (message_count, ))
message_count = new_message_count
count -= 1
if count == 0:
raise RuntimeError, \
'tic is looping forever. These messages are pending: %r' % (
[('/'.join(m.object_path), m.method_id,
m.processing_node, m.priority)
for m in portal_activities.getMessageList()],)
if not quiet:
ZopeTestCase._print('done (%.3fs)\n' % (time.time() - start))
get_transaction().commit() # Reset aq dynamic, so all unit tests will start again
_aq_reset()
portal_activities = getattr(portal, 'portal_activities', None) if os.environ.get('erp5_save_data_fs'):
if portal_activities is not None: # Quit the test in order to get a clean site
if not quiet: if not quiet:
ZopeTestCase._print('Executing pending activities ... ') ZopeTestCase._print('done (%.3fs)\n' % (time.time()-_start,))
start = time.time()
count = 1000
message_count = len(portal_activities.getMessageList())
while message_count > 0:
portal_activities.distribute()
portal_activities.tic()
get_transaction().commit() get_transaction().commit()
new_message_count = len(portal_activities.getMessageList()) ZopeTestCase.close(app)
if new_message_count != message_count: if not quiet:
if not quiet: ZopeTestCase._print('Data.fs created\n')
ZopeTestCase._print('%i ' % (message_count, )) get_transaction().commit()
message_count = new_message_count ZopeTestCase.close(app)
count -= 1 instance_home = os.environ['INSTANCE_HOME']
if count == 0: command = 'mysqldump %s > %s/dump.sql' \
raise RuntimeError, \ % (getMySQLArguments(), instance_home)
'tic is looping forever. These messages are pending: %r' % ( if not quiet:
[('/'.join(m.object_path), m.method_id, ZopeTestCase._print('Dumping MySQL database with %s... ' \
m.processing_node, m.priority) % command)
for m in portal_activities.getMessageList()],) os.system(command)
if not quiet: if not quiet:
ZopeTestCase._print('done (%.3fs)\n' % (time.time() - start)) ZopeTestCase._print('done\n')
if not quiet:
# Reset aq dynamic, so all unit tests will start again ZopeTestCase._print('Dumping static files... ')
_aq_reset() for dir in ('Constraint', 'Document', 'PropertySheet'):
os.system('rm -rf %s/%s.bak' % (instance_home, dir))
os.system('cp -ar %s/%s %s/%s.bak' % (instance_home, dir, instance_home, dir))
if not quiet:
ZopeTestCase._print('done\n')
if os.environ.get('erp5_save_data_fs'): # Log out
# Quit the test in order to get a clean site
if not quiet: if not quiet:
ZopeTestCase._print('done (%.3fs)\n' % (time.time()-_start,)) ZopeTestCase._print('Logout ... \n')
get_transaction().commit() noSecurityManager()
ZopeTestCase.close(app)
if not quiet: if not quiet:
ZopeTestCase._print('Data.fs created\n') ZopeTestCase._print('done (%.3fs)\n' % (time.time()-_start,))
ZopeTestCase._print('Ran Unit test of %s\n' % title)
except:
get_transaction().abort()
raise
else:
get_transaction().commit() get_transaction().commit()
ZopeTestCase.close(app) ZopeTestCase.close(app)
instance_home = os.environ['INSTANCE_HOME']
command = 'mysqldump %s > %s/dump.sql' \ if os.environ.get('erp5_load_data_fs'):
% (getMySQLArguments(), instance_home) # Import local PropertySheets, Documents
if not quiet: # when loading an environnement
ZopeTestCase._print('Dumping MySQL database with %s... ' \ for id_ in getLocalPropertySheetList():
% command) importLocalPropertySheet(id_)
os.system(command) for id_ in getLocalDocumentList():
if not quiet: importLocalDocument(id_)
ZopeTestCase._print('done\n') for id_ in getLocalConstraintList():
if not quiet: importLocalConstraint(id_)
ZopeTestCase._print('Dumping static files... ') _aq_reset()
for dir in ('Constraint', 'Document', 'PropertySheet'):
os.system('rm -rf %s/%s.bak' % (instance_home, dir)) except:
os.system('cp -ar %s/%s %s/%s.bak' % (instance_home, dir, instance_home, dir)) f = StringIO()
if not quiet: traceback.print_exc(file=f)
ZopeTestCase._print('done\n') ZopeTestCase._print(f.getvalue())
f.close()
# Log out failed_portal_installation[portal_name] = 1
if not quiet: ZopeTestCase._print('Ran Unit test of %s (installation failed)\n'
ZopeTestCase._print('Logout ... \n') % title) # run_unit_test depends on this string.
noSecurityManager() raise
if not quiet:
ZopeTestCase._print('done (%.3fs)\n' % (time.time()-_start,))
ZopeTestCase._print('Ran Unit test of %s\n' % title)
except:
get_transaction().abort()
raise
else:
get_transaction().commit()
ZopeTestCase.close(app)
if os.environ.get('erp5_load_data_fs'):
# Import local PropertySheets, Documents
# when loading an environnement
for id_ in getLocalPropertySheetList():
importLocalPropertySheet(id_)
for id_ in getLocalDocumentList():
importLocalDocument(id_)
for id_ in getLocalConstraintList():
importLocalConstraint(id_)
_aq_reset()
except:
f = StringIO()
traceback.print_exc(file=f)
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
from unittest import _makeLoader, TestSuite from unittest import _makeLoader, TestSuite
......
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