~bzr-pqm/bzr/bzr.dev

5557.1.7 by John Arbash Meinel
Merge in the bzr.dev 5582
1
# Copyright (C) 2006-2011 Canonical Ltd
0.4.1 by Martin Pool
Start lp-register command
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.4.1 by Martin Pool
Start lp-register command
16
0.4.8 by Martin Pool
More instrumentation of xmlrpc requests
17
import base64
18
from StringIO import StringIO
2978.5.1 by John Arbash Meinel
Fix bug #162494, 'bzr register-branch' needs proper auth handling.
19
import urlparse
0.4.5 by Martin Pool
Add structured test for parameters passed through xmlrpc
20
import xmlrpclib
21
2978.5.1 by John Arbash Meinel
Fix bug #162494, 'bzr register-branch' needs proper auth handling.
22
from bzrlib import (
23
    config,
24
    tests,
25
    ui,
26
    )
5582.1.2 by Jelmer Vernooij
Add NEWS entry, comment. Remove unnecessary code.
27
from bzrlib.tests import TestCaseWithTransport
0.4.1 by Martin Pool
Start lp-register command
28
0.4.5 by Martin Pool
Add structured test for parameters passed through xmlrpc
29
# local import
2898.3.8 by James Henstridge
Get rid of relative imports in Launchpad plugin.
30
from bzrlib.plugins.launchpad.lp_registration import (
0.4.26 by Martin Pool
(register-branch) Add test for link_branch_to_bug and fix its parameters
31
        BaseRequest,
32
        BranchBugLinkRequest,
33
        BranchRegistrationRequest,
2898.4.3 by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL.
34
        ResolveLaunchpadPathRequest,
0.4.26 by Martin Pool
(register-branch) Add test for link_branch_to_bug and fix its parameters
35
        LaunchpadService,
36
        )
0.4.5 by Martin Pool
Add structured test for parameters passed through xmlrpc
37
0.4.7 by Martin Pool
Start making provision to test using a mock xmlrpc transport.
38
0.4.12 by Martin Pool
doc
39
# TODO: Test that the command-line client, making sure that it'll pass the
40
# request through to a dummy transport, and that the transport will validate
41
# the results passed in.  Not sure how to get the transport object back out to
42
# validate that its OK - may not be necessary.
43
44
# TODO: Add test for (and implement) other command-line options to set
0.4.14 by Martin Pool
Update xmlrpc api
45
# project, author_email, description.
0.4.12 by Martin Pool
doc
46
47
# TODO: project_id is not properly handled -- must be passed in rpc or path.
48
0.4.8 by Martin Pool
More instrumentation of xmlrpc requests
49
class InstrumentedXMLRPCConnection(object):
50
    """Stands in place of an http connection for the purposes of testing"""
51
52
    def __init__(self, testcase):
53
        self.testcase = testcase
54
55
    def getreply(self):
56
        """Fake the http reply.
57
58
        :returns: (errcode, errmsg, headers)
59
        """
60
        return (200, 'OK', [])
61
5582.1.1 by Bazaar Builbot Net
Quick-and-dirty hack to fix bug #654733
62
    def getresponse(self, buffering=True):
5582.1.2 by Jelmer Vernooij
Add NEWS entry, comment. Remove unnecessary code.
63
        """Fake the http reply.
64
65
        This is used when running on Python 2.7, where xmlrpclib uses
66
        httplib.HTTPConnection in a different way than before.
67
        """
5582.1.1 by Bazaar Builbot Net
Quick-and-dirty hack to fix bug #654733
68
        class FakeHttpResponse(object):
69
5582.13.1 by Vincent Ladeuil
A bit less dirty and bit more robust so that it also works on FreeBSD8 (and may others).
70
            def __init__(self, status, reason, body):
5582.1.1 by Bazaar Builbot Net
Quick-and-dirty hack to fix bug #654733
71
                self.status = status
72
                self.reason = reason
73
                self.body = body
74
75
            def read(self, size=-1):
76
                return self.body.read(size)
77
5582.13.1 by Vincent Ladeuil
A bit less dirty and bit more robust so that it also works on FreeBSD8 (and may others).
78
            def getheader(self, name, default):
