1 # Copyright (C) 2012-2016 by the Free Software Foundation, Inc.
3 # This file is part of GNU Mailman.
5 # GNU Mailman is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option)
10 # GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 # You should have received a copy of the GNU General Public License along with
16 # GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18 """Test the incoming queue runner."""
22 from mailman
.app
.lifecycle
import create_list
23 from mailman
.chains
.base
import TerminalChainBase
24 from mailman
.config
import config
25 from mailman
.runners
.incoming
import IncomingRunner
26 from mailman
.testing
.helpers
import (
27 get_queue_messages
, make_testable_runner
,
28 specialized_message_from_string
as mfs
)
29 from mailman
.testing
.layers
import ConfigLayer
32 class Chain(TerminalChainBase
):
34 description
= 'a test chain'
36 def __init__(self
, marker
):
39 def _process(self
, mlist
, msg
, msgdata
):
40 msgdata
['marker'] = self
._marker
41 config
.switchboards
['out'].enqueue(msg
, msgdata
)
44 class TestIncoming(unittest
.TestCase
):
45 """Test the incoming queue runner."""
50 self
._mlist
= create_list('test@example.com')
51 self
._mlist
.posting_chain
= 'test posting'
52 self
._mlist
.owner_chain
= 'test owner'
53 config
.chains
['test posting'] = Chain('posting')
54 self
.addCleanup(config
.chains
.pop
, 'test posting')
55 config
.chains
['test owner'] = Chain('owner')
56 self
.addCleanup(config
.chains
.pop
, 'test owner')
57 self
._in
= make_testable_runner(IncomingRunner
, 'in')
59 From: anne@example.com
64 def test_posting(self
):
65 # A message posted to the list goes through the posting chain.
66 msgdata
= dict(listid
='test.example.com')
67 config
.switchboards
['in'].enqueue(self
._msg
, msgdata
)
69 items
= get_queue_messages('out', expected_count
=1)
70 self
.assertEqual(items
[0].msgdata
.get('marker'), 'posting')
73 # A message posted to the list goes through the posting chain.
74 msgdata
= dict(listid
='test.example.com',
76 config
.switchboards
['in'].enqueue(self
._msg
, msgdata
)
78 items
= get_queue_messages('out', expected_count
=1)
79 self
.assertEqual(items
[0].msgdata
.get('marker'), 'owner')