[Checkins] SVN: zope.sendmail/trunk/src/zope/sendmail/tests/test_delivery.py Test that a broken mailer implementation's exceptions don't abort transactions if they happen too late. Add tests for a new 'vote' method that allows a mailer to tell the delivery implementation that it knows it will be unable to proceed.
Matthew Wilkes
matthew at matthewwilkes.co.uk
Tue Jun 29 06:19:40 EDT 2010
Log message for revision 113967:
Test that a broken mailer implementation's exceptions don't abort transactions if they happen too late. Add tests for a new 'vote' method that allows a mailer to tell the delivery implementation that it knows it will be unable to proceed.
Changed:
U zope.sendmail/trunk/src/zope/sendmail/tests/test_delivery.py
-=-
Modified: zope.sendmail/trunk/src/zope/sendmail/tests/test_delivery.py
===================================================================
--- zope.sendmail/trunk/src/zope/sendmail/tests/test_delivery.py 2010-06-29 07:01:01 UTC (rev 113966)
+++ zope.sendmail/trunk/src/zope/sendmail/tests/test_delivery.py 2010-06-29 10:19:40 UTC (rev 113967)
@@ -34,6 +34,9 @@
def send(self, fromaddr, toaddrs, message):
self.sent_messages.append((fromaddr, toaddrs, message))
+
+ abort = None
+ vote = None
class TestMailDataManager(TestCase):
@@ -137,8 +140,60 @@
self.assertEquals(mailer.sent_messages, [])
transaction.abort()
self.assertEquals(mailer.sent_messages, [])
+
+ def testBrokenMailerErrorsAreEaten(self):
+ from zope.sendmail.delivery import DirectMailDelivery
+ mailer = BrokenMailerStub()
+ delivery = DirectMailDelivery(mailer)
+ fromaddr = 'Jim <jim at example.com'
+ toaddrs = ('Guido <guido at example.com>',
+ 'Steve <steve at examplecom>')
+ opt_headers = ('From: Jim <jim at example.org>\n'
+ 'To: some-zope-coders:;\n'
+ 'Date: Mon, 19 May 2003 10:17:36 -0400\n'
+ 'Message-Id: <20030519.1234 at example.org>\n')
+ message = ('Subject: example\n'
+ '\n'
+ 'This is just an example\n')
+ msgid = delivery.send(fromaddr, toaddrs, opt_headers + message)
+ try:
+ transaction.commit()
+ finally:
+ # Clean up after ourselves
+ transaction.abort()
+
+ def testRefusingMailerDiesInVote(self):
+ from zope.sendmail.delivery import DirectMailDelivery
+ mailer = RefusingMailerStub()
+ delivery = DirectMailDelivery(mailer)
+ fromaddr = 'Jim <jim at example.com'
+ toaddrs = ('Guido <guido at example.com>',
+ 'Steve <steve at examplecom>')
+ opt_headers = ('From: Jim <jim at example.org>\n'
+ 'To: some-zope-coders:;\n'
+ 'Date: Mon, 19 May 2003 10:17:36 -0400\n'
+ 'Message-Id: <20030519.1234 at example.org>\n')
+ message = ('Subject: example\n'
+ '\n'
+ 'This is just an example\n')
+ msgid = delivery.send(fromaddr, toaddrs, opt_headers + message)
+ try:
+ transaction.commit()
+ except:
+ if transaction.get()._voted:
+ # We voted for commit then failed, reraise
+ raise
+ else:
+ # We vetoed a commit, that's good.
+ pass
+ else:
+ self.fail("Did not raise an exception in vote")
+ finally:
+ # Clean up after ourselves
+ transaction.abort()
+
class MaildirWriterStub(object):
data = ''
@@ -219,8 +274,25 @@
def send(self, fromaddr, toaddrs, message):
raise BizzarreMailError("bad things happened while sending mail")
+
+ vote = None
+ abort = None
+class RefusingMailerStub(object):
+
+ implements(IMailer)
+ def __init__(self, *args, **kw):
+ pass
+
+ def vote(self, fromaddr, toaddrs, message):
+ raise BizzarreMailError("bad things happened while sending mail")
+
+ def send(self, fromaddr, toaddrs, message):
+ return
+
+ abort = None
+
class SMTPResponseExceptionMailerStub(object):
implements(IMailer)
More information about the checkins
mailing list