29
from zope.interface import implements
30
31
from mailman.app.lifecycle import create_list
32
from mailman.config import config
33
from mailman.core.errors import DiscardMessage, RejectMessage
31
34
from mailman.core.pipelines import process
35
from mailman.interfaces.handler import IHandler
36
from mailman.interfaces.pipeline import IPipeline
32
37
from mailman.testing.helpers import (
34
41
specialized_message_from_string as mfs)
35
42
from mailman.testing.layers import ConfigLayer
46
class DiscardingHandler:
50
def process(self, mlist, msg, msgdata):
51
raise DiscardMessage('by test handler')
58
def process(self, mlist, msg, msgdata):
59
raise RejectMessage('by test handler')
62
class DiscardingPipeline:
64
name = 'test-discarding'
65
description = 'Discarding test pipeline'
68
yield DiscardingHandler()
71
class RejectingPipeline:
73
name = 'test-rejecting'
74
description = 'Rejectinging test pipeline'
39
81
class TestBuiltinPipeline(unittest.TestCase):
40
82
"""Test various aspects of the built-in postings pipeline."""
45
87
self._mlist = create_list('test@example.com')
50
def test_rfc2369_headers(self):
51
# Ensure that RFC 2369 List-* headers are added.
88
config.pipelines['test-discarding'] = DiscardingPipeline()
89
config.pipelines['test-rejecting'] = RejectingPipeline()
53
91
From: Anne Person <anne@example.org>
54
92
To: test@example.com
101
del config.pipelines['test-discarding']
102
del config.pipelines['test-rejecting']
104
def test_rfc2369_headers(self):
105
# Ensure that RFC 2369 List-* headers are added.
60
process(self._mlist, msg, msgdata,
107
process(self._mlist, self._msg, msgdata,
61
108
pipeline_name='default-posting-pipeline')
62
self.assertEqual(msg['list-id'], '<test.example.com>')
63
self.assertEqual(msg['list-post'], '<mailto:test@example.com>')
109
self.assertEqual(self._msg['list-id'], '<test.example.com>')
110
self.assertEqual(self._msg['list-post'], '<mailto:test@example.com>')
112
def test_discarding_pipeline(self):
113
# If a handler in the pipeline raises DiscardMessage, the message will
114
# be thrown away, but with a log message.
115
mark = LogFileMark('mailman.vette')
116
process(self._mlist, self._msg, {}, 'test-discarding')
117
line = mark.readline()[:-1]
118
self.assertTrue(line.endswith(
119
'<ant> discarded by "test-discarding" pipeline handler '
120
'"discarding": by test handler'))
122
def test_rejecting_pipeline(self):
123
# If a handler in the pipeline raises DiscardMessage, the message will
124
# be thrown away, but with a log message.
125
mark = LogFileMark('mailman.vette')
126
process(self._mlist, self._msg, {}, 'test-rejecting')
127
line = mark.readline()[:-1]
128
self.assertTrue(line.endswith(
129
'<ant> rejected by "test-rejecting" pipeline handler '
130
'"rejecting": by test handler'))
131
# In the rejection case, the original message will also be in the
133
messages = get_queue_messages('virgin')
134
self.assertEqual(len(messages), 1)
135
self.assertEqual(str(messages[0].msg['subject']), 'a test')