~andrea-crotti-0/mailman/test_doc

« back to all changes in this revision

Viewing changes to src/mailman/core/tests/test_pipelines.py

  • Committer: Barry Warsaw
  • Date: 2012-03-17 16:54:26 UTC
  • mfrom: (7112.2.2 nopipermail)
  • Revision ID: barry@list.org-20120317165426-gh7r1owr9n8p0gvh
Merge the Pipermail eradication branch.  The scrubber is also removed.

 * Configuration variable `[mailman]filtered_messages_are_preservable`
   controls whether messages which have their top-level `Content-Type`
   filtered out can be preserved in the `bad` queue by list owners.
 * Configuration section `[scrubber]` removed, as is the scrubber handler.
   This handler was essentially incompatible with Mailman 3 since it required
   coordination with Pipermail to store attachments on disk.

 * Schema additions:
   - mailinglist.filter_action

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
import unittest
28
28
 
 
29
from zope.interface import implements
29
30
 
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 (
 
38
    LogFileMark,
 
39
    get_queue_messages,
33
40
    reset_the_world,
34
41
    specialized_message_from_string as mfs)
35
42
from mailman.testing.layers import ConfigLayer
36
43
 
37
44
 
38
45
 
 
46
class DiscardingHandler:
 
47
    implements(IHandler)
 
48
    name = 'discarding'
 
49
 
 
50
    def process(self, mlist, msg, msgdata):
 
51
        raise DiscardMessage('by test handler')
 
52
 
 
53
 
 
54
class RejectHandler:
 
55
    implements(IHandler)
 
56
    name = 'rejecting'
 
57
 
 
58
    def process(self, mlist, msg, msgdata):
 
59
        raise RejectMessage('by test handler')
 
60
 
 
61
 
 
62
class DiscardingPipeline:
 
63
    implements(IPipeline)
 
64
    name = 'test-discarding'
 
65
    description = 'Discarding test pipeline'
 
66
 
 
67
    def __iter__(self):
 
68
        yield DiscardingHandler()
 
69
 
 
70
 
 
71
class RejectingPipeline:
 
72
    implements(IPipeline)
 
73
    name = 'test-rejecting'
 
74
    description = 'Rejectinging test pipeline'
 
75
 
 
76
    def __iter__(self):
 
77
        yield RejectHandler()
 
78
 
 
79
 
 
80
 
39
81
class TestBuiltinPipeline(unittest.TestCase):
40
82
    """Test various aspects of the built-in postings pipeline."""
41
83
 
43
85
 
44
86
    def setUp(self):
45
87
        self._mlist = create_list('test@example.com')
46
 
 
47
 
    def tearDown(self):
48
 
        reset_the_world()
49
 
 
50
 
    def test_rfc2369_headers(self):
51
 
        # Ensure that RFC 2369 List-* headers are added.
52
 
        msg = mfs("""\
 
88
        config.pipelines['test-discarding'] = DiscardingPipeline()
 
89
        config.pipelines['test-rejecting'] = RejectingPipeline()
 
90
        self._msg = mfs("""\
53
91
From: Anne Person <anne@example.org>
54
92
To: test@example.com
55
93
Subject: a test
 
94
Message-ID: <ant>
56
95
 
57
96
testing
58
97
""")
 
98
 
 
99
    def tearDown(self):
 
100
        reset_the_world()
 
101
        del config.pipelines['test-discarding']
 
102
        del config.pipelines['test-rejecting']
 
103
 
 
104
    def test_rfc2369_headers(self):
 
105
        # Ensure that RFC 2369 List-* headers are added.
59
106
        msgdata = {}
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>')
 
111
 
 
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'))
 
121
 
 
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
 
132
        # virgin queue.
 
133
        messages = get_queue_messages('virgin')
 
134
        self.assertEqual(len(messages), 1)
 
135
        self.assertEqual(str(messages[0].msg['subject']), 'a test')