[Checkins] SVN: z3c.coverage/trunk/src/z3c/coverage/coveragediff.
Test the MailSender class.
Marius Gedminas
marius at pov.lt
Thu Jul 19 14:32:21 EDT 2007
Log message for revision 78190:
Test the MailSender class.
Changed:
U z3c.coverage/trunk/src/z3c/coverage/coveragediff.py
U z3c.coverage/trunk/src/z3c/coverage/coveragediff.txt
-=-
Modified: z3c.coverage/trunk/src/z3c/coverage/coveragediff.py
===================================================================
--- z3c.coverage/trunk/src/z3c/coverage/coveragediff.py 2007-07-19 18:31:41 UTC (rev 78189)
+++ z3c.coverage/trunk/src/z3c/coverage/coveragediff.py 2007-07-19 18:32:20 UTC (rev 78190)
@@ -221,6 +221,8 @@
class MailSender(object):
"""Send emails over SMTP"""
+ connection_class = smtplib.SMTP
+
def __init__(self, smtp_host='localhost', smtp_port=25):
self.smtp_host = smtp_host
self.smtp_port = smtp_port
@@ -235,7 +237,7 @@
if to_addr:
msg['To'] = to_addr
msg['Subject'] = subject
- smtp = smtplib.SMTP(self.smtp_host, self.smtp_port)
+ smtp = self.connection_class(self.smtp_host, self.smtp_port)
smtp.sendmail(from_addr, to_addr, msg.as_string())
smtp.quit()
Modified: z3c.coverage/trunk/src/z3c/coverage/coveragediff.txt
===================================================================
--- z3c.coverage/trunk/src/z3c/coverage/coveragediff.txt 2007-07-19 18:31:41 UTC (rev 78189)
+++ z3c.coverage/trunk/src/z3c/coverage/coveragediff.txt 2007-07-19 18:32:20 UTC (rev 78190)
@@ -5,10 +5,63 @@
coverage reports. It reports regressions, that is, increases in the number
of untested code.
-This document describes the internals of ``coveragediff``. It also acts as
+This document describes the internals of ``coveragediff.py``. It also acts as
a test suite.
+
+MailSender
+----------
+
+The ``MailSender`` class is responsible for assembling an RFC-2822 email
+message and handing it off to an SMTP server.
+
+ >>> from z3c.coverage.coveragediff import MailSender
+ >>> mailer = MailSender('smtp.example.com', 25)
+
+Since it wouldn't be a good idea to actually send emails from the test suite,
+we'll use a stub SMTP connection class.
+
+ >>> mailer.connection_class = None
+ >>> class FakeSMTP(object):
+ ... def __init__(self, host, port):
+ ... print "Connecting to %s:%s" % (host, port)
+ ... def sendmail(self, sender, recipients, body):
+ ... from smtplib import quoteaddr
+ ... print "MAIL FROM:%s" % quoteaddr(sender)
+ ... if isinstance(recipients, basestring):
+ ... recipients = [recipients]
+ ... for recipient in recipients:
+ ... print "RCPT TO:%s" % quoteaddr(recipient)
+ ... print "DATA"
+ ... print body
+ ... print "."
+ ... def quit(self):
+ ... print "QUIT"
+ >>> mailer.connection_class = FakeSMTP
+
+Here's how you send an email:
+
+ >>> mailer.send_email('Some Bot <bot at example.com>',
+ ... 'Maintainer <m at example.com>',
+ ... 'Test coverage regressions',
+ ... 'You broke the tests completely. Have a nice day.')
+ Connecting to smtp.example.com:25
+ MAIL FROM:<bot at example.com>
+ RCPT TO:<m at example.com>
+ DATA
+ Content-Type: text/plain; charset="us-ascii"
+ MIME-Version: 1.0
+ Content-Transfer-Encoding: 7bit
+ From: Some Bot <bot at example.com>
+ To: Maintainer <m at example.com>
+ Subject: Test coverage regressions
+ <BLANKLINE>
+ You broke the tests completely. Have a nice day.
+ .
+ QUIT
+
+
ReportPrinter
-------------
More information about the Checkins
mailing list