~sambuddhabasu1/mailman/fix_mailman_run_error

« back to all changes in this revision

Viewing changes to src/mailman/rules/tests/test_moderation.py

  • Committer: Barry Warsaw
  • Date: 2015-03-03 02:34:09 UTC
  • mfrom: (7299.1.1 mailman_trunk)
  • Revision ID: barry@list.org-20150303023409-g7qqejbizzouc85k
Doc fixes given by Abhilash Raj.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2014-2015 by the Free Software Foundation, Inc.
 
2
#
 
3
# This file is part of GNU Mailman.
 
4
#
 
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)
 
8
# any later version.
 
9
#
 
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
 
13
# more details.
 
14
#
 
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/>.
 
17
 
 
18
"""Test the `member-moderation` and `nonmember-moderation` rules."""
 
19
 
 
20
__all__ = [
 
21
    'TestModeration',
 
22
    ]
 
23
 
 
24
 
 
25
import unittest
 
26
 
 
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
 
34
 
 
35
 
 
36
 
 
37
class TestModeration(unittest.TestCase):
 
38
    """Test the approved handler."""
 
39
 
 
40
    layer = ConfigLayer
 
41
 
 
42
    def setUp(self):
 
43
        self._mlist = create_list('test@example.com')
 
44
 
 
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()
 
51
        msg = mfs("""\
 
52
From: anne@example.com
 
53
Sender: bill@example.com
 
54
To: test@example.com
 
55
Subject: A test message
 
56
Message-ID: <ant>
 
57
MIME-Version: 1.0
 
58
 
 
59
A message body.
 
60
""")
 
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)