Read mail settings from new (Plone 5) registry.

This commit is contained in:
Timo Stollenwerk
2014-12-13 16:20:08 +01:00
parent e11471a44e
commit 785bc7b890
4 changed files with 35 additions and 24 deletions
@@ -7,11 +7,13 @@ from Acquisition import aq_base
from zope.component import createObject
from zope.component import getSiteManager
from zope.component import queryUtility
from zope.component import getUtility
from plone.app.testing import TEST_USER_ID, setRoles
from Products.MailHost.interfaces import IMailHost
from Products.CMFPlone.tests.utils import MockMailHost
from Products.CMFPlone.interfaces import IMailSchema
from plone.registry.interfaces import IRegistry
@@ -34,7 +36,9 @@ class TestUserNotificationUnit(unittest.TestCase):
sm.unregisterUtility(provided=IMailHost)
sm.registerUtility(mailhost, provided=IMailHost)
# We need to fake a valid mail setup
self.portal.email_from_address = "portal@plone.test"
registry = getUtility(IRegistry)
mail_settings = registry.forInterface(IMailSchema, prefix='plone')
mail_settings.email_from_address = "portal@plone.test"
self.mailhost = self.portal.MailHost
# Enable user notification setting
registry = queryUtility(IRegistry)
@@ -122,7 +126,9 @@ class TestUserNotificationUnit(unittest.TestCase):
def test_do_not_notify_user_when_no_sender_is_available(self):
# Set sender mail address to none and make sure no email is send to
# the moderator.
self.portal.email_from_address = None
registry = getUtility(IRegistry)
mail_settings = registry.forInterface(IMailSchema, prefix='plone')
mail_settings.email_from_address = None
comment = createObject('plone.Comment')
comment.text = 'Comment text'
comment.user_notification = True
@@ -132,7 +138,6 @@ class TestUserNotificationUnit(unittest.TestCase):
comment.text = 'Comment text'
self.conversation.addComment(comment)
self.assertEqual(len(self.mailhost.messages), 0)
def test_notify_only_once(self):
@@ -172,7 +177,9 @@ class TestModeratorNotificationUnit(unittest.TestCase):
sm.unregisterUtility(provided=IMailHost)
sm.registerUtility(mailhost, provided=IMailHost)
# We need to fake a valid mail setup
self.portal.email_from_address = "portal@plone.test"
registry = getUtility(IRegistry)
mail_settings = registry.forInterface(IMailSchema, prefix='plone')
mail_settings.email_from_address = "portal@plone.test"
self.mailhost = self.portal.MailHost
# Enable comment moderation
self.portal.portal_types['Document'].allow_discussion = True
@@ -255,7 +262,9 @@ class TestModeratorNotificationUnit(unittest.TestCase):
def test_do_not_notify_moderator_when_no_sender_is_available(self):
# Set sender mail address to nonw and make sure no email is send to the
# moderator.
self.portal.email_from_address = None
registry = getUtility(IRegistry)
mail_settings = registry.forInterface(IMailSchema, prefix='plone')
mail_settings.email_from_address = None
comment = createObject('plone.Comment')
comment.text = 'Comment text'