~barry/mailman/lp1423756

« back to all changes in this revision

Viewing changes to src/mailman/runners/tests/test_lmtp.py

  • Committer: Barry Warsaw
  • Date: 2015-01-05 01:20:33 UTC
  • mfrom: (7264.4.66 py3)
  • Revision ID: barry@list.org-20150105012033-zdrw9c2odhpf22fz
Merge the Python 3 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Tests for the LMTP server."""
19
19
 
20
 
from __future__ import absolute_import, print_function, unicode_literals
21
 
 
22
 
__metaclass__ = type
23
20
__all__ = [
24
21
    'TestLMTP',
25
22
    ]
30
27
import unittest
31
28
 
32
29
from datetime import datetime
33
 
 
34
30
from mailman.config import config
35
31
from mailman.app.lifecycle import create_list
36
32
from mailman.database.transaction import transaction
67
63
        # reasons)
68
64
        self.assertEqual(cm.exception.smtp_code, 550)
69
65
        self.assertEqual(cm.exception.smtp_error,
70
 
                         'No Message-ID header provided')
 
66
                         b'No Message-ID header provided')
71
67
 
72
68
    def test_message_id_hash_is_added(self):
73
69
        self._lmtp.sendmail('anne@example.com', ['test@example.com'], """\
118
114
        queue_directory = os.path.join(config.QUEUE_DIR, 'lmtp')
119
115
        self.assertFalse(os.path.isdir(queue_directory))
120
116
 
 
117
    def test_nonexistent_mailing_list(self):
 
118
        # Trying to post to a nonexistent mailing list is an error.
 
119
        with self.assertRaises(smtplib.SMTPDataError) as cm:
 
120
            self._lmtp.sendmail('anne@example.com',
 
121
                                ['notalist@example.com'], """\
 
122
From: anne.person@example.com
 
123
To: notalist@example.com
 
124
Subject: An interesting message
 
125
Message-ID: <aardvark>
 
126
 
 
127
""")
 
128
        self.assertEqual(cm.exception.smtp_code, 550)
 
129
        self.assertEqual(cm.exception.smtp_error,
 
130
                         b'Requested action not taken: mailbox unavailable')
 
131
 
 
132
    def test_missing_subaddress(self):
 
133
        # Trying to send a message to a bogus subaddress is an error.
 
134
        with self.assertRaises(smtplib.SMTPDataError) as cm:
 
135
            self._lmtp.sendmail('anne@example.com',
 
136
                                ['test-bogus@example.com'], """\
 
137
From: anne.person@example.com
 
138
To: test-bogus@example.com
 
139
Subject: An interesting message
 
140
Message-ID: <aardvark>
 
141
 
 
142
""")
 
143
        self.assertEqual(cm.exception.smtp_code, 550)
 
144
        self.assertEqual(cm.exception.smtp_error,
 
145
                         b'Requested action not taken: mailbox unavailable')
 
146
 
121
147
 
122
148
 
123
149
class TestBugs(unittest.TestCase):
142
168
""")
143
169
        messages = get_queue_messages('in')
144
170
        self.assertEqual(len(messages), 1)
145
 
        self.assertEqual(messages[0].msgdata['listname'],
146
 
                         'my-list@example.com')
 
171
        self.assertEqual(messages[0].msgdata['listid'],
 
172
                         'my-list.example.com')