collective.MockMailHost


Namecollective.MockMailHost JSON
Version 3.0.0 PyPI version JSON
download
home_pagehttps://github.com/collective/collective.mockmailhost
SummaryUsed for integration testing with Plone
upload_time2024-04-23 16:22:30
maintainerNone
docs_urlNone
authorSuresh V.
requires_python>=3.7
licenseGPL
keywords mock mailhost tests
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            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()

.. _Plone: http://plone.org
.. _`plone.app.testing`: http://pypi.python.org/pypi/plone.app.testing

Using a member-posting forum
============================

    >>> from Products.CMFCore.utils import getToolByName
    >>> from Products.MailHost.interfaces import IMailHost
    >>> from zope.component import getUtility

    >>> app = layer['app']
    >>> portal = layer['portal']

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.

    >>> portal.error_log._ignored_exceptions = ()
    >>> portal.left_slots = portal.right_slots = []
    >>> workflow = portal.portal_workflow

Validate mailhost replacement
-----------------------------

    >>> portal.MailHost
    <collective.MockMailHost.MockMailHost.MockMailHost object at ...>

    >>> getToolByName(portal, 'MailHost')
    <collective.MockMailHost.MockMailHost.MockMailHost object at ...>

    >>> getUtility(IMailHost)
    <collective.MockMailHost.MockMailHost.MockMailHost object at ...>


Send email
----------

    >>> to_ = "member@example.com"
    >>> from_ = "admin@example.com"
    >>> msg = """
    ...
    ... Dear Sir:
    ...
    ... Thank you"""
    >>> portal.MailHost.send(msg, to_, from_)
    >>> len(portal.MailHost.messages)
    1
    >>> b'To: member@example.com' in portal.MailHost.messages[0]
    True
    >>> b'From: admin@example.com' in portal.MailHost.messages[0]
    True
    >>> b'Dear Sir:' in portal.MailHost.messages[0]
    True
    >>> portal.MailHost.messages_from
    ['admin@example.com']
    >>> portal.MailHost.messages_to
    [['member@example.com']]
    >>> portal.MailHost.reset()
    >>> len(portal.MailHost.messages)
    0

Send an `email.message.EmailMessage` object with cc/bcc recipients

    >>> from email.message import EmailMessage
    >>> msg = EmailMessage()
    >>> msg["Subject"] = "Hello"
    >>> msg["From"] = "me@example.com"
    >>> msg["To"] = "you@example.com"
    >>> msg["Cc"] = "foo@example.com"
    >>> msg["Bcc"] = "bar@example.com"
    >>> msg.set_content("""
    ... This message is for you, foo, and bar.
    ... """)
    >>> portal.MailHost.send(msg)
    >>> len(portal.MailHost.messages)
    1
    >>> b'To: you@example.com' in portal.MailHost.messages[0]
    True
    >>> b'From: me@example.com' in portal.MailHost.messages[0]
    True
    >>> b'Cc: foo@example.com' in portal.MailHost.messages[0]
    True
    >>> b'bar@example.com' in portal.MailHost.messages[0]
    False
    >>> b'This message is for you, foo, and bar.' in portal.MailHost.messages[0]
    True
    >>> len(portal.MailHost.messages)
    1
    >>> portal.MailHost.messages_from
    ['me@example.com']
    >>> portal.MailHost.messages_to
    [['you@example.com', 'foo@example.com', 'bar@example.com']]
    >>> portal.MailHost.reset()
    >>> len(portal.MailHost.messages)
    0

Changelog
=========

3.0.0 (2024-04-23)
------------------

Breaking changes:

- Remove support for Python versions prior to 3.7 and Plone versions
  prior to 5.2.
  [mamico]

New features:

- Add `messages_from`, and `messages_to` to record senders and recipients.
  This is useful for testing `bcc` that is not present in the message.
  [mamico]

Bug fixes:

- *add item here*


2.0.0 (2018-11-06)
------------------

Breaking changes:

- Do not depend on old SecureMailHost any longer.
  [pbauer]

