/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smtp_connection.py

  • Committer: Adeodato Simó
  • Date: 2007-07-18 15:51:52 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-20070718155152-pv6rwq41eckqyxem
New EmailMessage class, façade around email.Message and MIMEMultipart.

* bzrlib/email_message.py,
  bzrlib/tests/test_email_message.py:
  New files.

* bzrlib/tests/__init__.py:
  (test_suite): add bzrlib.tests.test_email_message.

* bzrlib/merge_directive.py:
  (MergeDirective.to_email): Use EmailMessage instead of email.Message.

* bzrlib/tests/test_merge_directive.py,
  bzrlib/tests/blackbox/test_merge_directive.py:
  (__main__): adjust EMAIL1 and EMAIL2 strings to how EmailMessage
  formats itself.

* bzrlib/smtp_connection.py:
  (SMTPConnection.get_message_addresses): do not use methods present in
  email.Message but not in EmailMessage (get_all). Use get() instead of
  __getitem__ to make explicit that None is returned if the header does
  not exist.

* bzrlib/tests/test_smtp_connection.py:
  (TestSMTPConnection.test_get_message_addresses, 
   TestSMTPConnection.test_destination_address_required): test the
   functions against EmailMessage in addition to email.Message.

* NEWS:
  Mention EmailMessage in INTERNALS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from email.Message import Message
19
19
 
20
20
from bzrlib import config
 
21
from bzrlib.email_message import EmailMessage
21
22
from bzrlib.errors import NoDestinationAddress
22
23
from bzrlib.tests import TestCase
23
24
from bzrlib.smtp_connection import SMTPConnection
72
73
        self.assertEqual(sorted(['john@doe.com', 'jane@doe.com',
73
74
            'pperez@ejemplo.com', 'user@localhost']), sorted(to))
74
75
 
 
76
        # now with bzrlib's EmailMessage
 
77
        msg = EmailMessage('"J. Random Developer" <jrandom@example.com>', [
 
78
            'John Doe <john@doe.com>', 'Jane Doe <jane@doe.com>',
 
79
            u'Pepe P\xe9rez <pperez@ejemplo.com>', 'user@localhost' ],
 
80
            'subject')
 
81
 
 
82
        from_, to = SMTPConnection.get_message_addresses(msg)
 
83
        self.assertEqual('jrandom@example.com', from_)
 
84
        self.assertEqual(sorted(['john@doe.com', 'jane@doe.com',
 
85
            'pperez@ejemplo.com', 'user@localhost']), sorted(to))
 
86
 
75
87
    def test_destination_address_required(self):
76
88
        class FakeConfig:
77
89
            def get_user_option(self, option):
81
93
        msg['From'] = '"J. Random Developer" <jrandom@example.com>'
82
94
        self.assertRaises(NoDestinationAddress,
83
95
                SMTPConnection(FakeConfig()).send_email, msg)
 
96
 
 
97
        msg = EmailMessage('from@from.com', '', 'subject')
 
98
        self.assertRaises(NoDestinationAddress,
 
99
                SMTPConnection(FakeConfig()).send_email, msg)
 
100
 
 
101
        msg = EmailMessage('from@from.com', [], 'subject')
 
102
        self.assertRaises(NoDestinationAddress,
 
103
                SMTPConnection(FakeConfig()).send_email, msg)