79
                # We don't have headers
80
                return default
81
82
        return FakeHttpResponse(200, 'OK', self.getfile())
5582.1.1 by Bazaar Builbot Net
Quick-and-dirty hack to fix bug #654733
83
0.4.8 by Martin Pool
More instrumentation of xmlrpc requests
84
    def getfile(self):
85
        """Return a fake file containing the response content."""
86
        return StringIO('''\
87
<?xml version="1.0" ?>
88
<methodResponse>
0.4.11 by Martin Pool
Check the correct params are seen by the server
89
    <params>
90
        <param>
91
            <value>
92
                <string>victoria dock</string>
93
            </value>
94
        </param>
95
    </params>
0.4.8 by Martin Pool
More instrumentation of xmlrpc requests
96
</methodResponse>''')
97
98
99
0.4.7 by Martin Pool
Start making provision to test using a mock xmlrpc transport.
100
class InstrumentedXMLRPCTransport(xmlrpclib.Transport):
101
2027.2.2 by Marien Zwart
Fixes for python 2.5.
102
    # Python 2.5's xmlrpclib looks for this.
103
    _use_datetime = False
104
2898.4.2 by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution.
105
    def __init__(self, testcase, expect_auth):
0.4.7 by Martin Pool
Start making provision to test using a mock xmlrpc transport.
106
        self.testcase = testcase
2898.4.2 by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution.
107
        self.expect_auth = expect_auth
5582.1.3 by Jelmer Vernooij
Revert _connection change, as it is apparently needed for Python >= 2.7.0 && Python < 2.7.2.
108
        self._connection = (None, None)
0.4.7 by Martin Pool
Start making provision to test using a mock xmlrpc transport.
109
110
    def make_connection(self, host):
111
        host, http_headers, x509 = self.get_host_info(host)
112
        test = self.testcase
0.4.10 by Martin Pool
Move test-specific values out of InstrumentedXMLRPCTransport
113
        self.connected_host = host
2898.4.2 by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution.
114
        if self.expect_auth:
115
            auth_hdrs = [v for k,v in http_headers if k == 'Authorization']
3376.2.15 by Martin Pool
Fix assertions in Launchpad registration tests
116
            if len(auth_hdrs) != 1:
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
117
                raise AssertionError("multiple auth headers: %r"
118
                    % (auth_hdrs,))
2898.4.2 by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution.
119
            authinfo = auth_hdrs[0]
120
            expected_auth = 'testuser@launchpad.net:testpassword'
121
            test.assertEquals(authinfo,
122
                    'Basic ' + base64.encodestring(expected_auth).strip())
3376.2.15 by Martin Pool
Fix assertions in Launchpad registration tests
123
        elif http_headers:
124
            raise AssertionError()
0.4.8 by Martin Pool
More instrumentation of xmlrpc requests
125
        return InstrumentedXMLRPCConnection(test)
0.4.7 by Martin Pool
Start making provision to test using a mock xmlrpc transport.
126
127
    def send_request(self, connection, handler_path, request_body):
128
        test = self.testcase
129
        self.got_request = True
130
131
    def send_host(self, conn, host):
132
        pass
133
134
    def send_user_agent(self, conn):
135
        # TODO: send special user agent string, including bzrlib version
136
        # number
137
        pass
138
139
    def send_content(self, conn, request_body):
140
        unpacked, method = xmlrpclib.loads(request_body)
3376.2.15 by Martin Pool
Fix assertions in Launchpad registration tests
141
        if None in unpacked:
142
            raise AssertionError(
143
                "xmlrpc result %r shouldn't contain None" % (unpacked,))
0.4.10 by Martin Pool
Move test-specific values out of InstrumentedXMLRPCTransport
144
        self.sent_params = unpacked
0.4.7 by Martin Pool
Start making provision to test using a mock xmlrpc transport.
145
146
0.4.22 by Martin Pool
(register-branch) Update tests to be in-process calls to a mock server.
147
class MockLaunchpadService(LaunchpadService):
148
2898.4.1 by James Henstridge
Make it possible to make unauthenticated XML-RPC requests.
149
    def send_request(self, method_name, method_params, authenticated):
