~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smtp_connection.py

  • Committer: Jelmer Vernooij
  • Date: 2016-04-03 16:32:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6617.
  • Revision ID: jelmer@jelmer.uk-20160403163231-h72bo0uyek2gikw0
Don't put French text in doc/en/user-reference when LANGUAGE=fr_CH.UTF_8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
class TestSMTPConnection(tests.TestCaseInTempDir):
91
91
 
92
92
    def get_connection(self, text, smtp_factory=None):
93
 
        my_config = config.GlobalConfig.from_string(text)
94
 
        return smtp_connection.SMTPConnection(my_config,
95
 
                                              _smtp_factory=smtp_factory)
 
93
        my_config = config.MemoryStack(text)
 
94
        return smtp_connection.SMTPConnection(
 
95
            my_config, _smtp_factory=smtp_factory)
96
96
 
97
97
    def test_defaults(self):
98
98
        conn = self.get_connection('')
101
101
        self.assertEqual(None, conn._smtp_password)
102
102
 
103
103
    def test_smtp_server(self):
104
 
        conn = self.get_connection('[DEFAULT]\nsmtp_server=host:10\n')
 
104
        conn = self.get_connection('smtp_server=host:10')
105
105
        self.assertEqual('host:10', conn._smtp_server)
106
106
 
107
107
    def test_missing_server(self):
108
108
        conn = self.get_connection('', smtp_factory=connection_refuser)
109
109
        self.assertRaises(errors.DefaultSMTPConnectionRefused, conn._connect)
110
 
        conn = self.get_connection('[DEFAULT]\nsmtp_server=smtp.example.com\n',
 
110
        conn = self.get_connection('smtp_server=smtp.example.com',
111
111
                                   smtp_factory=connection_refuser)
112
112
        self.assertRaises(errors.SMTPConnectionRefused, conn._connect)
113
113
 
115
115
        conn = self.get_connection('')
116
116
        self.assertIs(None, conn._smtp_username)
117
117
 
118
 
        conn = self.get_connection('[DEFAULT]\nsmtp_username=joebody\n')
 
118
        conn = self.get_connection('smtp_username=joebody')
119
119
        self.assertEqual(u'joebody', conn._smtp_username)
120
120
 
121
121
    def test_smtp_password_from_config(self):
122
122
        conn = self.get_connection('')
123
123
        self.assertIs(None, conn._smtp_password)
124
124
 
125
 
        conn = self.get_connection('[DEFAULT]\nsmtp_password=mypass\n')
 
125
        conn = self.get_connection('smtp_password=mypass')
126
126
        self.assertEqual(u'mypass', conn._smtp_password)
127
127
 
128
128
    def test_smtp_password_from_user(self):
161
161
        utf8_pass = unicode_pass.encode('utf-8')
162
162
        factory = WideOpenSMTPFactory()
163
163
        conn = self.get_connection(
164
 
            u'[DEFAULT]\nsmtp_username=%s\nsmtp_password=%s\n'
165
 
            % (user, unicode_pass), smtp_factory=factory)
 
164
            '[DEFAULT]\nsmtp_username=%s\nsmtp_password=%s\n'
 
165
            % (user, utf8_pass), smtp_factory=factory)
166
166
        self.assertEqual(unicode_pass, conn._smtp_password)
167
167
        conn._connect()
168
168
        self.assertEqual([('connect', 'localhost'),
254
254
            'pperez@ejemplo.com', 'user@localhost']), sorted(to))
255
255
 
256
256
    def test_destination_address_required(self):
257
 
        class FakeConfig:
258
 
            def get_user_option(self, option):
259
 
                return None
260
 
 
261
257
        msg = Message()
262
258
        msg['From'] = '"J. Random Developer" <jrandom@example.com>'
263
259
        self.assertRaises(
264
260
            errors.NoDestinationAddress,
265
 
            smtp_connection.SMTPConnection(FakeConfig()).send_email, msg)
 
261
            smtp_connection.SMTPConnection(config.MemoryStack("")
 
262
                                           ).send_email, msg)
266
263
 
267
264
        msg = email_message.EmailMessage('from@from.com', '', 'subject')
268
265
        self.assertRaises(
269
266
            errors.NoDestinationAddress,
270
 
            smtp_connection.SMTPConnection(FakeConfig()).send_email, msg)
 
267
            smtp_connection.SMTPConnection(config.MemoryStack("")
 
268
                                           ).send_email, msg)
271
269
 
272
270
        msg = email_message.EmailMessage('from@from.com', [], 'subject')
273
271
        self.assertRaises(
274
272
            errors.NoDestinationAddress,
275
 
            smtp_connection.SMTPConnection(FakeConfig()).send_email, msg)
 
273
            smtp_connection.SMTPConnection(config.MemoryStack("")
 
274
                                           ).send_email, msg)