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

replace boolean IS_PORTAL_EXISTING by a mapping 'list of business templates' ->

'is this portal set up ?'.
If the portal is not set up yet, then install all missing business templates.
With this you can run multiple tests on the same portal (using --portal_id=),
before it was only installing business templates in the first setUp.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13317 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8811873f
...@@ -24,8 +24,6 @@ def get_request(): ...@@ -24,8 +24,6 @@ def get_request():
Products.ERP5Type.Utils.get_request = get_request Products.ERP5Type.Utils.get_request = get_request
Globals.get_request = get_request Globals.get_request = get_request
IS_PORTAL_EXISTING = 1
import itools.zope import itools.zope
def get_context(): def get_context():
...@@ -165,6 +163,11 @@ portal_name = 'erp5_portal' ...@@ -165,6 +163,11 @@ portal_name = 'erp5_portal'
# prevent replaying the same failing setup step for each test. # prevent replaying the same failing setup step for each test.
failed_portal_installation = {} failed_portal_installation = {}
# have we installed business templates ?
# this is a mapping 'list of business template -> boolean
setup_done = {}
def _getConnectionStringDict(): def _getConnectionStringDict():
"""Returns the connection strings used for this test. """Returns the connection strings used for this test.
""" """
...@@ -188,7 +191,12 @@ def _getConnectionStringDict(): ...@@ -188,7 +191,12 @@ def _getConnectionStringDict():
erp5_sql_deferred_connection_string erp5_sql_deferred_connection_string
return connection_string_dict return connection_string_dict
class ERP5TypeTestCase(PortalTestCase): class ERP5TypeTestCase(PortalTestCase):
"""TestCase for ERP5 based tests.
This TestCase setups an ERP5Site and installs business templates.
"""
def dummy_test(self): def dummy_test(self):
ZopeTestCase._print('All tests are skipped with --save option.') ZopeTestCase._print('All tests are skipped with --save option.')
...@@ -224,7 +232,6 @@ class ERP5TypeTestCase(PortalTestCase): ...@@ -224,7 +232,6 @@ class ERP5TypeTestCase(PortalTestCase):
def getPortal(self): def getPortal(self):
"""Returns the portal object, i.e. the "fixture root". """Returns the portal object, i.e. the "fixture root".
Override if you don't like the default.
""" """
return self.app[self.getPortalName()] return self.app[self.getPortalName()]
...@@ -321,7 +328,8 @@ class ERP5TypeTestCase(PortalTestCase): ...@@ -321,7 +328,8 @@ 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()
erp5_catalog_storage = os.environ.get('erp5_catalog_storage', 'erp5_mysql_innodb_catalog') erp5_catalog_storage = os.environ.get('erp5_catalog_storage',
'erp5_mysql_innodb_catalog')
setupERP5Site(business_template_list=new_template_list, setupERP5Site(business_template_list=new_template_list,
light_install=light_install, light_install=light_install,
portal_name=self.getPortalName(), portal_name=self.getPortalName(),
...@@ -496,7 +504,6 @@ def setupERP5Site( business_template_list=(), ...@@ -496,7 +504,6 @@ def setupERP5Site( business_template_list=(),
business_template_list must be specified correctly business_template_list must be specified correctly
(e.g. '("erp5_base", )'). (e.g. '("erp5_base", )').
''' '''
global IS_PORTAL_EXISTING
from Products.ERP5Type.Base import _aq_reset from Products.ERP5Type.Base import _aq_reset
if portal_name in failed_portal_installation: if portal_name in failed_portal_installation:
raise RuntimeError, 'Installation of %s already failed, giving up'\ raise RuntimeError, 'Installation of %s already failed, giving up'\
...@@ -509,8 +516,10 @@ def setupERP5Site( business_template_list=(), ...@@ -509,8 +516,10 @@ def setupERP5Site( business_template_list=(),
global current_app global current_app
current_app = app current_app = app
if not hasattr(aq_base(app), portal_name): global setup_done
IS_PORTAL_EXISTING = 0 if not (hasattr(aq_base(app), portal_name) and
setup_done.get(tuple(business_template_list))):
setup_done[tuple(business_template_list)] = 1
try: try:
_start = time.time() _start = time.time()
# Add user and log in # Add user and log in
...@@ -525,6 +534,9 @@ def setupERP5Site( business_template_list=(), ...@@ -525,6 +534,9 @@ def setupERP5Site( business_template_list=(),
if hot_reindexing: if hot_reindexing:
setattr(app, 'isIndexable', 0) setattr(app, 'isIndexable', 0)
reindex = 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('Adding %s ERP5 Site ... ' % portal_name)
...@@ -532,6 +544,7 @@ def setupERP5Site( business_template_list=(), ...@@ -532,6 +544,7 @@ def setupERP5Site( business_template_list=(),
email_from_address = os.environ.get('email_from_address') email_from_address = os.environ.get('email_from_address')
if email_from_address is not None: if email_from_address is not None:
extra_constructor_kw['email_from_address'] = email_from_address extra_constructor_kw['email_from_address'] = email_from_address
factory = app.manage_addProduct['ERP5'] factory = app.manage_addProduct['ERP5']
factory.manage_addERP5Site(portal_name, factory.manage_addERP5Site(portal_name,
erp5_catalog_storage=erp5_catalog_storage, erp5_catalog_storage=erp5_catalog_storage,
...@@ -539,12 +552,12 @@ def setupERP5Site( business_template_list=(), ...@@ -539,12 +552,12 @@ def setupERP5Site( business_template_list=(),
reindex=reindex, reindex=reindex,
create_activities=create_activities, create_activities=create_activities,
**extra_constructor_kw ) **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()
portal = app[portal_name]
if os.environ.get('erp5_load_data_fs'): if os.environ.get('erp5_load_data_fs'):
# Import local PropertySheets, Documents # Import local PropertySheets, Documents
...@@ -637,6 +650,9 @@ def setupERP5Site( business_template_list=(), ...@@ -637,6 +650,9 @@ def setupERP5Site( business_template_list=(),
else: else:
get_transaction().commit() get_transaction().commit()
ZopeTestCase.close(app) ZopeTestCase.close(app)
else:
# Display which test is run when loading for the 1st time
ZopeTestCase._print('Ran Unit test of %s\n' % title)
if os.environ.get('erp5_load_data_fs'): if os.environ.get('erp5_load_data_fs'):
# Import local PropertySheets, Documents # Import local PropertySheets, Documents
...@@ -649,11 +665,6 @@ def setupERP5Site( business_template_list=(), ...@@ -649,11 +665,6 @@ def setupERP5Site( business_template_list=(),
importLocalConstraint(id_) importLocalConstraint(id_)
_aq_reset() _aq_reset()
if IS_PORTAL_EXISTING == 1:
# Display which test is run when loading for the 1st time
IS_PORTAL_EXISTING = 0
ZopeTestCase._print('Ran Unit test of %s\n' % title)
except: except:
f = StringIO() f = StringIO()
traceback.print_exc(file=f) traceback.print_exc(file=f)
......
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