0.4.22 by Martin Pool
(register-branch) Update tests to be in-process calls to a mock server.
150
        """Stash away the method details rather than sending them to a real server"""
151
        self.called_method_name = method_name
152
        self.called_method_params = method_params
2898.4.1 by James Henstridge
Make it possible to make unauthenticated XML-RPC requests.
153
        self.called_authenticated = authenticated
0.4.22 by Martin Pool
(register-branch) Update tests to be in-process calls to a mock server.
154
155
3200.2.1 by Robert Collins
* The ``register-branch`` command will now use the public url of the branch
156
class TestBranchRegistration(TestCaseWithTransport):
0.4.4 by Martin Pool
Start forming xmlrpc requests
157
0.4.23 by Martin Pool
(register-branch) fix ordering of parameters and restore transport-level test.
158
    def setUp(self):
159
        super(TestBranchRegistration, self).setUp()
160
        # make sure we have a reproducible standard environment
5570.3.6 by Vincent Ladeuil
Get rid of all _captureVar() calls, no test failures, pfew.
161
        self.overrideEnv('BZR_LP_XMLRPC_URL', None)
0.4.23 by Martin Pool
(register-branch) fix ordering of parameters and restore transport-level test.
162
0.4.22 by Martin Pool
(register-branch) Update tests to be in-process calls to a mock server.
163
    def test_register_help(self):
164
        """register-branch accepts --help"""
2581.1.4 by Martin Pool
fixup run_bzr syntax in launchpad plugin
165
        out, err = self.run_bzr(['register-branch', '--help'])
0.4.2 by Martin Pool
Rename command to 'register-branch'
166
        self.assertContainsRe(out, r'Register a branch')
167
3200.2.1 by Robert Collins
* The ``register-branch`` command will now use the public url of the branch
168
    def test_register_no_url_no_branch(self):
0.4.22 by Martin Pool
(register-branch) Update tests to be in-process calls to a mock server.
169
        """register-branch command requires parameters"""
3200.2.1 by Robert Collins
* The ``register-branch`` command will now use the public url of the branch
170
        self.make_repository('.')
171
        self.run_bzr_error(
172
            ['register-branch requires a public branch url - '
173
             'see bzr help register-branch'],
174
            'register-branch')
175
176
    def test_register_no_url_in_published_branch_no_error(self):
177
        b = self.make_branch('.')
178
        b.set_public_branch('http://test-server.com/bzr/branch')
179
        out, err = self.run_bzr(['register-branch', '--dry-run'])
180
        self.assertEqual('Branch registered.\n', out)
181
        self.assertEqual('', err)
182
183
    def test_register_no_url_in_unpublished_branch_errors(self):
184
        b = self.make_branch('.')
185
        out, err = self.run_bzr_error(['no public branch'],
186
            ['register-branch', '--dry-run'])
187
        self.assertEqual('', out)