New features:

- Python 3 support.
  [pbauer]


1.1.0 (2018-06-27)
------------------

- Fix import location, Globals has been removed.
  [gforcada]

- Rework tests setup.
  [gforcada]


1.0 (2016-01-25)
----------------

- Fix MIMEText compatibility (broken since 0.9).
  [jone]


0.9 (2015-07-10)
----------------

- Clean up msg before sending. Otherwise Plone self registration
  email does not work [sureshvv]


0.8 (2015-06-13)
----------------

- Add browser view for functional testing [Casecarsid]


0.7 (2013-07-05)
----------------

- MANIFEST [sureshvv]


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]

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/collective/collective.mockmailhost",
    "name": "collective.MockMailHost",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "mock mailhost tests",
    "author": "Suresh V.",
    "author_email": "suresh@grafware.com",
    "download_url": "https://files.pythonhosted.org/packages/19/48/18aa36e82d58f97ee04a216cd9a90d76f56ef8d6482d6c3d007fab5d77a3/collective.MockMailHost-3.0.0.tar.gz",
    "platform": null,
    "description": "Introduction\n============\n\n``collective.MockMailHost`` enables integration testing of email functionality\nfrom Plone_. Simply add this egg to your [test] runner section, and install\nthis product through your ``Layer`` or ``TestCase``.\n\nNote\n  THIS IS FOR TESTING PURPOSE ONLY, do not use this product on your\n  running Plone site. It replaces the standard MailHost with a Mock\n  MailHost that you can poke at to check email content and recipients.\n\nHas been tested with Plone 4 but should also work with earlier versions.\n\n\nIntegration\n-----------\n\nExample how to integrate ``collective.MockMailHost`` to your testing setup\nbased on `plone.app.testing`_. Add the package to your extras_requires section\nin your package's ``setup.py`` file, so buildout will automatically download\nthe package for you.::\n\n    setup(name='my.package',\n          ...\n          extras_require={\n            'test': [\n                'plone.app.testing',\n                'collective.MockMailHost',\n            ]\n          },\n          ...\n          )\n\nYour test layer setup could look like this example below::\n\n    from plone.app.testing import helpers, layers\n    from plone.testing import z2\n\n\n    class MyLayer(helpers.PloneSandboxLayer):\n        defaultBases = (layers.PLONE_FIXTURE, )\n\n        def setUpZope(self, app, configurationContext):\n            # Load zcml\n            import collective.MockMailHost\n            self.loadZCML(package=collective.MockMailHost)\n\n            # Install product and call its initialize() function\n            z2.installProduct(app, 'collective.MockMailHost')\n\n            # Note: you can skip this if my.product is not a Zope 2-style\n            # product, i.e. it is not in the Products.* namespace and it\n            # does not have a <five:registerPackage /> directive in its\n            # configure.zcml.\n\n        def tearDownZope(self, app):\n            # Uninstall product\n            z2.uninstallProduct(app, 'collective.MockMailHost')\n\n            # Note: Again, you can skip this if my.product is not a Zope 2-\n            # style product\n\n        def setUpPloneSite(self, portal):\n            helpers.quickInstallProduct(portal, 'collective.MockMailHost')\n\n            helpers.applyProfile(portal, 'collective.MockMailHost:default')\n\n    MY_FIXTURE = MyLayer()\n\n.. _Plone: http://plone.org\n.. _`plone.app.testing`: http://pypi.python.org/pypi/plone.app.testing\n\nUsing a member-posting forum\n============================\n\n    >>> from Products.CMFCore.utils import getToolByName\n    >>> from Products.MailHost.interfaces import IMailHost\n    >>> from zope.component import getUtility\n\n    >>> app = layer['app']\n    >>> portal = layer['portal']\n\nTest starting conversations, replying and modifying comments in a default\nmember-posting forum.\n\nLet us log all exceptions, which is useful for debugging. Also, clear portlet\nslots, to make the test browser less confused by things like the recent portlet\nand the navtree.\n\n    >>> portal.error_log._ignored_exceptions = ()\n    >>> portal.left_slots = portal.right_slots = []\n    >>> workflow = portal.portal_workflow\n\nValidate mailhost replacement\n-----------------------------\n\n    >>> portal.MailHost\n    <collective.MockMailHost.MockMailHost.MockMailHost object at ...>\n\n    >>> getToolByName(portal, 'MailHost')\n    <collective.MockMailHost.MockMailHost.MockMailHost object at ...>\n\n    >>> getUtility(IMailHost)\n    <collective.MockMailHost.MockMailHost.MockMailHost object at ...>\n\n\nSend email\n----------\n\n    >>> to_ = \"member@example.com\"\n    >>> from_ = \"admin@example.com\"\n    >>> msg = \"\"\"\n    ...\n    ... Dear Sir:\n    ...\n    ... Thank you\"\"\"\n    >>> portal.MailHost.send(msg, to_, from_)\n    >>> len(portal.MailHost.messages)\n    1\n    >>> b'To: member@example.com' in portal.MailHost.messages[0]\n    True\n    >>> b'From: admin@example.com' in portal.MailHost.messages[0]\n    True\n    >>> b'Dear Sir:' in portal.MailHost.messages[0]\n    True\n    >>> portal.MailHost.messages_from\n    ['admin@example.com']\n    >>> portal.MailHost.messages_to\n    [['member@example.com']]\n    >>> portal.MailHost.reset()\n    >>> len(portal.MailHost.messages)\n    0\n\nSend an `email.message.EmailMessage` object with cc/bcc recipients\n\n    >>> from email.message import EmailMessage\n    >>> msg = EmailMessage()\n    >>> msg[\"Subject\"] = \"Hello\"\n    >>> msg[\"From\"] = \"me@example.com\"\n    >>> msg[\"To\"] = \"you@example.com\"\n    >>> msg[\"Cc\"] = \"foo@example.com\"\n    >>> msg[\"Bcc\"] = \"bar@example.com\"\n    >>> msg.set_content(\"\"\"\n    ... This message is for you, foo, and bar.\n    ... \"\"\")\n    >>> portal.MailHost.send(msg)\n    >>> len(portal.MailHost.messages)\n    1\n    >>> b'To: you@example.com' in portal.MailHost.messages[0]\n    True\n    >>> b'From: me@example.com' in portal.MailHost.messages[0]\n    True\n    >>> b'Cc: foo@example.com' in portal.MailHost.messages[0]\n    True\n    >>> b'bar@example.com' in portal.MailHost.messages[0]\n    False\n    >>> b'This message is for you, foo, and bar.' in portal.MailHost.messages[0]\n    True\n    >>> len(portal.MailHost.messages)\n    1\n    >>> portal.MailHost.messages_from\n    ['me@example.com']\n    >>> portal.MailHost.messages_to\n    [['you@example.com', 'foo@example.com', 'bar@example.com']]\n    >>> portal.MailHost.reset()\n    >>> len(portal.MailHost.messages)\n    0\n\nChangelog\n=========\n\n3.0.0 (2024-04-23)\n------------------\n\nBreaking changes:\n\n- Remove support for Python versions prior to 3.7 and Plone versions\n  prior to 5.2.\n  [mamico]\n\nNew features:\n\n- Add `messages_from`, and `messages_to` to record senders and recipients.\n  This is useful for testing `bcc` that is not present in the message.\n  [mamico]\n\nBug fixes:\n\n- *add item here*\n\n\n2.0.0 (2018-11-06)\n------------------\n\nBreaking changes:\n\n- Do not depend on old SecureMailHost any longer.\n  [pbauer]\n\nNew features:\n\n- Python 3 support.\n  [pbauer]\n\n\n1.1.0 (2018-06-27)\n------------------\n\n- Fix import location, Globals has been removed.\n  [gforcada]\n\n- Rework tests setup.\n  [gforcada]\n\n\n1.0 (2016-01-25)\n----------------\n\n- Fix MIMEText compatibility (broken since 0.9).\n  [jone]\n\n\n0.9 (2015-07-10)\n----------------\n\n- Clean up msg before sending. Otherwise Plone self registration\n  email does not work [sureshvv]\n\n\n0.8 (2015-06-13)\n----------------\n\n- Add browser view for functional testing [Casecarsid]\n\n\n0.7 (2013-07-05)\n----------------\n\n- MANIFEST [sureshvv]\n\n\n0.6 (2013-07-03)\n----------------\n\n- Track msg_type also.\n  [sureshvv]\n\n- Behave more like ``collective.testcaselayer``'s MockMailHost.\n  [saily]\n\n- Documentation updates\n  [saily]\n\n\n0.5 - 2012-09-25\n----------------\n\n- Remove ZopeSkel and Paster dependency from setup.py\n  [saily]\n\n- Moved to github and changed to README.rst, links in setup.py\n  [saily]\n\n- Allow multiple paramters for ``send`` and ``secureSend`` method in\n  MockMailHost class.  [saily]\n\n\n0.4 (2011-05-17)\n----------------\n\n- Register MockMailHost in SiteManager to get MockMailHost when using\n  ``getToolByName(context, 'MailHost')`` or ``getUtility(IMailHost)``.\n  [saily]\n\n- Inherit from MailHost instead of SimpleItem\n  [saily]\n\n- Implement the secureSend method\n  [saily]\n\n\n0.3 (2011-04-04)\n----------------\n\n- Add ``**kwargs`` to MockMailHost's send method to support mto, mfrom, ...\n  keyword arguments as default MailHost does.  [saily]\n\n- Added file for generic setup various handlers\n  [sureshvv]\n\n\n0.2 (2010-05-21)\n----------------\n\n- Added tests\n  [sureshvv]\n\n\n0.1 (2010-05-16)\n----------------\n\n- Initial release\n  [sureshvv]\n",
    "bugtrack_url": null,
    "license": "GPL",
    "summary": "Used for integration testing with Plone",
    "version": "3.0.0",
    "project_urls": {
        "Homepage": "https://github.com/collective/collective.mockmailhost"
    },
    "split_keywords": [
        "mock",
        "mailhost",
        "tests"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2b9951cdac9f189de8f9c7882dd845fa6e8aece928419ebb90ba5005a0f67ccb",
                "md5": "b22c0d211f3862458f6b67754d59ff93",
                "sha256": "a008be95e6e85afff75310156cde30462b20435a1223d0ca791bc6962a61118d"
            },
            "downloads": -1,
            "filename": "collective.MockMailHost-3.0.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b22c0d211f3862458f6b67754d59ff93",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.7",
            "size": 12530,
            "upload_time": "2024-04-23T16:22:29",
            "upload_time_iso_8601": "2024-04-23T16:22:29.226957Z",
            "url": "https://files.pythonhosted.org/packages/2b/99/51cdac9f189de8f9c7882dd845fa6e8aece928419ebb90ba5005a0f67ccb/collective.MockMailHost-3.0.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "194818aa36e82d58f97ee04a216cd9a90d76f56ef8d6482d6c3d007fab5d77a3",
                "md5": "fb4a110ef335be4fdf7b41eaafc80539",
                "sha256": "392071e1037d19851c7e209efd681e9830c11356226fc17c23f3e671b8ca9f06"
            },
            "downloads": -1,
            "filename": "collective.MockMailHost-3.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "fb4a110ef335be4fdf7b41eaafc80539",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 19556,
            "upload_time": "2024-04-23T16:22:30",
            "upload_time_iso_8601": "2024-04-23T16:22:30.625903Z",
            "url": "https://files.pythonhosted.org/packages/19/48/18aa36e82d58f97ee04a216cd9a90d76f56ef8d6482d6c3d007fab5d77a3/collective.MockMailHost-3.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-23 16:22:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "collective",
    "github_project": "collective.mockmailhost",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "collective.mockmailhost"
}
        
Elapsed time: 2.69848s