/
test_mailing.py
49 lines (38 loc) · 1.68 KB
/
test_mailing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from Products.MailHost.interfaces import IMailHost
from ftw.testing.mailing import Mailing
from ftw.testing.testing import PAGE_OBJECT_FUNCTIONAL
from unittest2 import TestCase
from zope.component import getUtility
class TestMailing(TestCase):
layer = PAGE_OBJECT_FUNCTIONAL
def setUp(self):
Mailing(self.layer['portal']).set_up(configure=True)
def tearDown(self):
Mailing(self.layer['portal']).tear_down()
def test_mailing_mock(self):
mailhost = getUtility(IMailHost)
mailhost.send(messageText='Hello World',
mto='info@4teamwork.ch',
mfrom='info@4teamwork.ch',
subject='A test mail from ftw.testing')
self.assertTrue(Mailing(self.layer['portal']).has_messages(),
'There should be one message in the MockMailHost,'
' but there was none.')
self.assertEquals(
1, len(Mailing(self.layer['portal']).get_messages()),
'Expected exactly one email in the MockMailHost.')
message = Mailing(self.layer['portal']).pop().split('\n')
self.assertEquals(
0, len(Mailing(self.layer['portal']).get_messages()),
'Expected no email in the MockMailHost after popping.')
# replace "Date: ..." - it changes constantly.
message = [line.startswith('Date:') and 'Date: ---' or line
for line in message]
self.assertEquals(
['Subject: A test mail from ftw.testing',
'To: info@4teamwork.ch',
'From: info@4teamwork.ch',
'Date: ---',
'',
'Hello World'],
message)