0.4.3 by Martin Pool
More command line processing
188
1668.1.12 by Martin Pool
(launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service.
189
    def test_register_dry_run(self):
2581.1.4 by Martin Pool
fixup run_bzr syntax in launchpad plugin
190
        out, err = self.run_bzr(['register-branch',
1668.1.12 by Martin Pool
(launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service.
191
                                'http://test-server.com/bzr/branch',
2581.1.4 by Martin Pool
fixup run_bzr syntax in launchpad plugin
192
                                '--dry-run'])
1668.1.12 by Martin Pool
(launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service.
193
        self.assertEquals(out, 'Branch registered.\n')
0.4.4 by Martin Pool
Start forming xmlrpc requests
194
0.4.23 by Martin Pool
(register-branch) fix ordering of parameters and restore transport-level test.
195
    def test_onto_transport(self):
4634.165.3 by Vincent Ladeuil
Delete all references to edge.launchpad.net in code and associated tests.
196
        """How the request is sent by transmitting across a mock Transport"""
0.4.23 by Martin Pool
(register-branch) fix ordering of parameters and restore transport-level test.
197
        # use a real transport, but intercept at the http/xml layer
2898.4.2 by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution.
198
        transport = InstrumentedXMLRPCTransport(self, expect_auth=True)
0.4.30 by Martin Pool
Fix wierd syntax errors in test
199
        service = LaunchpadService(transport)
0.4.23 by Martin Pool
(register-branch) fix ordering of parameters and restore transport-level test.
200
        service.registrant_email = 'testuser@launchpad.net'
201
        service.registrant_password = 'testpassword'
0.4.7 by Martin Pool
Start making provision to test using a mock xmlrpc transport.
202
        rego = BranchRegistrationRequest('http://test-server.com/bzr/branch',
0.4.23 by Martin Pool
(register-branch) fix ordering of parameters and restore transport-level test.
203
                'branch-id',
204
                'my test branch',
205
                'description',
206
                'author@launchpad.net',
207
                'product')
0.4.20 by Bjorn Tillenius
try to fix the tests.
208
        rego.submit(service)
5243.1.1 by Martin
Use the production server in the launchpad plugin rather than edge
209
        self.assertEquals(transport.connected_host, 'xmlrpc.launchpad.net')
0.4.14 by Martin Pool
Update xmlrpc api
210
        self.assertEquals(len(transport.sent_params), 6)
0.4.11 by Martin Pool
Check the correct params are seen by the server
211
        self.assertEquals(transport.sent_params,
0.4.23 by Martin Pool
(register-branch) fix ordering of parameters and restore transport-level test.
212
                ('http://test-server.com/bzr/branch',  # branch_url
213
                 'branch-id',                          # branch_name
214
                 'my test branch',                     # branch_title
215
                 'description',
216
                 'author@launchpad.net',
217
                 'product'))
0.4.8 by Martin Pool
More instrumentation of xmlrpc requests
218
        self.assertTrue(transport.got_request)
0.4.13 by Martin Pool
Update xmlrpc api to pass product name as a parameter.
219
2898.4.2 by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution.
220
    def test_onto_transport_unauthenticated(self):
4634.165.3 by Vincent Ladeuil
Delete all references to edge.launchpad.net in code and associated tests.
221
        """An unauthenticated request is transmitted across a mock Transport"""
2898.4.2 by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution.
222
        transport = InstrumentedXMLRPCTransport(self, expect_auth=False)
223
        service = LaunchpadService(transport)
2898.4.3 by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL.
224
        resolve = ResolveLaunchpadPathRequest('bzr')
2898.4.2 by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution.
225
        resolve.submit(service)
5243.1.1 by Martin
Use the production server in the launchpad plugin rather than edge
226
        self.assertEquals(transport.connected_host, 'xmlrpc.launchpad.net')
2898.4.2 by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution.
227
        self.assertEquals(len(transport.sent_params), 1)
228
        self.assertEquals(transport.sent_params, ('bzr', ))
229
        self.assertTrue(transport.got_request)
230
0.4.22 by Martin Pool
(register-branch) Update tests to be in-process calls to a mock server.
231
    def test_subclass_request(self):
232
        """Define a new type of xmlrpc request"""
233
        class DummyRequest(BaseRequest):
234
            _methodname = 'dummy_request'
235
            def _request_params(self):
236
                return (42,)
237
238
        service = MockLaunchpadService()
239
        service.registrant_email = 'test@launchpad.net'
240
        service.registrant_password = ''
241
        request = DummyRequest()
242
        request.submit(service)
243
        self.assertEquals(service.called_method_name, 'dummy_request')
244
        self.assertEquals(service.called_method_params, (42,))
245
0.4.24 by Martin Pool
(register-branch) additional test case against mock server
246
    def test_mock_server_registration(self):
247
        """Send registration to mock server"""
248
        test_case = self
249
        class MockRegistrationService(MockLaunchpadService):
2898.4.1 by James Henstridge
Make it possible to make unauthenticated XML-RPC requests.
250
            def send_request(self, method_name, method_params, authenticated):
0.4.24 by Martin Pool
(register-branch) additional test case against mock server
251
                test_case.assertEquals(method_name, "register_branch")
252
                test_case.assertEquals(list(method_params),
253
                        ['url', 'name', 'title', 'description', 'email', 'name'])
2898.4.1 by James Henstridge
Make it possible to make unauthenticated XML-RPC requests.
254
                test_case.assertEquals(authenticated, True)
0.4.24 by Martin Pool
(register-branch) additional test case against mock server
255
                return 'result'
256
        service = MockRegistrationService()
257
        rego = BranchRegistrationRequest('url', 'name', 'title',
258
                        'description', 'email', 'name')
259
        result = rego.submit(service)
260
        self.assertEquals(result, 'result')
0.4.25 by Martin Pool
(register-branch) additional test for registration with defaults
261
262
    def test_mock_server_registration_with_defaults(self):
263
        """Send registration to mock server"""
264
        test_case = self
265
        class MockRegistrationService(MockLaunchpadService):
2898.4.1 by James Henstridge
Make it possible to make unauthenticated XML-RPC requests.
266
            def send_request(self, method_name, method_params, authenticated):
0.4.25 by Martin Pool
(register-branch) additional test for registration with defaults
267
                test_case.assertEquals(method_name, "register_branch")
268
                test_case.assertEquals(list(method_params),
269
                        ['http://server/branch', 'branch', '', '', '', ''])
2898.4.1 by James Henstridge
Make it possible to make unauthenticated XML-RPC requests.
270
                test_case.assertEquals(authenticated, True)
0.4.25 by Martin Pool
(register-branch) additional test for registration with defaults
271
                return 'result'
272
        service = MockRegistrationService()
273
        rego = BranchRegistrationRequest('http://server/branch')
274
        result = rego.submit(service)
275
        self.assertEquals(result, 'result')
0.4.26 by Martin Pool
(register-branch) Add test for link_branch_to_bug and fix its parameters
276
277
    def test_mock_bug_branch_link(self):
278
        """Send bug-branch link to mock server"""
279
        test_case = self
280
        class MockService(MockLaunchpadService):
2898.4.1 by James Henstridge
Make it possible to make unauthenticated XML-RPC requests.
281
            def send_request(self, method_name, method_params, authenticated):
0.4.26 by Martin Pool
(register-branch) Add test for link_branch_to_bug and fix its parameters
282
                test_case.assertEquals(method_name, "link_branch_to_bug")
283
                test_case.assertEquals(list(method_params),
284
                        ['http://server/branch', 1234, ''])
2898.4.1 by James Henstridge
Make it possible to make unauthenticated XML-RPC requests.
285
                test_case.assertEquals(authenticated, True)
0.4.26 by Martin Pool
(register-branch) Add test for link_branch_to_bug and fix its parameters
286
                return 'http://launchpad.net/bug/1234'
287
        service = MockService()
288
        rego = BranchBugLinkRequest('http://server/branch', 1234)
289
        result = rego.submit(service)
290
        self.assertEquals(result, 'http://launchpad.net/bug/1234')
2898.4.2 by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution.
291
292
    def test_mock_resolve_lp_url(self):
293
        test_case = self
294
        class MockService(MockLaunchpadService):
295
            def send_request(self, method_name, method_params, authenticated):
2898.4.7 by James Henstridge
Fix up tests.
296
                test_case.assertEquals(method_name, "resolve_lp_path")
2898.4.2 by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution.
297
                test_case.assertEquals(list(method_params), ['bzr'])
298
                test_case.assertEquals(authenticated, False)
2898.4.4 by James Henstridge
Changes to account for modifications to the XMLRPC API.
299
                return dict(urls=[
300
                        'bzr+ssh://bazaar.launchpad.net~bzr/bzr/trunk',
301
                        'sftp://bazaar.launchpad.net~bzr/bzr/trunk',
302
                        'bzr+http://bazaar.launchpad.net~bzr/bzr/trunk',
303
                        'http://bazaar.launchpad.net~bzr/bzr/trunk'])
2898.4.2 by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution.
304
        service = MockService()
2898.4.3 by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL.
305
        resolve = ResolveLaunchpadPathRequest('bzr')
2898.4.2 by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution.
306
        result = resolve.submit(service)
2898.4.4 by James Henstridge
Changes to account for modifications to the XMLRPC API.
307
        self.assertTrue('urls' in result)
308
        self.assertEquals(result['urls'], [
309
                'bzr+ssh://bazaar.launchpad.net~bzr/bzr/trunk',
310
                'sftp://bazaar.launchpad.net~bzr/bzr/trunk',
311
                'bzr+http://bazaar.launchpad.net~bzr/bzr/trunk',
312
                'http://bazaar.launchpad.net~bzr/bzr/trunk'])
2978.5.2 by John Arbash Meinel
merge bzr.dev 2991
313
2978.5.1 by John Arbash Meinel
Fix bug #162494, 'bzr register-branch' needs proper auth handling.
314
315
class TestGatherUserCredentials(tests.TestCaseInTempDir):
316
317
    def setUp(self):
318
        super(TestGatherUserCredentials, self).setUp()
319
        # make sure we have a reproducible standard environment
5570.3.6 by Vincent Ladeuil
Get rid of all _captureVar() calls, no test failures, pfew.
320
        self.overrideEnv('BZR_LP_XMLRPC_URL', None)
2978.5.1 by John Arbash Meinel
Fix bug #162494, 'bzr register-branch' needs proper auth handling.
321
322
    def test_gather_user_credentials_has_password(self):
323
        service = LaunchpadService()
324
        service.registrant_password = 'mypassword'
325
        # This should be a basic no-op, since we already have the password
326
        service.gather_user_credentials()
327
        self.assertEqual('mypassword', service.registrant_password)
328
329
    def test_gather_user_credentials_from_auth_conf(self):
330
        auth_path = config.authentication_config_filename()
331
        service = LaunchpadService()
332
        g_conf = config.GlobalConfig()
333
        g_conf.set_user_option('email', 'Test User <test@user.com>')
334
        f = open(auth_path, 'wb')
335
        try:
336
            scheme, hostinfo = urlparse.urlsplit(service.service_url)[:2]
337
            f.write('[section]\n'
338
                    'scheme=%s\n'
339
                    'host=%s\n'
340
                    'user=test@user.com\n'
341
                    'password=testpass\n'
342
                    % (scheme, hostinfo))
343
        finally:
344
            f.close()
345
        self.assertIs(None, service.registrant_password)
346
        service.gather_user_credentials()
347
        self.assertEqual('test@user.com', service.registrant_email)
348
        self.assertEqual('testpass', service.registrant_password)
349
350
    def test_gather_user_credentials_prompts(self):
351
        service = LaunchpadService()
352
        self.assertIs(None, service.registrant_password)
353
        g_conf = config.GlobalConfig()
354
        g_conf.set_user_option('email', 'Test User <test@user.com>')
355
        stdout = tests.StringIOWrapper()
4368.3.4 by Vincent Ladeuil
Fix plugin test too :-/
356
        stderr = tests.StringIOWrapper()
2978.5.1 by John Arbash Meinel
Fix bug #162494, 'bzr register-branch' needs proper auth handling.
357
        ui.ui_factory = tests.TestUIFactory(stdin='userpass\n',
4368.3.4 by Vincent Ladeuil
Fix plugin test too :-/
358
                                            stdout=stdout, stderr=stderr)
2978.5.1 by John Arbash Meinel
Fix bug #162494, 'bzr register-branch' needs proper auth handling.
359
        self.assertIs(None, service.registrant_password)
360
        service.gather_user_credentials()
361
        self.assertEqual('test@user.com', service.registrant_email)
362
        self.assertEqual('userpass', service.registrant_password)
4368.3.4 by Vincent Ladeuil
Fix plugin test too :-/
363
        self.assertEquals('', stdout.getvalue())
364
        self.assertContainsRe(stderr.getvalue(),
2978.5.1 by John Arbash Meinel
Fix bug #162494, 'bzr register-branch' needs proper auth handling.
365
                             'launchpad.net password for test@user\\.com')
366