diff --git a/product/ERP5Type/tests/testERP5Type.py b/product/ERP5Type/tests/testERP5Type.py index dabd93ee94a571bfccb2e15b34614a167946b86a..595ff8981ddc1c8e58c51070d7cbffebfdb1fed0 100644 --- a/product/ERP5Type/tests/testERP5Type.py +++ b/product/ERP5Type/tests/testERP5Type.py @@ -1,10 +1,4 @@ -# we need a class tool for this test. -def allowClassTool(): - return 1 -import Products.ERP5Type -Products.ERP5Type.allowClassTool = allowClassTool - import os, sys if __name__ == '__main__': execfile(os.path.join(sys.path[0], 'framework.py')) @@ -20,6 +14,7 @@ from zLOG import LOG, INFO from Products.CMFCore.tests.base.testcase import LogInterceptor from Products.ERP5Type.Cache import CachingMethod, clearCache from Products.ERP5Type.Base import _aq_reset +from Products.ERP5Type.tests.utils import installRealClassTool class TestERP5Type(ERP5TypeTestCase, LogInterceptor): @@ -406,6 +401,7 @@ class TestERP5Type(ERP5TypeTestCase, LogInterceptor): This is a test to make sure this will not happens any more """ if not run: return + installRealClassTool(self.getPortal()) # We will first define a new propertysheet class_tool = self.getClassTool() diff --git a/product/ERP5Type/tests/utils.py b/product/ERP5Type/tests/utils.py index 66429aefe392c767dd1061f3a711559de2f3e23c..8c259ffa3eaa25f9f92760ea5c7ad0ccd89a90ff 100644 --- a/product/ERP5Type/tests/utils.py +++ b/product/ERP5Type/tests/utils.py @@ -29,6 +29,7 @@ """Utility functions and classes for unit testing """ +import Products.ERP5Type from Products.MailHost.MailHost import MailHost class DummyMailHost(MailHost): @@ -68,3 +69,24 @@ def removeZODBPythonScript(container, script_id): Removes a Python script `script_id` in the given `container`. """ container.manage_delObjects([script_id]) + +def installRealClassTool(portal): + """Replaces portal_classes by a real class tool object. + """ + Products.ERP5Type.allowClassTool = lambda: 1 + _recreateClassTool(portal) + +def installDummyClassTool(portal): + """Replaces portal_classes by a dummy class tool object. + """ + Products.ERP5Type.allowClassTool = lambda: 0 + _recreateClassTool(portal) + +def _recreateClassTool(portal): + """Recreate the class tool for this portal. + """ + from Products.ERP5Type.Tool import ClassTool + reload(ClassTool) + portal.manage_delObjects(['portal_classes']) + portal._setObject('portal_classes', ClassTool.ClassTool()) +