[Zope3-checkins] CVS: Zope3/src/zope/app/mail/tests - test_service.py:1.1.2.3
Albertas Agejevas
alga@codeworks.lt
Sun, 22 Jun 2003 13:47:27 -0400
Update of /cvs-repository/Zope3/src/zope/app/mail/tests
In directory cvs.zope.org:/tmp/cvs-serv25126/src/zope/app/mail/tests
Modified Files:
Tag: cw-mail-branch
test_service.py
Log Message:
EP2003 sprint: finished the mail service.
Added logging to the Zope log.
=== Zope3/src/zope/app/mail/tests/test_service.py 1.1.2.2 => 1.1.2.3 ===
--- Zope3/src/zope/app/mail/tests/test_service.py:1.1.2.2 Mon May 26 14:25:49 2003
+++ Zope3/src/zope/app/mail/tests/test_service.py Sun Jun 22 13:47:26 2003
@@ -23,6 +23,7 @@
from zope.app.interfaces.mail import IMailer
from transaction import get_transaction
from os import mkdir, rmdir, unlink, getpid, listdir
+from tempfile import mktemp
import os.path
__metaclass__ = type
@@ -127,15 +128,42 @@
self.path = path
self.create = create
self.msgs = []
+ self.files = []
def __iter__(self):
- return iter(self.msgs)
+ return iter(self.files)
def newMessage(self):
m = MaildirWriterStub()
self.msgs.append(m)
return m
+class LoggerStub:
+
+ def __init__(self):
+ self.infos = []
+ self.errors = []
+
+ def getLogger(name):
+ return self
+
+ def error(self, msg, *args, **kwargs):
+ self.errors.append((msg, args, kwargs))
+
+ def info(self, msg, *args, **kwargs):
+ self.infos.append((msg, args, kwargs))
+
+class BizzarreMailError(IOError):
+ pass
+
+class BrokenMailerStub:
+
+ implements(IMailer)
+ def __init__(self, *args, **kw):
+ pass
+
+ def send(self, fromaddr, toaddrs, message):
+ raise BizzarreMailError("bad things happened while sending mail")
class TestQueuedMailService(TestCase):
@@ -212,6 +240,7 @@
self.thread.setMaildir(self.md)
self.mailer = MailerStub()
self.thread.setMailer(self.mailer)
+ self.thread.log = LoggerStub()
def test_parseMessage(self):
@@ -228,14 +257,43 @@
self.assertEquals(m, msg)
def test_deliveration(self):
- self.md.msgs.append('X-Zope-From: foo@example.com\n'
- 'X-Zope-To: bar@example.com, baz@example.com\n'
- 'Header: value\n\nBody\n')
+ self.filename = mktemp()
+ temp = open(self.filename, "w+b")
+ temp.write('X-Zope-From: foo@example.com\n'
+ 'X-Zope-To: bar@example.com, baz@example.com\n'
+ 'Header: value\n\nBody\n')
+ temp.close()
+ self.md.files.append(self.filename)
self.thread.run(forever=False)
self.assertEquals(self.mailer.sent_messages,
[('foo@example.com',
('bar@example.com', 'baz@example.com'),
'Header: value\n\nBody\n')])
+ self.failIf(os.path.exists(self.filename), 'File exists')
+ self.assertEquals(self.thread.log.infos,
+ [('Mail from %s to %s sent.',
+ ('foo@example.com',
+ 'bar@example.com, baz@example.com'),
+ {})])
+
+
+ def test_error_logging(self):
+ self.thread.setMailer(BrokenMailerStub())
+ self.filename = mktemp()
+ temp = open(self.filename, "w+b")
+ temp.write('X-Zope-From: foo@example.com\n'
+ 'X-Zope-To: bar@example.com, baz@example.com\n'
+ 'Header: value\n\nBody\n')
+ temp.close()
+ self.md.files.append(self.filename)
+ self.thread.run(forever=False)
+ self.assertEquals(self.thread.log.errors,
+ [('Error while sending mail from %s to %s.',
+ ('foo@example.com',
+ 'bar@example.com, baz@example.com'),
+ {'exc_info': 1})])
+
+
def test_suite():
return TestSuite((