~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_email_message.py

  • Committer: Adeodato Simó
  • Date: 2007-07-19 21:22:53 UTC
  • mto: (2639.1.1 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 2640.
  • Revision ID: dato@net.com.org.es-20070719212253-iaqokj16w681svwe
Changes after review by John.

* bzrlib/email_message.py:
  (EmailMessage): inherit from object.
  (EmailMessage.__getitem__): fix grammar in docstring.

* bzrlib/email_message.py,
  bzrlib/tests/test_email_message.py:
  Do not use variables named "string".

* bzrlib/tests/test_email_message.py:
  (TestEmailMessage.test_send): do not assert inside the verify_*
  functions that replace SMTPConnection.send_email. Instead, append the
  received message to a local variable, and call assert in the main body
  function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
111
111
                msg.as_string(BOUNDARY))
112
112
 
113
113
    def test_headers_accept_unicode_and_utf8(self):
114
 
        for string in [ u'Pepe P\xe9rez <pperez@ejemplo.com>',
 
114
        for user in [ u'Pepe P\xe9rez <pperez@ejemplo.com>',
115
115
                'Pepe P\xc3\xa9red <pperez@ejemplo.com>' ]:
116
 
            msg = EmailMessage(string, string, string) # no exception raised
 
116
            msg = EmailMessage(user, user, user) # no exception raised
117
117
 
118
118
            for header in ['From', 'To', 'Subject']:
119
119
                value = msg[header]
153
153
            def get_user_option(self, option):
154
154
                return None
155
155
 
156
 
        def verify_message_with_mime_type(mime_subtype='plain'):
157
 
            def wrapper(_self, msg):
158
 
                self.assertEqualDiff(COMPLEX_MULTIPART_MESSAGE % mime_subtype,
159
 
                        msg.as_string(BOUNDARY))
160
 
            return wrapper
 
156
        messages = []
161
157
 
162
 
        def verify_message_without_attachment(_self, msg):
163
 
            self.assertEqualDiff(SIMPLE_MESSAGE_ASCII , msg.as_string())
 
158
        def send_as_append(_self, msg):
 
159
            messages.append(msg.as_string(BOUNDARY))
164
160
 
165
161
        old_send_email = SMTPConnection.send_email
166
162
        try:
167
 
            SMTPConnection.send_email = verify_message_with_mime_type()
 
163
            SMTPConnection.send_email = send_as_append
 
164
 
168
165
            EmailMessage.send(FakeConfig(), 'from@from.com', 'to@to.com',
169
166
                    'subject', 'body', u'a\nb\nc\nd\ne\n', 'lines.txt')
 
167
            self.assertEqualDiff(COMPLEX_MULTIPART_MESSAGE % 'plain',
 
168
                    messages[0])
 
169
            messages[:] = []
170
170
 
171
 
            SMTPConnection.send_email = verify_message_with_mime_type(
172
 
                    'x-patch')
173
171
            EmailMessage.send(FakeConfig(), 'from@from.com', 'to@to.com',
174
172
                    'subject', 'body', u'a\nb\nc\nd\ne\n', 'lines.txt',
175
173
                    'x-patch')
 
174
            self.assertEqualDiff(COMPLEX_MULTIPART_MESSAGE % 'x-patch',
 
175
                    messages[0])
 
176
            messages[:] = []
176
177
 
177
 
            SMTPConnection.send_email = verify_message_without_attachment
178
178
            EmailMessage.send(FakeConfig(), 'from@from.com', 'to@to.com',
179
179
                    'subject', 'body')
 
180
            self.assertEqualDiff(SIMPLE_MESSAGE_ASCII , messages[0])
 
181
            messages[:] = []
180
182
        finally:
181
183
            SMTPConnection.send_email = old_send_email
182
184
 
220
222
                'P\xc3\xa9rez': ('P\xc3\xa9rez', 'utf-8'),
221
223
                'P\xe9rez':     ('P\xe9rez', '8-bit'),
222
224
        }
223
 
        for string, pair in pairs.items():
224
 
            self.assertEqual(pair, EmailMessage.string_with_encoding(string))
 
225
        for string_, pair in pairs.items():
 
226
            self.assertEqual(pair, EmailMessage.string_with_encoding(string_))