~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: 2008-08-25 21:50:11 UTC
  • mfrom: (0.11.3 tools)
  • mto: This revision was merged to the branch mainline in revision 3659.
  • Revision ID: john@arbash-meinel.com-20080825215011-de9esmzgkue3e522
Merge in Lukáš's helper scripts.
Update the packaging documents to describe how to do the releases
using bzr-builddeb to package all distro platforms
simultaneously.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2007, 2009 Canonical Ltd
 
1
# Copyright (C) 2005, 2007 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
from cStringIO import StringIO
18
18
from email.Message import Message
19
19
import errno
20
20
import smtplib
21
21
import socket
 
22
import sys
22
23
 
23
24
from bzrlib import (
24
25
    config,
85
86
    """A fake smtp server that implements login by accepting anybody."""
86
87
 
87
88
    def login(self, user, password):
88
 
        self._calls.append(('login', user, password))
 
89
        pass
89
90
 
90
91
 
91
92
class TestSMTPConnection(tests.TestCaseInTempDir):
136
137
                                   smtp_factory=factory)
137
138
        self.assertIs(None, conn._smtp_password)
138
139
 
139
 
        ui.ui_factory = ui.CannedInputUIFactory([password])
 
140
        ui.ui_factory = tests.TestUIFactory(stdin=password + '\n',
 
141
                                            stdout=tests.StringIOWrapper())
140
142
        conn._connect()
141
143
        self.assertEqual(password, conn._smtp_password)
 
144
        # stdin should be empty (the provided password have been consumed)
 
145
        self.assertEqual('', ui.ui_factory.stdin.readline())
142
146
 
143
147
    def test_smtp_password_from_auth_config(self):
144
148
        user = 'joe'
158
162
        conn._connect()
159
163
        self.assertEqual(password, conn._smtp_password)
160
164
 
161
 
    def test_authenticate_with_byte_strings(self):
162
 
        user = 'joe'
163
 
        password = 'h\xC3\xACspass'
164
 
        factory = WideOpenSMTPFactory()
165
 
        conn = self.get_connection(
166
 
            '[DEFAULT]\nsmtp_username=%s\nsmtp_password=%s\n'
167
 
            % (user, password), smtp_factory=factory)
168
 
        self.assertEqual(u'h\xECspass', conn._smtp_password)
169
 
        conn._connect()
170
 
        self.assertEqual([('connect', 'localhost'),
171
 
                          ('ehlo',),
172
 
                          ('has_extn', 'starttls'),
173
 
                          ('login', user, password)], factory._calls)
174
 
        smtp_username, smtp_password = factory._calls[-1][1:]
175
 
        self.assertIsInstance(smtp_username, str)
176
 
        self.assertIsInstance(smtp_password, str)
177
 
 
178
165
    def test_create_connection(self):
179
166
        factory = StubSMTPFactory()
180
167
        conn = self.get_connection('', smtp_factory=factory)