~abompard/mailman/moderation_reasons

« back to all changes in this revision

Viewing changes to src/mailman/chains/tests/test_hold.py

  • Committer: Aurelien Bompard
  • Date: 2014-04-17 20:16:14 UTC
  • Revision ID: abompard@redhat.com-20140417201614-lu003t6awfju7nfo
Use real reasons when a message is held

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
from zope.component import getUtility
30
30
 
31
31
from mailman.app.lifecycle import create_list
32
 
from mailman.chains.hold import autorespond_to_sender
 
32
from mailman.chains.hold import autorespond_to_sender, HoldChain
 
33
from mailman.email.message import Message
33
34
from mailman.interfaces.autorespond import IAutoResponseSet, Response
34
35
from mailman.interfaces.usermanager import IUserManager
35
 
from mailman.testing.helpers import configuration, get_queue_messages
 
36
from mailman.testing.helpers import (
 
37
    configuration,
 
38
    get_queue_messages,
 
39
    specialized_message_from_string as mfs)
36
40
from mailman.testing.layers import ConfigLayer
37
41
 
38
42
 
89
93
 
90
94
If you believe this message is in error, or if you have any questions,
91
95
please contact the list owner at test-owner@example.com.""")
 
96
 
 
97
 
 
98
 
 
99
class TestHoldChain(unittest.TestCase):
 
100
    """Test the hold chain code."""
 
101
 
 
102
    layer = ConfigLayer
 
103
 
 
104
    def setUp(self):
 
105
        self._mlist = create_list('test@example.com')
 
106
 
 
107
    def test_hold_chain(self):
 
108
        msg = mfs("""\
 
109
From: anne@example.com
 
110
To: test@example.com
 
111
Subject: A message
 
112
Message-ID: <ant>
 
113
MIME-Version: 1.0
 
114
 
 
115
A message body.
 
116
""")
 
117
        metadata = {
 
118
            "moderation_reasons": [
 
119
                "TEST-REASON-1",
 
120
                "TEST-REASON-2",
 
121
            ],
 
122
        }
 
123
        chain = HoldChain()
 
124
        chain._process(self._mlist, msg, metadata)
 
125
        messages = get_queue_messages('virgin')
 
126
        self.assertEqual(len(messages), 2)
 
127
        sent_msgs = {}
 
128
        for msg_bag in messages:
 
129
            if msg_bag.msg["To"] == "test-owner@example.com":
 
130
                sent_msgs["owner"] = msg_bag.msg
 
131
            elif msg_bag.msg["To"] == "anne@example.com":
 
132
                sent_msgs["sender"] = msg_bag.msg
 
133
            else:
 
134
                self.fail("Unexpected message: %s" % msg_bag.msg)
 
135
        self.assertTrue("TEST-REASON-1, TEST-REASON-2" in
 
136
                        sent_msgs["owner"].as_string())
 
137
        self.assertTrue("    TEST-REASON-1" in
 
138
                        sent_msgs["sender"].as_string())
 
139
        self.assertTrue("    TEST-REASON-2" in
 
140
                        sent_msgs["sender"].as_string())