~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smtp_connection.py

  • Committer: Andrew Bennetts
  • Date: 2010-07-29 11:17:57 UTC
  • mfrom: (5050.3.17 2.2)
  • mto: This revision was merged to the branch mainline in revision 5365.
  • Revision ID: andrew.bennetts@canonical.com-20100729111757-018h3pcefo7z0dnq
Merge lp:bzr/2.2 into lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2009, 2010, 2011 Canonical Ltd
 
1
# Copyright (C) 2005, 2007, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from cStringIO import StringIO
17
18
from email.Message import Message
18
19
import errno
19
20
import smtplib
90
91
class TestSMTPConnection(tests.TestCaseInTempDir):
91
92
 
92
93
    def get_connection(self, text, smtp_factory=None):
93
 
        my_config = config.GlobalConfig.from_string(text)
 
94
        my_config = config.GlobalConfig()
 
95
        config_file = StringIO(text)
 
96
        my_config._get_parser(config_file)
94
97
        return smtp_connection.SMTPConnection(my_config,
95
98
                                              _smtp_factory=smtp_factory)
96
99
 
157
160
 
158
161
    def test_authenticate_with_byte_strings(self):
159
162
        user = 'joe'
160
 
        unicode_pass = u'h\xECspass'
161
 
        utf8_pass = unicode_pass.encode('utf-8')
 
163
        password = 'h\xC3\xACspass'
162
164
        factory = WideOpenSMTPFactory()
163
165
        conn = self.get_connection(
164
 
            u'[DEFAULT]\nsmtp_username=%s\nsmtp_password=%s\n'
165
 
            % (user, unicode_pass), smtp_factory=factory)
166
 
        self.assertEqual(unicode_pass, conn._smtp_password)
 
166
            '[DEFAULT]\nsmtp_username=%s\nsmtp_password=%s\n'
 
167
            % (user, password), smtp_factory=factory)
 
168
        self.assertEqual(u'h\xECspass', conn._smtp_password)
167
169
        conn._connect()
168
170
        self.assertEqual([('connect', 'localhost'),
169
171
                          ('ehlo',),
170
172
                          ('has_extn', 'starttls'),
171
 
                          ('login', user, utf8_pass)], factory._calls)
 
173
                          ('login', user, password)], factory._calls)
172
174
        smtp_username, smtp_password = factory._calls[-1][1:]
173
175
        self.assertIsInstance(smtp_username, str)
174
176
        self.assertIsInstance(smtp_password, str)