From 1cb0c529cb4d3e2d2fe0432eb329473ef77672bd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Tue, 19 Sep 2006 11:14:32 +0000
Subject: [PATCH] create installRealClassTool and installDummyClassTool utility
 functions

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10145 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/tests/testERP5Type.py |  8 ++------
 product/ERP5Type/tests/utils.py        | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/product/ERP5Type/tests/testERP5Type.py b/product/ERP5Type/tests/testERP5Type.py
index dabd93ee94..595ff8981d 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 66429aefe3..8c259ffa3e 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())
+  
-- 
2.30.9