~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smtp_connection.py

  • Committer: Alexander Belchenko
  • Date: 2012-03-29 08:34:13 UTC
  • mto: (6015.44.14 2.4)
  • mto: This revision was merged to the branch mainline in revision 6513.
  • Revision ID: bialix@ukr.net-20120329083413-d4bqqdtfn2yrxp4f
change st_dev, st_ino, st_uid, st_gid from int members to properties.

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.MemoryStack(text)
94
 
        return smtp_connection.SMTPConnection(
95
 
            my_config, _smtp_factory=smtp_factory)
 
93
        my_config = config.GlobalConfig.from_string(text)
 
94
        return smtp_connection.SMTPConnection(my_config,
 
95
                                              _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('smtp_server=host:10')
 
104
        conn = self.get_connection('[DEFAULT]\nsmtp_server=host:10\n')
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('smtp_server=smtp.example.com',
 
110
        conn = self.get_connection('[DEFAULT]\nsmtp_server=smtp.example.com\n',
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('smtp_username=joebody')
 
118
        conn = self.get_connection('[DEFAULT]\nsmtp_username=joebody\n')
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('smtp_password=mypass')
 
125
        conn = self.get_connection('[DEFAULT]\nsmtp_password=mypass\n')
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
 
            '[DEFAULT]\nsmtp_username=%s\nsmtp_password=%s\n'
165
 
            % (user, utf8_pass), smtp_factory=factory)
 
164
            u'[DEFAULT]\nsmtp_username=%s\nsmtp_password=%s\n'
 
165
            % (user, unicode_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
 
257
261
        msg = Message()
258
262
        msg['From'] = '"J. Random Developer" <jrandom@example.com>'
259
263
        self.assertRaises(
260
264
            errors.NoDestinationAddress,
261
 
            smtp_connection.SMTPConnection(config.MemoryStack("")
262
 
                                           ).send_email, msg)
 
265
            smtp_connection.SMTPConnection(FakeConfig()).send_email, msg)
263
266
 
264
267
        msg = email_message.EmailMessage('from@from.com', '', 'subject')
265
268
        self.assertRaises(
266
269
            errors.NoDestinationAddress,
267
 
            smtp_connection.SMTPConnection(config.MemoryStack("")
268
 
                                           ).send_email, msg)
 
270
            smtp_connection.SMTPConnection(FakeConfig()).send_email, msg)
269
271
 
270
272
        msg = email_message.EmailMessage('from@from.com', [], 'subject')
271
273
        self.assertRaises(
272
274
            errors.NoDestinationAddress,
273
 
            smtp_connection.SMTPConnection(config.MemoryStack("")
274
 
                                           ).send_email, msg)
 
275
            smtp_connection.SMTPConnection(FakeConfig()).send_email, msg)