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
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 ProcessingNodeTestCase as\
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, stream=None, **kw):
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):
......
......@@ -274,7 +274,7 @@ def profile_if_environ(environment_var_name):
# 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(ProcessingNodeTestCase, PortalTestCase):
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(ProcessingNodeTestCase, PortalTestCase):
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(ProcessingNodeTestCase, PortalTestCase):
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:
......
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