Commit 79a40fd4 authored by Julien Muchembled's avatar Julien Muchembled

Some cleanup in ERP5TypeLiveTestCase

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@42904 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ad103832
...@@ -68,9 +68,9 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin): ...@@ -68,9 +68,9 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin):
sometimes but should remain an exception because they hinder sometimes but should remain an exception because they hinder
productivity by adding an extra time to build the productivity by adding an extra time to build the
environment (which is already built in live instances). environment (which is already built in live instances).
All other test classes should derive from ERP5TypeLiveTestCase. All other test classes should derive from ERP5TypeLiveTestCase.
TODO: TODO:
- An eplicit list of exceptions to live tests remains to be - An eplicit list of exceptions to live tests remains to be
defined. defined.
...@@ -79,17 +79,13 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin): ...@@ -79,17 +79,13 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin):
def getPortalName(self): def getPortalName(self):
""" Return the default ERP5 site id. """ Return the default ERP5 site id.
""" """
return self.getPortalObject().getId() return self.portal.getId()
def getPortal(self): def getPortal(self):
"""Returns the portal object, i.e. the "fixture root". """Returns the portal object, i.e. the "fixture root".
""" """
# Assumes that portal exists (which has sense) and that there is only one from Products.ERP5Site import getSite
# ERP5 site in Zope (which is always the case) return getSite(get_request())
if self.app.meta_type == 'ERP5 Site':
return self.app
return [q for q in self.app.objectValues() if q.meta_type == 'ERP5 Site'
][0]
getPortalObject = getPortal getPortalObject = getPortal
...@@ -103,7 +99,12 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin): ...@@ -103,7 +99,12 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin):
def _close(self): def _close(self):
'''Closes the ZODB connection.''' '''Closes the ZODB connection.'''
revert = transaction.get().__hash__() != self.initial_transaction_hash
transaction.abort() transaction.abort()
if revert:
if self.activity_tool_subscribed:
self.portal.portal_activities.subscribe()
transaction.commit()
def _setup(self): def _setup(self):
'''Change some site properties in order to be ready for live test '''Change some site properties in order to be ready for live test
...@@ -132,21 +133,7 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin): ...@@ -132,21 +133,7 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin):
def _app(self): def _app(self):
'''Returns the app object for a test.''' '''Returns the app object for a test.'''
request = get_request() return self.getPortal().aq_parent
return request.PARENTS[-1]
def afterSetUp(self):
'''Called after setUp() has completed. This is
far and away the most useful hook.
'''
pass
def beforeSetUp(self):
'''Called before the ZODB connection is opened,
at the start of setUp(). By default begins
a new transaction.
'''
pass
def beforeClear(self): def beforeClear(self):
'''Called before _clear(). Subclasses should '''Called before _clear(). Subclasses should
...@@ -161,15 +148,6 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin): ...@@ -161,15 +148,6 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin):
''' '''
PortalTestCase.tearDown(self) PortalTestCase.tearDown(self)
def beforeClose(self):
"""
put back site properties that were disabled for unit test
"""
if transaction.get().__hash__() != self.initial_transaction_hash:
if self.activity_tool_subscribed:
self.portal.portal_activities.subscribe()
transaction.commit()
PortalTestCase.beforeClose(self)
def runLiveTest(test_list, verbosity=1, stream=None, **kw): def runLiveTest(test_list, verbosity=1, stream=None, **kw):
from Products.ERP5Type.tests.runUnitTest import DebugTestResult from Products.ERP5Type.tests.runUnitTest import DebugTestResult
...@@ -214,7 +192,5 @@ def runLiveTest(test_list, verbosity=1, stream=None, **kw): ...@@ -214,7 +192,5 @@ def runLiveTest(test_list, verbosity=1, stream=None, **kw):
if stream is None: if stream is None:
output = StringIO() output = StringIO()
output.write("**Running Live Test:\n") output.write("**Running Live Test:\n")
def _print(msg): ZopeTestCase._print = output.write
output.write(msg)
ZopeTestCase._print = _print
result = TestRunner(stream=output, verbosity=verbosity).run(suite) result = TestRunner(stream=output, verbosity=verbosity).run(suite)
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