[Zope-dev] zope.sendmail and testing

Adam GROSZER agroszer at gmail.com
Tue Aug 25 10:02:28 EDT 2009


Hello,

I'd rather use a mailer stub for testing.
Like the one in zope.sendmail.tests.test_mailer.py

...
class SMTP(object):
...

Something like this can be setup for individual tests with

  <utility
      name="mailer-name"
      provides="zope.sendmail.interfaces.IMailer"
      factory="your.own.mailerFactory"
      />

def mailerFactory():
    mailer = SMTPMailer()
    mailer.smtp = SMTP
    return mailer 
      
Tuesday, August 25, 2009, 2:48:57 PM, you wrote:

JWK> Hello,

JWK> We're using zope.sendmail to send mail from our applications. These 
JWK> applications are built on top of a more generic application library. It
JWK> is this application library that depends on zope.sendmail. This 
JWK> application library listens for certain events and then can decide to 
JWK> send out an email.

JWK> Obviously, when running the tests for the concrete application no mail
JWK> is allowed to be actually sent.

JWK> Zope.sendmail explains in its README.txt that the developer using 
JWK> zope.sendmail should himself take care of not sending emails (by setting
JWK> up a test layer for example, that would register a no-op IMailDelivery
JWK> utility).

JWK> I had hoped that somehow zope.sendmail would automagically "detect" it
JWK> is used during test runs and then would not send out any mails.

JWK> I dug around in zope.testing and found the cleanup module that seems to
JWK> provide (if I understand correctly) a global registry of things to 
JWK> cleanup after tests. I wonder if this could be extended to also be able
JWK> to register routines for globally setting up stuff - in this case it 
JWK> could stub the mail delivery so that never ever any mail is actually 
JWK> send out when running tests.

JWK> Questions:

JWK> 1) how do others make sure that applications that directly or indirectly
JWK> trigger sending mails do not actually send during testing?

JWK> 2) am I on the right track thinking a "set up" equivalent of 
JWK> zope.testing.cleanup could be useful for these cases?

JWK> kind regards,
JWK> jw

JWK> --
JWK> Jan-Wijbrand Kolman

JWK> _______________________________________________
JWK> Zope-Dev maillist  -  Zope-Dev at zope.org
JWK> http://mail.zope.org/mailman/listinfo/zope-dev
JWK> **  No cross posts or HTML encoding!  **
JWK> (Related lists - 
JWK>  http://mail.zope.org/mailman/listinfo/zope-announce
JWK>  http://mail.zope.org/mailman/listinfo/zope )


-- 
Best regards,
 Adam GROSZER                            mailto:agroszer at gmail.com
--
Quote of the day:
To be upset over what you don't have is to waste what you do have. 
- Ken S. Keyes 



More information about the Zope-Dev mailing list