~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/launchpad/test_register.py

Merge bzr.dev, update to use new hooks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2011 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
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import base64
18
 
import os
19
18
from StringIO import StringIO
20
19
import urlparse
21
20
import xmlrpclib
22
21
 
23
22
from bzrlib import (
24
23
    config,
25
 
    osutils,
26
24
    tests,
27
25
    ui,
28
26
    )
29
 
from bzrlib.tests import TestCaseWithTransport, TestSkipped
 
27
from bzrlib.tests import TestCaseWithTransport
30
28
 
31
29
# local import
32
30
from bzrlib.plugins.launchpad.lp_registration import (
61
59
        """
62
60
        return (200, 'OK', [])
63
61
 
 
62
    def getresponse(self, buffering=True):
 
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
        """
 
68
        class FakeHttpResponse(object):
 
69
 
 
70
            def __init__(self, status, reason, body):
 
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
 
 
78
            def getheader(self, name, default):
 
79
                # We don't have headers
 
80
                return default
 
81
 
 
82
        return FakeHttpResponse(200, 'OK', self.getfile())
 
83
 
64
84
    def getfile(self):
65
85
        """Return a fake file containing the response content."""
66
86
        return StringIO('''\
85
105
    def __init__(self, testcase, expect_auth):
86
106
        self.testcase = testcase
87
107
        self.expect_auth = expect_auth
 
108
        self._connection = (None, None)
88
109
 
89
110
    def make_connection(self, host):
90
111
        host, http_headers, x509 = self.get_host_info(host)
133
154
 
134
155
 
135
156
class TestBranchRegistration(TestCaseWithTransport):
136
 
    SAMPLE_URL = 'http://bazaar-vcs.org/bzr/bzr.dev/'
137
 
    SAMPLE_OWNER = 'jhacker@foo.com'
138
 
    SAMPLE_BRANCH_ID = 'bzr.dev'
139
157
 
140
158
    def setUp(self):
141
159
        super(TestBranchRegistration, self).setUp()
142
160
        # make sure we have a reproducible standard environment
143
 
        self._captureVar('BZR_LP_XMLRPC_URL', None)
 
161
        self.overrideEnv('BZR_LP_XMLRPC_URL', None)
144
162
 
145
163
    def test_register_help(self):
146
164
        """register-branch accepts --help"""
175
193
        self.assertEquals(out, 'Branch registered.\n')
176
194
 
177
195
    def test_onto_transport(self):
178
 
        """Test how the request is sent by transmitting across a mock Transport"""
 
196
        """How the request is sent by transmitting across a mock Transport"""
179
197
        # use a real transport, but intercept at the http/xml layer
180
198
        transport = InstrumentedXMLRPCTransport(self, expect_auth=True)
181
199
        service = LaunchpadService(transport)
200
218
        self.assertTrue(transport.got_request)
201
219
 
202
220
    def test_onto_transport_unauthenticated(self):
203
 
        """Test how an unauthenticated request is transmitted across a mock Transport"""
 
221
        """An unauthenticated request is transmitted across a mock Transport"""
204
222
        transport = InstrumentedXMLRPCTransport(self, expect_auth=False)
205
223
        service = LaunchpadService(transport)
206
224
        resolve = ResolveLaunchpadPathRequest('bzr')
299
317
    def setUp(self):
300
318
        super(TestGatherUserCredentials, self).setUp()
301
319
        # make sure we have a reproducible standard environment
302
 
        self._captureVar('BZR_LP_XMLRPC_URL', None)
 
320
        self.overrideEnv('BZR_LP_XMLRPC_URL', None)
303
321
 
304
322
    def test_gather_user_credentials_has_password(self):
305
323
        service = LaunchpadService()