summaryrefslogtreecommitdiff
path: root/src/mailman/chains/tests/test_headers.py
diff options
context:
space:
mode:
authorBarry Warsaw2017-07-26 23:24:18 +0000
committerBarry Warsaw2017-07-26 23:24:18 +0000
commitade94e8f833a9472ba9be52a08f4e2f381e7a212 (patch)
tree5fba570b0c6f4c0919009cb6f455c18bc732192a /src/mailman/chains/tests/test_headers.py
parent02826321d0430d7ffc1f674eeff4221941689ef7 (diff)
parentbea94cb9538a55b1376afd42c2ce751efce62cfe (diff)
downloadmailman-ade94e8f833a9472ba9be52a08f4e2f381e7a212.tar.gz
mailman-ade94e8f833a9472ba9be52a08f4e2f381e7a212.tar.zst
mailman-ade94e8f833a9472ba9be52a08f4e2f381e7a212.zip
Diffstat (limited to 'src/mailman/chains/tests/test_headers.py')
-rw-r--r--src/mailman/chains/tests/test_headers.py55
1 files changed, 54 insertions, 1 deletions
diff --git a/src/mailman/chains/tests/test_headers.py b/src/mailman/chains/tests/test_headers.py
index cd4c932cc..2aae503b2 100644
--- a/src/mailman/chains/tests/test_headers.py
+++ b/src/mailman/chains/tests/test_headers.py
@@ -25,7 +25,8 @@ from mailman.chains.headers import HeaderMatchRule, make_link
from mailman.config import config
from mailman.core.chains import process
from mailman.email.message import Message
-from mailman.interfaces.chain import DiscardEvent, HoldEvent, LinkAction
+from mailman.interfaces.chain import (
+ DiscardEvent, HoldEvent, LinkAction, RejectEvent)
from mailman.interfaces.mailinglist import IHeaderMatchList
from mailman.testing.helpers import (
LogFileMark, configuration, event_subscribers,
@@ -343,3 +344,55 @@ A message body.
# ...and are actually the identical objects.
for link1, link2 in zip(links_1, links_2):
self.assertIs(link1.rule, link2.rule)
+
+ def test_hold_returns_reason(self):
+ # Test that a match with hold action returns a reason
+ msg = mfs("""\
+From: anne@example.com
+To: test@example.com
+Subject: Bad subject
+Message-ID: <ant>
+
+body
+
+""")
+ msgdata = {}
+ header_matches = IHeaderMatchList(self._mlist)
+ header_matches.append('Subject', 'Bad', 'hold')
+ # This event subscriber records the event that occurs when the message
+ # is processed by the owner chain.
+ events = []
+ with event_subscribers(events.append):
+ process(self._mlist, msg, msgdata, start_chain='header-match')
+ self.assertEqual(len(events), 1)
+ event = events[0]
+ self.assertIsInstance(event, HoldEvent)
+ self.assertEqual(msgdata['moderation_reasons'],
+ [('Header "{}" matched a header rule',
+ 'Bad subject')])
+
+ def test_reject_returns_reason(self):
+ # Test that a match with reject action returns a reason
+ msg = mfs("""\
+From: anne@example.com
+To: test@example.com
+Subject: Bad subject
+Message-ID: <ant>
+
+body
+
+""")
+ msgdata = {}
+ header_matches = IHeaderMatchList(self._mlist)
+ header_matches.append('Subject', 'Bad', 'reject')
+ # This event subscriber records the event that occurs when the message
+ # is processed by the owner chain.
+ events = []
+ with event_subscribers(events.append):
+ process(self._mlist, msg, msgdata, start_chain='header-match')
+ self.assertEqual(len(events), 1)
+ event = events[0]
+ self.assertIsInstance(event, RejectEvent)
+ self.assertEqual(msgdata['moderation_reasons'],
+ [('Header "{}" matched a header rule',
+ 'Bad subject')])