[Erp5-report] r42529 seb - /erp5/trunk/products/ERP5Type/tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Jan 20 19:13:48 CET 2011
Author: seb
Date: Thu Jan 20 19:13:48 2011
New Revision: 42529
URL: http://svn.erp5.org?rev=42529&view=rev
Log:
make ERP5TypeTestCase a proxy to :
- CommandLineTestCase if test started from runUnitTest
- ERP5TypeLiveTestCase if test started from portal_classes.runLiveTest
This allows to run any test from both command line and from
portal_classes, so it allows to run on any instance any
existing test.
Modified:
erp5/trunk/products/ERP5Type/tests/ERP5TypeLiveTestCase.py
erp5/trunk/products/ERP5Type/tests/ERP5TypeTestCase.py
Modified: erp5/trunk/products/ERP5Type/tests/ERP5TypeLiveTestCase.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/ERP5TypeLiveTestCase.py?rev=42529&r1=42528&r2=42529&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/ERP5TypeLiveTestCase.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/tests/ERP5TypeLiveTestCase.py [utf8] Thu Jan 20 19:13:48 2011
@@ -36,6 +36,7 @@ from Products.CMFCore.utils import getTo
from Products.ERP5Type.tests.ProcessingNodeTestCase import ProcessingNodeTestCase
from Products.ERP5Type.Globals import get_request
from ERP5TypeTestCase import ERP5TypeTestCaseMixin
+from glob import glob
import transaction
from zLOG import LOG, DEBUG, INFO
@@ -59,7 +60,7 @@ from Products.ERP5Type.tests import Proc
ProcessingNodeTestCaseModule
ProcessingNodeTestCaseModule.patchActivityTool = lambda: None
-class ERP5TypeLiveTestCase(ERP5TypeTestMixin):
+class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin):
"""ERP5TypeLiveTestCase is the default class for *all* tests
in ERP5. It is designed with the idea in mind that tests should
be run through the web. Command line based tests may be helpful
@@ -171,12 +172,20 @@ def runLiveTest(test_list, verbosity=1,
path = kw.get('path', None)
if path is not None and path not in sys.path:
sys.path.append(path)
+ product_test_list = []
+ import Products
+ for product_path in Products.__path__:
+ product_test_list.extend(glob(os.path.join(product_path, '*', 'tests')))
+
+ sys.path.extend(product_test_list)
# Reload the test class before runing tests
for test_name in test_list:
(test_file, test_path_name, test_description) = imp.find_module(test_name)
imp.load_module(test_name, test_file, test_path_name, test_description)
TestRunner = backportUnittest.TextTestRunner
+ from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
+ getTransactionalVariable()['unit_test_type'] = 'live_test'
if kw.get('debug', False):
class DebugTextTestRunner(TestRunner):
def _makeResult(self):
Modified: erp5/trunk/products/ERP5Type/tests/ERP5TypeTestCase.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/ERP5TypeTestCase.py?rev=42529&r1=42528&r2=42529&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/ERP5TypeTestCase.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/tests/ERP5TypeTestCase.py [utf8] Thu Jan 20 19:13:48 2011
@@ -274,7 +274,7 @@ def profile_if_environ(environment_var_n
# No profiling, return identity decorator
return lambda self, method: method
-class ERP5TypeTestMixin(ProcessingNodeTestCase, PortalTestCase):
+class ERP5TypeTestCaseMixin(object):
"""Mixin class for ERP5 based tests.
"""
@@ -308,8 +308,9 @@ class ERP5TypeTestMixin(ProcessingNodeTe
PortalTestCase.logout(self)
# clean up certain cache related REQUEST keys that might be associated
# with the logged in user
- for key in ('_ec_cache', '_oai_cache'):
- self.REQUEST.other.pop(key, None)
+ if getattr(self, 'REQUEST', None) is not None:
+ for key in ('_ec_cache', '_oai_cache'):
+ self.REQUEST.other.pop(key, None)
def _setupUser(self):
'''Creates the default user.'''
@@ -533,7 +534,8 @@ class ERP5TypeTestMixin(ProcessingNodeTe
transaction.commit()
self.tic()
- getPortalObject = getPortal
+ def getPortalObject(self):
+ return self.getPortal()
# class-defined decorators for profiling.
# Depending on the environment variable, they return
@@ -622,11 +624,8 @@ class ERP5TypeTestMixin(ProcessingNodeTe
setSecurityManager(sm)
return ResponseWrapper(response, outstream, path)
-class ERP5TypeTestCase(ERP5TypeTestMixin):
- """TestCase for ERP5 based tests.
- This TestCase setups an ERP5Site and installs business templates.
- """
+class CommandLineTestCase(object):
def dummy_test(self):
ZopeTestCase._print('All tests are skipped when --save option is passed '
@@ -1094,10 +1093,31 @@ class ERP5TypeTestCase(ERP5TypeTestMixin
obj.manage_afterClone(obj)
return obj
+class ERP5TypeTestCase(ERP5TypeTestCaseMixin):
+ """TestCase for ERP5 based tests.
+
+ This TestCase setups an ERP5Site and installs business templates.
+ """
+
+ def __init__(self, *args, **kw):
+ type_test_case_klass = CommandLineTestCase
+ from Products.ERP5Type.TransactionalVariable import \
+ getTransactionalVariable
+ unit_test_type = getTransactionalVariable().get('unit_test_type', None)
+ if unit_test_type == 'live_test':
+ from Products.ERP5Type.tests.ERP5TypeLiveTestCase import \
+ ERP5TypeLiveTestCase
+ type_test_case_klass = ERP5TypeLiveTestCase
+ klass = self.__class__
+ class TempTestCase(klass, type_test_case_klass,
+ ProcessingNodeTestCase, PortalTestCase):
+ pass
+ self.__class__ = TempTestCase
+ return PortalTestCase.__init__(self, *args, **kw)
from Products.ERP5 import ERP5Site
ERP5Site.getBootstrapBusinessTemplateUrl = lambda bt_title: \
- ERP5TypeTestCase._getBTPathAndIdList((bt_title,))[0][0]
+ CommandLineTestCase._getBTPathAndIdList((bt_title,))[0][0]
class ResponseWrapper:
More information about the Erp5-report
mailing list