Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install collective.mockmailhost

How to install collective.MockMailHost

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install collective.mockmailhost
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.4
0.7Never BuiltWhy not?
0.4 Available View build log
0.3 Available View build log
0.2 Available View build log
Windows (64-bit)
0.4
0.7Never BuiltWhy not?
0.4 Available View build log
0.3 Available View build log
0.2 Available View build log
Mac OS X (10.5+)
0.4
0.7Never BuiltWhy not?
0.4 Available View build log
0.3 Available View build log
0.2 Available View build log
Linux (32-bit)
0.5
0.7Never BuiltWhy not?
0.5 Available View build log
0.4 Available View build log
0.3 Available View build log
0.2 Available View build log
Linux (64-bit)
0.7 Available View build log
0.5 Available View build log
0.4 Available View build log
0.3 Available View build log
0.2 Available View build log
 
Author
License
GPL
Lastest release
version 0.7 on Jan 9th, 2014

Introduction

collective.MockMailHost enables integration testing of email functionality from Plone. Simply add this egg to your [test] runner section, and install this product through your Layer or TestCase.

Note
THIS IS FOR TESTING PURPOSE ONLY, do not use this product on your running Plone site. It replaces the standard MailHost with a Mock MailHost that you can poke at to check email content and recipients.

Has been tested with Plone 4 but should also work with earlier versions.

Integration

Example how to integrate collective.MockMailHost to your testing setup based on plone.app.testing. Add the package to your extras_requires section in your package's setup.py file, so buildout will automatically download the package for you.:

setup(name='my.package',
      ...
      extras_require={
        'test': [
            'plone.app.testing',
            'collective.MockMailHost',
        ]
      },
      ...
      )

Your test layer setup could look like this example below:

from plone.app.testing import helpers, layers
from plone.testing import z2


class MyLayer(helpers.PloneSandboxLayer):
    defaultBases = (layers.PLONE_FIXTURE, )

    def setUpZope(self, app, configurationContext):
        # Load zcml
        import collective.MockMailHost
        self.loadZCML(package=collective.MockMailHost)

        # Install product and call its initialize() function
        z2.installProduct(app, 'collective.MockMailHost')

        # Note: you can skip this if my.product is not a Zope 2-style
        # product, i.e. it is not in the Products.* namespace and it
        # does not have a <five:registerPackage /> directive in its
        # configure.zcml.

    def tearDownZope(self, app):
        # Uninstall product
        z2.uninstallProduct(app, 'collective.MockMailHost')

        # Note: Again, you can skip this if my.product is not a Zope 2-
        # style product

    def setUpPloneSite(self, portal):
        helpers.quickInstallProduct(portal, 'collective.MockMailHost')

        helpers.applyProfile(portal, 'collective.MockMailHost:default')

MY_FIXTURE = MyLayer()

Using a member-posting forum

Test starting conversations, replying and modifying comments in a default member-posting forum.

Let us log all exceptions, which is useful for debugging. Also, clear portlet slots, to make the test browser less confused by things like the recent portlet and the navtree.

>>> self.portal.error_log._ignored_exceptions = ()
>>> self.portal.left_slots = self.portal.right_slots = []
>>> workflow = self.portal.portal_workflow
Validate mailhost replacement
>>> self.portal.MailHost
<MockMailHost at ...>
>>> from Products.CMFCore.utils import getToolByName
>>> getToolByName(self.portal, 'MailHost')
<MockMailHost at ...>
>>> from zope.component import getUtility
>>> from Products.MailHost.interfaces import IMailHost
>>> getUtility(IMailHost)
<MockMailHost at ...>
Send email
>>> to = "member@example.com"
>>> from = "admin@example.com"
>>> msg = """
...
... Dear Sir:
...
... Thank you"""
>>> self.portal.MailHost.send(msg, to, from)
>>> len(self.portal.MailHost.messages)
1
>>> print self.portal.MailHost.messages[0].as_string()
...
To: member@example.com
From: admin@example.com
...
>>> print self.portal.MailHost.messages[0].as_string()
...
Dear Sir:
...
>>> self.portal.MailHost.reset()
>>> len(self.portal.MailHost.messages)
0

Changelog

0.7 (2013-07-05)
  • Nothing changed yet.
0.6 (2013-07-03)
  • Track msg_type also. [sureshvv]
  • Behave more like collective.testcaselayer's MockMailHost. [saily]
  • Documentation updates [saily]
0.5 - 2012-09-25
  • Remove ZopeSkel and Paster dependency from setup.py [saily]
  • Moved to github and changed to README.rst, links in setup.py [saily]
  • Allow multiple paramters for send and secureSend method in MockMailHost class. [saily]
0.4 (2011-05-17)
  • Register MockMailHost in SiteManager to get MockMailHost when using getToolByName(context, 'MailHost') or getUtility(IMailHost). [saily]
  • Inherit from MailHost instead of SimpleItem [saily]
  • Implement the secureSend method [saily]
0.3 (2011-04-04)
  • Add **kwargs to MockMailHost's send method to support mto, mfrom, ... keyword arguments as default MailHost does. [saily]
  • Added file for generic setup various handlers [sureshvv]
0.2 (2010-05-21)
  • Added tests [sureshvv]
0.1 (2010-05-16)
  • Initial release [sureshvv]

Subscribe to package updates

Last updated Jan 9th, 2014

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.