Commit 2cea36fd authored by Jérome Perrin's avatar Jérome Perrin

ProcessingNodeTestCase: use _setUpDummyMailHost also in activity nodes

_setUpDummyMailHost is also used to prevent accidentally sending "real"
emails, so we also like to have it enabled for other nodes.
parent 1f8655d4
...@@ -26,7 +26,6 @@ from cPickle import dumps ...@@ -26,7 +26,6 @@ from cPickle import dumps
from glob import glob from glob import glob
from hashlib import md5 from hashlib import md5
from warnings import warn from warnings import warn
from ExtensionClass import pmc_init_of
from DateTime import DateTime from DateTime import DateTime
import Products.ZMySQLDA.DA import Products.ZMySQLDA.DA
from Products.ZMySQLDA.DA import Connection as ZMySQLDA_Connection from Products.ZMySQLDA.DA import Connection as ZMySQLDA_Connection
...@@ -65,7 +64,7 @@ from zLOG import LOG, DEBUG ...@@ -65,7 +64,7 @@ from zLOG import LOG, DEBUG
from Products.ERP5Type.Utils import convertToUpperCase from Products.ERP5Type.Utils import convertToUpperCase
from Products.ERP5Type.tests.backportUnittest import SetupSiteError from Products.ERP5Type.tests.backportUnittest import SetupSiteError
from Products.ERP5Type.tests.utils import addUserToDeveloperRole from Products.ERP5Type.tests.utils import addUserToDeveloperRole
from Products.ERP5Type.tests.utils import DummyMailHostMixin, parseListeningAddress from Products.ERP5Type.tests.utils import parseListeningAddress
# Quiet messages when installing business templates # Quiet messages when installing business templates
install_bt5_quiet = 0 install_bt5_quiet = 0
...@@ -354,23 +353,6 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase): ...@@ -354,23 +353,6 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
if not uf.getUserById(user_name): if not uf.getUserById(user_name):
uf._doAddUser(user_name, self.newPassword(), ['Member'], []) uf._doAddUser(user_name, self.newPassword(), ['Member'], [])
def _setUpDummyMailHost(self):
"""Replace Original Mail Host by Dummy Mail Host in a non-persistent way
"""
cls = self.portal.MailHost.__class__
if not issubclass(cls, DummyMailHostMixin):
cls.__bases__ = (DummyMailHostMixin,) + cls.__bases__
pmc_init_of(cls)
def _restoreMailHost(self):
"""Restore original Mail Host
"""
if self.portal is not None:
cls = self.portal.MailHost.__class__
if cls.__bases__[0] is DummyMailHostMixin:
cls.__bases__ = cls.__bases__[1:]
pmc_init_of(cls)
def pinDateTime(self, date_time): def pinDateTime(self, date_time):
# pretend time has stopped at a certain date (i.e. the test runs # pretend time has stopped at a certain date (i.e. the test runs
# infinitely fast), for example to avoid errors on tests that are started # infinitely fast), for example to avoid errors on tests that are started
......
...@@ -9,8 +9,9 @@ from Testing import ZopeTestCase ...@@ -9,8 +9,9 @@ from Testing import ZopeTestCase
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from zLOG import LOG, ERROR from zLOG import LOG, ERROR
from Products.CMFActivity.Activity.Queue import VALIDATION_ERROR_DELAY from Products.CMFActivity.Activity.Queue import VALIDATION_ERROR_DELAY
from ExtensionClass import pmc_init_of
from Products.ERP5Type.tests.utils import \ from Products.ERP5Type.tests.utils import \
addUserToDeveloperRole, createZServer, parseListeningAddress addUserToDeveloperRole, createZServer, DummyMailHostMixin, parseListeningAddress
from Products.CMFActivity.ActivityTool import getCurrentNode from Products.CMFActivity.ActivityTool import getCurrentNode
...@@ -354,6 +355,23 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase): ...@@ -354,6 +355,23 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
self._registerNode(distributing=not cluster, processing=1) self._registerNode(distributing=not cluster, processing=1)
self.commit() self.commit()
def _setUpDummyMailHost(self):
"""Replace Original Mail Host by Dummy Mail Host in a non-persistent way
"""
cls = self.portal.MailHost.__class__
if not issubclass(cls, DummyMailHostMixin):
cls.__bases__ = (DummyMailHostMixin,) + cls.__bases__
pmc_init_of(cls)
def _restoreMailHost(self):
"""Restore original Mail Host
"""
if self.portal is not None:
cls = self.portal.MailHost.__class__
if cls.__bases__[0] is DummyMailHostMixin:
cls.__bases__ = cls.__bases__[1:]
pmc_init_of(cls)
def processing_node(self): def processing_node(self):
"""Main loop for nodes that process activities""" """Main loop for nodes that process activities"""
try: try:
...@@ -361,9 +379,10 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase): ...@@ -361,9 +379,10 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
time.sleep(.3) time.sleep(.3)
transaction.begin() transaction.begin()
try: try:
portal = self.app[self.app.test_portal_name] portal = self.portal = self.app[self.app.test_portal_name]
except (AttributeError, KeyError): except (AttributeError, KeyError):
continue continue
self._setUpDummyMailHost()
if portal.portal_activities.isSubscribed(): if portal.portal_activities.isSubscribed():
try: try:
portal.portal_activities.process_timer(None, None) portal.portal_activities.process_timer(None, None)
......
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