summaryrefslogtreecommitdiff
path: root/src/mailman/chains/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/chains/tests')
-rw-r--r--src/mailman/chains/tests/test_accept.py8
-rw-r--r--src/mailman/chains/tests/test_base.py7
-rw-r--r--src/mailman/chains/tests/test_headers.py17
-rw-r--r--src/mailman/chains/tests/test_hold.py24
-rw-r--r--src/mailman/chains/tests/test_owner.py17
-rw-r--r--src/mailman/chains/tests/test_reject.py12
6 files changed, 20 insertions, 65 deletions
diff --git a/src/mailman/chains/tests/test_accept.py b/src/mailman/chains/tests/test_accept.py
index 62370021d..661ad2146 100644
--- a/src/mailman/chains/tests/test_accept.py
+++ b/src/mailman/chains/tests/test_accept.py
@@ -17,11 +17,6 @@
"""Test the accept chain."""
-__all__ = [
- 'TestAccept',
- ]
-
-
import unittest
from mailman.app.lifecycle import create_list
@@ -47,7 +42,6 @@ class MyChain:
yield Link('truth', LinkAction.jump, 'accept')
-
class TestAccept(unittest.TestCase):
"""Test the accept chain."""
@@ -66,7 +60,7 @@ Subject: Ignore
config.chains['mine'] = MyChain()
self.addCleanup(config.chains.pop, 'mine')
hits = None
- def handler(event):
+ def handler(event): # flake8: noqa
nonlocal hits
if isinstance(event, AcceptEvent):
hits = event.msg['x-mailman-rule-hits']
diff --git a/src/mailman/chains/tests/test_base.py b/src/mailman/chains/tests/test_base.py
index 86a09678d..a9c07c7ab 100644
--- a/src/mailman/chains/tests/test_base.py
+++ b/src/mailman/chains/tests/test_base.py
@@ -17,12 +17,6 @@
"""Test the base chain stuff."""
-__all__ = [
- 'TestMiscellaneous',
- 'TestTerminalChainBase',
- ]
-
-
import unittest
from mailman.chains.accept import AcceptChain
@@ -37,7 +31,6 @@ class SimpleChain(TerminalChainBase):
pass
-
class TestMiscellaneous(unittest.TestCase):
"""Reach additional code coverage."""
diff --git a/src/mailman/chains/tests/test_headers.py b/src/mailman/chains/tests/test_headers.py
index 11b00f7ba..b3ccdf675 100644
--- a/src/mailman/chains/tests/test_headers.py
+++ b/src/mailman/chains/tests/test_headers.py
@@ -17,11 +17,6 @@
"""Test the header chain."""
-__all__ = [
- 'TestHeaderChain',
- ]
-
-
import unittest
from mailman.app.lifecycle import create_list
@@ -173,7 +168,7 @@ class TestHeaderChain(unittest.TestCase):
[('foo', 'a+', LinkAction.jump, 'reject'),
('bar', 'b+', LinkAction.jump, 'discard'),
('baz', 'z+', LinkAction.jump, 'accept'),
- ])
+ ]) # flake8: noqa
@configuration('antispam', header_checks="""
Foo: foo
@@ -202,7 +197,7 @@ A message body.
self.assertEqual(len(events), 1)
event = events[0]
# Site-wide wants to hold the message, the list wants to accept it.
- self.assertTrue(isinstance(event, HoldEvent))
+ self.assertIsInstance(event, HoldEvent)
self.assertEqual(event.chain, config.chains['hold'])
def test_no_action_defaults_to_site_wide_action(self):
@@ -223,7 +218,7 @@ A message body.
# This event subscriber records the event that occurs when the message
# is processed by the owner chain, which holds its for approval.
events = []
- def record_holds(event):
+ def record_holds(event): # flake8: noqa
if not isinstance(event, HoldEvent):
return
events.append(event)
@@ -231,7 +226,7 @@ A message body.
# Set the site-wide antispam action to hold the message.
with configuration('antispam', header_checks="""
Spam: [*]{3,}
- """, jump_chain='hold'):
+ """, jump_chain='hold'): # flake8: noqa
process(self._mlist, msg, {}, start_chain='header-match')
self.assertEqual(len(events), 1)
event = events[0]
@@ -240,7 +235,7 @@ A message body.
self.assertEqual(event.mlist, self._mlist)
self.assertEqual(event.msg, msg)
events = []
- def record_discards(event):
+ def record_discards(event): # flake8: noqa
if not isinstance(event, DiscardEvent):
return
events.append(event)
@@ -249,7 +244,7 @@ A message body.
msg.replace_header('Message-Id', '<bee>')
with configuration('antispam', header_checks="""
Spam: [*]{3,}
- """, jump_chain='discard'):
+ """, jump_chain='discard'): # flake8: noqa
process(self._mlist, msg, {}, start_chain='header-match')
self.assertEqual(len(events), 1)
event = events[0]
diff --git a/src/mailman/chains/tests/test_hold.py b/src/mailman/chains/tests/test_hold.py
index c7b676f8b..0957fe880 100644
--- a/src/mailman/chains/tests/test_hold.py
+++ b/src/mailman/chains/tests/test_hold.py
@@ -17,12 +17,6 @@
"""Additional tests for the hold chain."""
-__all__ = [
- 'TestAutorespond',
- 'TestHoldChain',
- ]
-
-
import unittest
from email import message_from_bytes as mfb
@@ -40,16 +34,14 @@ from pkg_resources import resource_filename
from zope.component import getUtility
-
class TestAutorespond(unittest.TestCase):
"""Test autorespond_to_sender()"""
layer = ConfigLayer
+ maxDiff = None
def setUp(self):
self._mlist = create_list('test@example.com')
- # Let assertMultiLineEqual work without bounds.
- self.maxDiff = None
@configuration('mta', max_autoresponses_per_day=1)
def test_max_autoresponses_per_day(self):
@@ -70,9 +62,9 @@ class TestAutorespond(unittest.TestCase):
self.assertEqual(len(messages), 1)
# Remove the variable headers.
message = messages[0].msg
- self.assertTrue('message-id' in message)
+ self.assertIn('message-id', message)
del message['message-id']
- self.assertTrue('date' in message)
+ self.assertIn('date', message)
del message['date']
self.assertMultiLineEqual(messages[0].msg.as_string(), """\
MIME-Version: 1.0
@@ -95,7 +87,6 @@ If you believe this message is in error, or if you have any questions,
please contact the list owner at test-owner@example.com.""")
-
class TestHoldChain(unittest.TestCase):
"""Test the hold chain code."""
@@ -120,8 +111,7 @@ A message body.
])
logfile = LogFileMark('mailman.vette')
process_chain(self._mlist, msg, msgdata, start_chain='hold')
- messages = get_queue_messages('virgin')
- self.assertEqual(len(messages), 2)
+ messages = get_queue_messages('virgin', expected_count=2)
payloads = {}
for item in messages:
if item.msg['to'] == 'test-owner@example.com':
@@ -150,8 +140,7 @@ A message body.
process_chain(self._mlist, msg, {}, start_chain='hold')
# The postauth.txt message is now in the virgin queue awaiting
# delivery to the moderators.
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 1)
+ items = get_queue_messages('virgin', expected_count=1)
msgdata = items[0].msgdata
self.assertTrue(msgdata['tomoderators'])
self.assertEqual(msgdata['recipients'], {'test-owner@example.com'})
@@ -180,11 +169,10 @@ A message body.
""")
process_chain(self._mlist, msg, {}, start_chain='hold')
process_chain(mlist2, msg, {}, start_chain='hold')
- items = get_queue_messages('virgin')
# There are four items in the virgin queue. Two of them are for the
# list owners who need to moderate the held message, and the other is
# for anne telling her that her message was held for approval.
- self.assertEqual(len(items), 4)
+ items = get_queue_messages('virgin', expected_count=4)
anne_froms = set()
owner_tos = set()
for item in items:
diff --git a/src/mailman/chains/tests/test_owner.py b/src/mailman/chains/tests/test_owner.py
index cf9c06f94..06ba10582 100644
--- a/src/mailman/chains/tests/test_owner.py
+++ b/src/mailman/chains/tests/test_owner.py
@@ -17,11 +17,6 @@
"""Test the owner chain."""
-__all__ = [
- 'TestOwnerChain',
- ]
-
-
import unittest
from mailman.app.lifecycle import create_list
@@ -34,7 +29,6 @@ from mailman.testing.helpers import (
from mailman.testing.layers import ConfigLayer
-
class TestOwnerChain(unittest.TestCase):
"""Test the owner chain."""
@@ -56,18 +50,17 @@ Message-ID: <ant>
# This event subscriber records the event that occurs when the message
# is processed by the owner chain.
events = []
- def catch_event(event):
+ def catch_event(event): # flake8: noqa
if isinstance(event, AcceptOwnerEvent):
events.append(event)
with event_subscribers(catch_event):
process(self._mlist, self._msg, {}, 'default-owner-chain')
self.assertEqual(len(events), 1)
event = events[0]
- self.assertTrue(isinstance(event, AcceptOwnerEvent))
+ self.assertIsInstance(event, AcceptOwnerEvent)
self.assertEqual(event.mlist, self._mlist)
self.assertEqual(event.msg['message-id'], '<ant>')
- self.assertTrue(isinstance(event.chain, BuiltInOwnerChain))
- messages = get_queue_messages('pipeline')
- self.assertEqual(len(messages), 1)
- message = messages[0].msg
+ self.assertIsInstance(event.chain, BuiltInOwnerChain)
+ items = get_queue_messages('pipeline', expected_count=1)
+ message = items[0].msg
self.assertEqual(message['message-id'], '<ant>')
diff --git a/src/mailman/chains/tests/test_reject.py b/src/mailman/chains/tests/test_reject.py
index ae83d63bf..a645a849c 100644
--- a/src/mailman/chains/tests/test_reject.py
+++ b/src/mailman/chains/tests/test_reject.py
@@ -17,11 +17,6 @@
"""Test the reject chain."""
-__all__ = [
- 'TestReject',
- ]
-
-
import unittest
from mailman.app.lifecycle import create_list
@@ -31,7 +26,6 @@ from mailman.testing.helpers import (
from mailman.testing.layers import ConfigLayer
-
class TestReject(unittest.TestCase):
"""Test the reject chain."""
@@ -53,8 +47,7 @@ Subject: Ignore
'TEST-REASON-2',
])
process_chain(self._mlist, self._msg, msgdata, start_chain='reject')
- bounces = get_queue_messages('virgin')
- self.assertEqual(len(bounces), 1)
+ bounces = get_queue_messages('virgin', expected_count=1)
payload = bounces[0].msg.get_payload(0).as_string()
self.assertIn('TEST-REASON-1', payload)
self.assertIn('TEST-REASON-2', payload)
@@ -62,7 +55,6 @@ Subject: Ignore
def test_no_reason(self):
# There may be no moderation reasons.
process_chain(self._mlist, self._msg, {}, start_chain='reject')
- bounces = get_queue_messages('virgin')
- self.assertEqual(len(bounces), 1)
+ bounces = get_queue_messages('virgin', expected_count=1)
payload = bounces[0].msg.get_payload(0).as_string()
self.assertIn('No bounce details are available', payload)