1 # Copyright (C) 2012-2014 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 owner chain."""
20 from __future__
import absolute_import
, print_function
, unicode_literals
30 from mailman
.app
.lifecycle
import create_list
31 from mailman
.chains
.owner
import BuiltInOwnerChain
32 from mailman
.core
.chains
import process
33 from mailman
.interfaces
.chain
import AcceptOwnerEvent
34 from mailman
.testing
.helpers
import (
37 specialized_message_from_string
as mfs
)
38 from mailman
.testing
.layers
import ConfigLayer
42 class TestOwnerChain(unittest
.TestCase
):
43 """Test the owner chain."""
48 self
._mlist
= create_list('test@example.com')
50 From: anne@example.com
56 def test_owner_pipeline(self
):
57 # Messages processed through the default owners chain end up in the
58 # pipeline queue, and an event gets sent.
60 # This event subscriber records the event that occurs when the message
61 # is processed by the owner chain.
63 def catch_event(event
):
64 if isinstance(event
, AcceptOwnerEvent
):
66 with
event_subscribers(catch_event
):
67 process(self
._mlist
, self
._msg
, {}, 'default-owner-chain')
68 self
.assertEqual(len(events
), 1)
70 self
.assertTrue(isinstance(event
, AcceptOwnerEvent
))
71 self
.assertEqual(event
.mlist
, self
._mlist
)
72 self
.assertEqual(event
.msg
['message-id'], '<ant>')
73 self
.assertTrue(isinstance(event
.chain
, BuiltInOwnerChain
))
74 messages
= get_queue_messages('pipeline')
75 self
.assertEqual(len(messages
), 1)
76 message
= messages
[0].msg
77 self
.assertEqual(message
['message-id'], '<ant>')