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
from glob import glob
from hashlib import md5
from warnings import warn
from ExtensionClass import pmc_init_of
from DateTime import DateTime
import Products.ZMySQLDA.DA
from Products.ZMySQLDA.DA import Connection as ZMySQLDA_Connection
......@@ -65,7 +64,7 @@ from zLOG import LOG, DEBUG
from Products.ERP5Type.Utils import convertToUpperCase
from Products.ERP5Type.tests.backportUnittest import SetupSiteError
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
install_bt5_quiet = 0
......@@ -354,23 +353,6 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
if not uf.getUserById(user_name):
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):
# 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
......
......@@ -9,8 +9,9 @@ from Testing import ZopeTestCase
from ZODB.POSException import ConflictError
from zLOG import LOG, ERROR
from Products.CMFActivity.Activity.Queue import VALIDATION_ERROR_DELAY
from ExtensionClass import pmc_init_of
from Products.ERP5Type.tests.utils import \
addUserToDeveloperRole, createZServer, parseListeningAddress
addUserToDeveloperRole, createZServer, DummyMailHostMixin, parseListeningAddress
from Products.CMFActivity.ActivityTool import getCurrentNode
......@@ -354,6 +355,23 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
self._registerNode(distributing=not cluster, processing=1)
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):
"""Main loop for nodes that process activities"""
try:
......@@ -361,9 +379,10 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
time.sleep(.3)
transaction.begin()
try:
portal = self.app[self.app.test_portal_name]
portal = self.portal = self.app[self.app.test_portal_name]
except (AttributeError, KeyError):
continue
self._setUpDummyMailHost()
if portal.portal_activities.isSubscribed():
try:
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