1
# Copyright (C) 2014-2015 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 `member-moderation` and `nonmember-moderation` rules."""
27
from mailman.app.lifecycle import create_list
28
from mailman.interfaces.member import MemberRole
29
from mailman.interfaces.usermanager import IUserManager
30
from mailman.rules import moderation
31
from mailman.testing.helpers import specialized_message_from_string as mfs
32
from mailman.testing.layers import ConfigLayer
33
from zope.component import getUtility
37
class TestModeration(unittest.TestCase):
38
"""Test the approved handler."""
43
self._mlist = create_list('test@example.com')
45
def test_member_and_nonmember(self):
46
user_manager = getUtility(IUserManager)
47
anne = user_manager.create_address('anne@example.com')
48
user_manager.create_address('bill@example.com')
49
self._mlist.subscribe(anne, MemberRole.member)
50
rule = moderation.NonmemberModeration()
52
From: anne@example.com
53
Sender: bill@example.com
55
Subject: A test message
61
# Both Anne and Bill are in the message's senders list.
62
self.assertIn('anne@example.com', msg.senders)
63
self.assertIn('bill@example.com', msg.senders)
64
# The NonmemberModeration rule should *not* hit, because even though
65
# Bill is in the list of senders he is not a member of the mailing
66
# list. Anne is also in the list of senders and she *is* a member, so
67
# she takes precedence.
68
result = rule.check(self._mlist, msg, {})
69
self.assertFalse(result, 'NonmemberModeration rule should not hit')
70
# After the rule runs, Bill becomes a non-member.
71
bill_member = self._mlist.nonmembers.get_member('bill@example.com')
72
self.assertIsNotNone(bill_member)
73
# Bill is not a member.
74
bill_member = self._mlist.members.get_member('bill@example.com')
75
self.assertIsNone(bill_member)