Commit 22c8fd66 authored by Sebastien Robin's avatar Sebastien Robin

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.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@42529 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ed4e67bc
...@@ -36,6 +36,7 @@ from Products.CMFCore.utils import getToolByName ...@@ -36,6 +36,7 @@ from Products.CMFCore.utils import getToolByName
from Products.ERP5Type.tests.ProcessingNodeTestCase import ProcessingNodeTestCase from Products.ERP5Type.tests.ProcessingNodeTestCase import ProcessingNodeTestCase
from Products.ERP5Type.Globals import get_request from Products.ERP5Type.Globals import get_request
from ERP5TypeTestCase import ERP5TypeTestCaseMixin from ERP5TypeTestCase import ERP5TypeTestCaseMixin
from glob import glob
import transaction import transaction
from zLOG import LOG, DEBUG, INFO from zLOG import LOG, DEBUG, INFO
...@@ -59,7 +60,7 @@ from Products.ERP5Type.tests import ProcessingNodeTestCase as\ ...@@ -59,7 +60,7 @@ from Products.ERP5Type.tests import ProcessingNodeTestCase as\
ProcessingNodeTestCaseModule ProcessingNodeTestCaseModule
ProcessingNodeTestCaseModule.patchActivityTool = lambda: None ProcessingNodeTestCaseModule.patchActivityTool = lambda: None
class ERP5TypeLiveTestCase(ERP5TypeTestMixin): class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin):
"""ERP5TypeLiveTestCase is the default class for *all* tests """ERP5TypeLiveTestCase is the default class for *all* tests
in ERP5. It is designed with the idea in mind that tests should 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 be run through the web. Command line based tests may be helpful
...@@ -171,12 +172,20 @@ def runLiveTest(test_list, verbosity=1, stream=None, **kw): ...@@ -171,12 +172,20 @@ def runLiveTest(test_list, verbosity=1, stream=None, **kw):
path = kw.get('path', None) path = kw.get('path', None)
if path is not None and path not in sys.path: if path is not None and path not in sys.path:
sys.path.append(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 # Reload the test class before runing tests
for test_name in test_list: for test_name in test_list:
(test_file, test_path_name, test_description) = imp.find_module(test_name) (test_file, test_path_name, test_description) = imp.find_module(test_name)
imp.load_module(test_name, test_file, test_path_name, test_description) imp.load_module(test_name, test_file, test_path_name, test_description)
TestRunner = backportUnittest.TextTestRunner TestRunner = backportUnittest.TextTestRunner
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
getTransactionalVariable()['unit_test_type'] = 'live_test'
if kw.get('debug', False): if kw.get('debug', False):
class DebugTextTestRunner(TestRunner): class DebugTextTestRunner(TestRunner):
def _makeResult(self): def _makeResult(self):
......
...@@ -274,7 +274,7 @@ def profile_if_environ(environment_var_name): ...@@ -274,7 +274,7 @@ def profile_if_environ(environment_var_name):
# No profiling, return identity decorator # No profiling, return identity decorator
return lambda self, method: method return lambda self, method: method
class ERP5TypeTestMixin(ProcessingNodeTestCase, PortalTestCase): class ERP5TypeTestCaseMixin(object):
"""Mixin class for ERP5 based tests. """Mixin class for ERP5 based tests.
""" """
...@@ -308,8 +308,9 @@ class ERP5TypeTestMixin(ProcessingNodeTestCase, PortalTestCase): ...@@ -308,8 +308,9 @@ class ERP5TypeTestMixin(ProcessingNodeTestCase, PortalTestCase):
PortalTestCase.logout(self) PortalTestCase.logout(self)
# clean up certain cache related REQUEST keys that might be associated # clean up certain cache related REQUEST keys that might be associated
# with the logged in user # with the logged in user
for key in ('_ec_cache', '_oai_cache'): if getattr(self, 'REQUEST', None) is not None:
self.REQUEST.other.pop(key, None) for key in ('_ec_cache', '_oai_cache'):
self.REQUEST.other.pop(key, None)
def _setupUser(self): def _setupUser(self):
'''Creates the default user.''' '''Creates the default user.'''
...@@ -533,7 +534,8 @@ class ERP5TypeTestMixin(ProcessingNodeTestCase, PortalTestCase): ...@@ -533,7 +534,8 @@ class ERP5TypeTestMixin(ProcessingNodeTestCase, PortalTestCase):
transaction.commit() transaction.commit()
self.tic() self.tic()
getPortalObject = getPortal def getPortalObject(self):
return self.getPortal()
# class-defined decorators for profiling. # class-defined decorators for profiling.
# Depending on the environment variable, they return # Depending on the environment variable, they return
...@@ -622,11 +624,8 @@ class ERP5TypeTestMixin(ProcessingNodeTestCase, PortalTestCase): ...@@ -622,11 +624,8 @@ class ERP5TypeTestMixin(ProcessingNodeTestCase, PortalTestCase):
setSecurityManager(sm) setSecurityManager(sm)
return ResponseWrapper(response, outstream, path) 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): def dummy_test(self):
ZopeTestCase._print('All tests are skipped when --save option is passed ' ZopeTestCase._print('All tests are skipped when --save option is passed '
...@@ -1094,10 +1093,31 @@ class ERP5TypeTestCase(ERP5TypeTestMixin): ...@@ -1094,10 +1093,31 @@ class ERP5TypeTestCase(ERP5TypeTestMixin):
obj.manage_afterClone(obj) obj.manage_afterClone(obj)
return 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 from Products.ERP5 import ERP5Site
ERP5Site.getBootstrapBusinessTemplateUrl = lambda bt_title: \ ERP5Site.getBootstrapBusinessTemplateUrl = lambda bt_title: \
ERP5TypeTestCase._getBTPathAndIdList((bt_title,))[0][0] CommandLineTestCase._getBTPathAndIdList((bt_title,))[0][0]
class ResponseWrapper: class ResponseWrapper:
......
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