~ulrith/mailman/russian-2.1.20

1249 by Mark Sapiro
Updated unit tests for current Mailman so all tests should pass.
1
# Copyright (C) 2001-2010 by the Free Software Foundation, Inc.
1 by
This commit was manufactured by cvs2svn to create branch
2
#
3
# This program is free software; you can redistribute it and/or
4
# modify it under the terms of the GNU General Public License
5
# as published by the Free Software Foundation; either version 2
6
# of the License, or (at your option) any later version.
7
# 
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
# 
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software 
749 by tkikuchi
FSF office has moved to 51 Franklin Street.
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1 by
This commit was manufactured by cvs2svn to create branch
16
17
"""Unit tests for the various Message class methods.
18
"""
19
1249 by Mark Sapiro
Updated unit tests for current Mailman so all tests should pass.
20
import sys
1 by
This commit was manufactured by cvs2svn to create branch
21
import unittest
22
import email
1249 by Mark Sapiro
Updated unit tests for current Mailman so all tests should pass.
23
try:
24
    from Mailman import __init__
25
except ImportError:
26
    import paths
1 by
This commit was manufactured by cvs2svn to create branch
27
28
from Mailman import Message
29
from Mailman import Version
30
from Mailman import Errors
31
32
from EmailBase import EmailBase
33
34
35

1249 by Mark Sapiro
Updated unit tests for current Mailman so all tests should pass.
36
class TestSentMessage1(EmailBase):
1 by
This commit was manufactured by cvs2svn to create branch
37
    def test_user_notification(self):
38
        eq = self.assertEqual
39
        unless = self.failUnless
40
        msg = Message.UserNotification(
41
            'aperson@dom.ain',
42
            '_xtest@dom.ain',
43
            'Your Test List',
44
            'About your test list')
45
        msg.send(self._mlist)
46
        qmsg = email.message_from_string(self._readmsg())
47
        eq(qmsg['subject'], 'Your Test List')
48
        eq(qmsg['from'], '_xtest@dom.ain')
49
        eq(qmsg['to'], 'aperson@dom.ain')
50
        # The Message-ID: header has some time-variant information
51
        msgid = qmsg['message-id']
52
        unless(msgid.startswith('<mailman.'))
53
        unless(msgid.endswith('._xtest@dom.ain>'))
1249 by Mark Sapiro
Updated unit tests for current Mailman so all tests should pass.
54
        eq(qmsg['sender'], '_xtest-bounces@dom.ain')
55
        eq(qmsg['errors-to'], '_xtest-bounces@dom.ain')
1 by
This commit was manufactured by cvs2svn to create branch
56
        eq(qmsg['x-beenthere'], '_xtest@dom.ain')
57
        eq(qmsg['x-mailman-version'], Version.VERSION)
58
        eq(qmsg['precedence'], 'bulk')
59
        eq(qmsg['list-id'], '<_xtest.dom.ain>')
1249 by Mark Sapiro
Updated unit tests for current Mailman so all tests should pass.
60
        eq(qmsg['x-list-administrivia'], 'yes')
1 by
This commit was manufactured by cvs2svn to create branch
61
        eq(qmsg.get_payload(), 'About your test list')
62
1249 by Mark Sapiro
Updated unit tests for current Mailman so all tests should pass.
63
class TestSentMessage2(EmailBase):
1 by
This commit was manufactured by cvs2svn to create branch
64
    def test_bounce_message(self):
65
        eq = self.assertEqual
66
        unless = self.failUnless
67
        msg = email.message_from_string("""\
68
To: _xtest@dom.ain
69
From: nobody@dom.ain
70
Subject: and another thing
71
72
yadda yadda yadda
73
""", Message.Message)
74
        self._mlist.BounceMessage(msg, {})
75
        qmsg = email.message_from_string(self._readmsg())
76
        unless(qmsg.is_multipart())
77
        eq(len(qmsg.get_payload()), 2)
78
        # The first payload is the details of the bounce action, and the
79
        # second message is the message/rfc822 attachment of the original
80
        # message.
81
        msg1 = qmsg.get_payload(0)
1139.1.1 by Mark Sapiro
Now that Python 2.4 is the minimum and we will use more recent installed
82
        eq(msg1.get_content_type(), 'text/plain')
1249 by Mark Sapiro
Updated unit tests for current Mailman so all tests should pass.
83
        eq(msg1.get_payload(), '[No bounce details are available]')
1 by
This commit was manufactured by cvs2svn to create branch
84
        msg2 = qmsg.get_payload(1)
1139.1.1 by Mark Sapiro
Now that Python 2.4 is the minimum and we will use more recent installed
85
        eq(msg2.get_content_type(), 'message/rfc822')
1249 by Mark Sapiro
Updated unit tests for current Mailman so all tests should pass.
86
        unless(msg2.is_multipart())
87
        msg3 = msg2.get_payload(0)
1 by
This commit was manufactured by cvs2svn to create branch
88
        eq(msg3.get_payload(), 'yadda yadda yadda\n')
89
90
91

1249 by Mark Sapiro
Updated unit tests for current Mailman so all tests should pass.
92
def suite(x):
1 by
This commit was manufactured by cvs2svn to create branch
93
    suite = unittest.TestSuite()
1249 by Mark Sapiro
Updated unit tests for current Mailman so all tests should pass.
94
    if x == '1':
95
        suite.addTest(unittest.makeSuite(TestSentMessage1))
96
    elif x == '2':
97
        suite.addTest(unittest.makeSuite(TestSentMessage2))
1 by
This commit was manufactured by cvs2svn to create branch
98
    return suite
99
100
101

102
if __name__ == '__main__':
1249 by Mark Sapiro
Updated unit tests for current Mailman so all tests should pass.
103
    # There is some issue in asyncore.py that prevents successfully running more than
104
    # one test at a time, so specify which of the two tests as an argument.
105
    if len(sys.argv) == 1:
106
        x = '1'
107
    else:
108
        x = sys.argv[1]
109
    if x not in ('1', '2'):
110
        print >> sys.stderr, (
111
            'usage: python test_message.py [n] where n = 1, 2 is the sub-test to run.')
112
        sys.exit(1)
113
    unittest.TextTestRunner(verbosity=2).run(suite(x)) 
114