~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-11-08 11:35:49 UTC
  • mfrom: (5531.1.3 662509-ignore-empty)
  • Revision ID: pqm@pqm.ubuntu.com-20101108113549-e4mhhq2fe1i0etbf
(vila) Add an option to accept any output from commands in shell-like tests.
 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006 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
18
19
from StringIO import StringIO
19
20
import urlparse
20
21
import xmlrpclib
21
22
 
22
23
from bzrlib import (
23
24
    config,
 
25
    osutils,
24
26
    tests,
25
27
    ui,
26
28
    )
27
 
from bzrlib.tests import TestCaseWithTransport
 
29
from bzrlib.tests import TestCaseWithTransport, TestSkipped
28
30
 
29
31
# local import
30
32
from bzrlib.plugins.launchpad.lp_registration import (
59
61
        """
60
62
        return (200, 'OK', [])
61
63
 
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, headers, body):
71
 
                self.status = status
72
 
                self.reason = reason
73
 
                self.headers = headers
74
 
                self.body = body
75
 
 
76
 
            def read(self, size=-1):
77
 
                return self.body.read(size)
78
 
 
79
 
        return FakeHttpResponse(200, 'OK', [], self.getfile())
80
 
 
81
64
    def getfile(self):
82
65
        """Return a fake file containing the response content."""
83
66
        return StringIO('''\
102
85
    def __init__(self, testcase, expect_auth):
103
86
        self.testcase = testcase
104
87
        self.expect_auth = expect_auth
105
 
        self._connection = (None, None)
106
88
 
107
89
    def make_connection(self, host):
108
90
        host, http_headers, x509 = self.get_host_info(host)
151
133
 
152
134
 
153
135
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'
154
139
 
155
140
    def setUp(self):
156
141
        super(TestBranchRegistration, self).setUp()
157
142
        # make sure we have a reproducible standard environment
158
 
        self.overrideEnv('BZR_LP_XMLRPC_URL', None)
 
143
        self._captureVar('BZR_LP_XMLRPC_URL', None)
159
144
 
160
145
    def test_register_help(self):
161
146
        """register-branch accepts --help"""
190
175
        self.assertEquals(out, 'Branch registered.\n')
191
176
 
192
177
    def test_onto_transport(self):
193
 
        """How the request is sent by transmitting across a mock Transport"""
 
178
        """Test how the request is sent by transmitting across a mock Transport"""
194
179
        # use a real transport, but intercept at the http/xml layer
195
180
        transport = InstrumentedXMLRPCTransport(self, expect_auth=True)
196
181
        service = LaunchpadService(transport)
215
200
        self.assertTrue(transport.got_request)
216
201
 
217
202
    def test_onto_transport_unauthenticated(self):
218
 
        """An unauthenticated request is transmitted across a mock Transport"""
 
203
        """Test how an unauthenticated request is transmitted across a mock Transport"""
219
204
        transport = InstrumentedXMLRPCTransport(self, expect_auth=False)
220
205
        service = LaunchpadService(transport)
221
206
        resolve = ResolveLaunchpadPathRequest('bzr')
314
299
    def setUp(self):
315
300
        super(TestGatherUserCredentials, self).setUp()
316
301
        # make sure we have a reproducible standard environment
317
 
        self.overrideEnv('BZR_LP_XMLRPC_URL', None)
 
302
        self._captureVar('BZR_LP_XMLRPC_URL', None)
318
303
 
319
304
    def test_gather_user_credentials_has_password(self):
320
305
        service = LaunchpadService()