Skip to content

Commit

Permalink
Merge pull request #11 from collective/bcc
Browse files Browse the repository at this point in the history
test bcc recipients
  • Loading branch information
mauritsvanrees committed Apr 23, 2024
2 parents 340ce11 + 38274a4 commit b17f02c
Show file tree
Hide file tree
Showing 19 changed files with 251 additions and 63 deletions.
5 changes: 2 additions & 3 deletions .coveragerc
Expand Up @@ -5,8 +5,7 @@ branch = True
omit =
*/.buildout/eggs/*
/usr/*
parts/*
eggs/*
*/parts/*
*/eggs/*
*/bin/*
*/lib/*

57 changes: 57 additions & 0 deletions .github/workflows/tests.yml
@@ -0,0 +1,57 @@
name: tests

on:
push:
branches: [ master ]
pull_request:

jobs:
build:
strategy:
matrix:
config:
# [Python version, tox env]
- ["3.7", "plone52-py37"]
- ["3.8", "plone52-py38"]
- ["3.9", "plone52-py39"]
- ["3.8", "plone60-py38"]
- ["3.9", "plone60-py39"]
- ["3.10", "plone60-py310"]
- ["3.11", "plone60-py311"]
- ["3.12", "plone60-py312"]
runs-on: ubuntu-latest
name: ${{ matrix.config[1] }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.config[0] }}
- name: Pip cache
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.config[0] }}-${{ hashFiles('setup.*', 'tox.ini') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.config[0] }}-
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Test
run: tox -e ${{ matrix.config[1] }}
- name: Coveralls
uses: AndreMiras/coveralls-python-action@develop
with:
parallel: true
flag-name: ${{ matrix.config[1] }}

coveralls_finish:
needs: build
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: AndreMiras/coveralls-python-action@develop
with:
parallel-finished: true
8 changes: 8 additions & 0 deletions .gitignore
Expand Up @@ -12,3 +12,11 @@ eggs
fake-eggs
parts
var
.coverage
coverage.json
.python-version
.vscode/
include/
lib/
lib64
pyvenv.cfg
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

8 changes: 6 additions & 2 deletions CHANGES.rst
Expand Up @@ -6,11 +6,15 @@ Changelog

Breaking changes:

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

New features:

- *add item here*
- 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:

Expand Down
58 changes: 58 additions & 0 deletions base.cfg
@@ -0,0 +1,58 @@
[buildout]
show-picked-versions = true
package-name = collective.MockMailHost
package-extras = [test]
parts +=
test
coverage-sh
code-analysis
createcoverage
coverage
test-coverage
releaser
i18ndude
omelette
vscode

[vscode]
recipe = collective.recipe.vscode
eggs = ${instance:eggs}
autocomplete-use-omelette = True

[code-analysis]
recipe = plone.recipe.codeanalysis
directory = ${buildout:directory}/collective
return-status-codes = False

[omelette]
recipe = collective.recipe.omelette
eggs = ${instance:eggs}

[coverage]
recipe = zc.recipe.egg
eggs = coverage

[releaser]
recipe = zc.recipe.egg
eggs = zest.releaser

[test-coverage]
recipe = collective.recipe.template
input = inline:
#!/bin/bash
export TZ=UTC
${buildout:directory}/bin/coverage run bin/test $*
${buildout:directory}/bin/coverage html
${buildout:directory}/bin/coverage report -m --fail-under=80
# Fail (exit status 1) if coverage returns exit status 2 (this happens
# when test coverage is below 100%.
output = ${buildout:directory}/bin/test-coverage
mode = 755


[createcoverage]
recipe = zc.recipe.egg
eggs = createcoverage

[versions]
collective.MockMailHost =
22 changes: 1 addition & 21 deletions buildout.cfg
@@ -1,22 +1,2 @@
[buildout]
extends = http://dist.plone.org/release/5.1-latest/versions.cfg
parts =
test
coverage
releaser
develop = .

[test]
recipe = zc.recipe.testrunner
eggs = collective.mockmailhost[test]

[coverage]
recipe = zc.recipe.egg
eggs = coverage

[releaser]
recipe = zc.recipe.egg
eggs =
zest.releaser[recommended]
readme
docutils
extends = plone-6.0.x.cfg
8 changes: 7 additions & 1 deletion collective/MockMailHost/MockMailHost.py
Expand Up @@ -18,6 +18,8 @@ def __init__(self, id=''):

def reset(self):
self.messages = []
self.messages_from = []
self.messages_to = []
self.msg_types = []
self._p_changed = True

Expand All @@ -30,6 +32,8 @@ def _send(self, mfrom, mto, messageText, debug=False):
else:
message = messageText
self.messages.append(message)
self.messages_from.append(mfrom)
self.messages_to.append(mto)
self._p_changed = True

def send(self,
Expand All @@ -46,7 +50,9 @@ def send(self,
# messageText may be an MIMEText object, or something else.
# We onyl want to clean it up if it is a string.
if isinstance(messageText, (str, six.text_type)):
messageText = '\n'.join([x.strip() for x in messageText.split('\n')])
messageText = '\n'.join([
x.strip() for x in messageText.split('\n')
])

self.msg_types.append(msg_type)
super(MockMailHost, self).send(messageText, mto, mfrom,
Expand Down
1 change: 1 addition & 0 deletions collective/MockMailHost/__init__.py
@@ -1,5 +1,6 @@
from Products.CMFCore import utils as CMFCoreUtils


def initialize(context):
from . import MockMailHost
tools = (MockMailHost.MockMailHost, )
Expand Down
16 changes: 8 additions & 8 deletions collective/MockMailHost/testing.py
Expand Up @@ -10,24 +10,24 @@ class CollectiveMockMailHostLayer(PloneSandboxLayer):

def setUpZope(self, app, configurationContext):
import collective.MockMailHost

self.loadZCML(package=collective.MockMailHost)

def setUpPloneSite(self, portal):
applyProfile(portal, 'collective.MockMailHost:default')
applyProfile(portal, "collective.MockMailHost:default")


COLLECTIVE_MOCKMAILHOST_FIXTURE = CollectiveMockMailHostLayer()

COLLECTIVE_MOCKMAILHOST_INTEGRATION_TESTING = IntegrationTesting(
bases=(COLLECTIVE_MOCKMAILHOST_FIXTURE, ),
name='CollectiveMockMailHostLayer:Integration'
bases=(COLLECTIVE_MOCKMAILHOST_FIXTURE,),
name="CollectiveMockMailHostLayer:Integration",
)
COLLECTIVE_MOCKMAILHOST_FUNCTIONAL_TESTING = FunctionalTesting(
bases=(COLLECTIVE_MOCKMAILHOST_FIXTURE, ),
name='CollectiveMockMailHostLayer:Functional'
bases=(COLLECTIVE_MOCKMAILHOST_FIXTURE,),
name="CollectiveMockMailHostLayer:Functional",
)

optionflags = (
doctest.REPORT_ONLY_FIRST_FAILURE
| doctest.ELLIPSIS
| doctest.NORMALIZE_WHITESPACE
doctest.REPORT_ONLY_FIRST_FAILURE | doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE # noqa E501
)
50 changes: 44 additions & 6 deletions collective/MockMailHost/tests/SendEmail.txt
Expand Up @@ -23,13 +23,13 @@ Validate mailhost replacement
-----------------------------

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

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

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


Send email
Expand All @@ -45,13 +45,51 @@ Send email
>>> portal.MailHost.send(msg, to_, from_)
>>> len(portal.MailHost.messages)
1
>>> 'To: member@example.com' in portal.MailHost.messages[0]
>>> b'To: member@example.com' in portal.MailHost.messages[0]
True
>>> 'From: admin@example.com' in portal.MailHost.messages[0]
>>> b'From: admin@example.com' in portal.MailHost.messages[0]
True
>>> 'Dear Sir:' in portal.MailHost.messages[0]
>>> 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
13 changes: 12 additions & 1 deletion collective/MockMailHost/tests/testFunctional.py
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
from collective.MockMailHost.testing import COLLECTIVE_MOCKMAILHOST_FUNCTIONAL_TESTING
from collective.MockMailHost.testing import \
COLLECTIVE_MOCKMAILHOST_FUNCTIONAL_TESTING
from collective.MockMailHost.testing import optionflags
from plone.testing import layered
from plone.app.testing import applyProfile

import doctest
import unittest
Expand All @@ -11,6 +13,14 @@
'SendEmail.txt',
)


def setUp(self):
# this is a workaround, because the profile loaded in the layer is
# not present in the tests
portal = self.globs['layer']['portal']
applyProfile(portal, 'collective.MockMailHost:default')


def test_suite():
suite = unittest.TestSuite()
tests = [
Expand All @@ -19,6 +29,7 @@ def test_suite():
'tests/{0}'.format(test_file),
package='collective.MockMailHost',
optionflags=optionflags,
setUp=setUp,
),
layer=COLLECTIVE_MOCKMAILHOST_FUNCTIONAL_TESTING,
)
Expand Down
9 changes: 9 additions & 0 deletions plone-5.2.x.cfg
@@ -0,0 +1,9 @@
[buildout]
extends =
https://raw.githubusercontent.com/collective/buildout.plonetest/master/test-5.2.x.cfg
https://raw.github.com/collective/buildout.plonetest/master/qa.cfg
base.cfg
plone-series = 5.2

[versions]
bleach = 3.3.1
5 changes: 5 additions & 0 deletions plone-6.0.x.cfg
@@ -0,0 +1,5 @@
[buildout]
extends =
https://raw.githubusercontent.com/collective/buildout.plonetest/master/test-6.0.x.cfg
https://raw.githubusercontent.com/collective/buildout.plonetest/master/qa.cfg
base.cfg
1 change: 1 addition & 0 deletions requirements-5.2.x.txt
@@ -0,0 +1 @@
-r https://dist.plone.org/release/5.2-latest/requirements.txt
1 change: 1 addition & 0 deletions requirements-6.0.x.txt
@@ -0,0 +1 @@
-r http://dist.plone.org/release/6.0-latest/requirements.txt
3 changes: 1 addition & 2 deletions requirements.txt
@@ -1,2 +1 @@
setuptools==33.1.1
zc.buildout==2.9.5
-r requirements-6.0.x.txt

0 comments on commit b17f02c

Please sign in to comment.