~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smtp_connection.py

  • Committer: John Arbash Meinel
  • Date: 2007-07-20 14:28:59 UTC
  • mfrom: (2625.6.3 bzr.email_message)
  • mto: This revision was merged to the branch mainline in revision 2640.
  • Revision ID: john@arbash-meinel.com-20070720142859-a24s0khul0yw91bh
(Adeodato Simó) EmailMessage class, allowing much nicer access to Email object than stdlib

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)