1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# Copyright (C) 2012-2017 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
# GNU Mailman is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
"""Test the pipeline runner."""
import unittest
from mailman.app.lifecycle import create_list
from mailman.config import config
from mailman.interfaces.handler import IHandler
from mailman.interfaces.pipeline import IPipeline
from mailman.runners.pipeline import PipelineRunner
from mailman.testing.helpers import (
make_testable_runner, specialized_message_from_string as mfs)
from mailman.testing.layers import ConfigLayer
from zope.interface import implementer
@implementer(IHandler)
class MyTestHandler:
"""See `IHandler`."""
name = 'test handler'
description = 'A test handler'
def __init__(self, marker, test):
self._marker = marker
self._test = test
def process(self, mlist, msg, msgdata):
self._test.mark(self._marker)
@implementer(IPipeline)
class MyTestPipeline:
name = 'test'
description = 'a test pipeline'
def __init__(self, marker, test):
self._marker = marker
self._test = test
def __iter__(self):
yield MyTestHandler(self._marker, self._test)
class TestPipelineRunner(unittest.TestCase):
"""Test the pipeline runner."""
layer = ConfigLayer
def setUp(self):
self._mlist = create_list('test@example.com')
self._mlist.posting_pipeline = 'test posting'
self._mlist.owner_pipeline = 'test owner'
config.pipelines['test posting'] = MyTestPipeline('posting', self)
config.pipelines['test owner'] = MyTestPipeline('owner', self)
self._pipeline = make_testable_runner(PipelineRunner, 'pipeline')
self._markers = []
self._msg = mfs("""\
From: anne@example.com
To: test@example.com
""")
def tearDown(self):
del config.pipelines['test posting']
del config.pipelines['test owner']
def mark(self, marker):
# Record a marker seen by a handler.
self._markers.append(marker)
def test_posting(self):
# A message accepted for posting gets processed through the posting
# pipeline.
msgdata = dict(listid='test.example.com')
config.switchboards['pipeline'].enqueue(self._msg, msgdata)
self._pipeline.run()
self.assertEqual(len(self._markers), 1)
self.assertEqual(self._markers[0], 'posting')
def test_owner(self):
# A message accepted for posting to a list's owners gets processed
# through the owner pipeline.
msgdata = dict(listid='test.example.com',
to_owner=True)
config.switchboards['pipeline'].enqueue(self._msg, msgdata)
self._pipeline.run()
self.assertEqual(len(self._markers), 1)
self.assertEqual(self._markers[0], 'owner')
|