/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.7 by John Arbash Meinel
Merge in the bzr.dev 5582
1
# Copyright (C) 2007-2011 Canonical Ltd
2245.8.1 by Martin Pool
Start adding tests for launchpad indirection
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
2245.8.1 by Martin Pool
Start adding tests for launchpad indirection
16
3251.4.3 by Aaron Bentley
More renames and cleanups
17
"""Tests for directory lookup through Launchpad.net"""
2245.8.1 by Martin Pool
Start adding tests for launchpad indirection
18
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
19
import os
2898.4.4 by James Henstridge
Changes to account for modifications to the XMLRPC API.
20
import xmlrpclib
21
2245.8.3 by Martin Pool
Start adding indirection transport
22
from bzrlib import (
2245.8.4 by Martin Pool
lp:/// indirection works
23
    errors,
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
24
    tests,
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
25
    transport,
2245.8.3 by Martin Pool
Start adding indirection transport
26
    )
2898.4.17 by James Henstridge
Add a test that the redirect actually occurs when opening an lp: URL.
27
from bzrlib.branch import Branch
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
28
from bzrlib.directory_service import directories
3777.1.18 by Aaron Bentley
Fix None handling wrt auth upgrades
29
from bzrlib.tests import (
30
    TestCaseInTempDir,
31
    TestCaseWithMemoryTransport
32
)
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
33
from bzrlib.plugins.launchpad import (
34
    _register_directory,
35
    lp_registration,
36
    )
3251.4.3 by Aaron Bentley
More renames and cleanups
37
from bzrlib.plugins.launchpad.lp_directory import (
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
38
    LaunchpadDirectory)
5361.1.1 by John Arbash Meinel
Handle a simple ~ in lp: urls.
39
from bzrlib.plugins.launchpad.account import get_lp_login, set_lp_login
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
40
from bzrlib.tests import http_server
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
41
42
43
def load_tests(standard_tests, module, loader):
44
    result = loader.suiteClass()
45
    t_tests, remaining_tests = tests.split_suite_by_condition(
46
        standard_tests, tests.condition_isinstance((
4776.2.6 by Vincent Ladeuil
Fixed as per review comments.
47
                TestXMLRPCTransport,
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
48
                )))
49
    transport_scenarios = [
50
        ('http', dict(server_class=PreCannedHTTPServer,)),
51
        ]
52
    if tests.HTTPSServerFeature.available():
53
        transport_scenarios.append(
54
            ('https', dict(server_class=PreCannedHTTPSServer,)),
55
            )
56
    tests.multiply_tests(t_tests, transport_scenarios, result)
57
58
    # No parametrization for the remaining tests
59
    result.addTests(remaining_tests)
60
61
    return result
2898.4.3 by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL.
62
63
64
class FakeResolveFactory(object):
65
    def __init__(self, test, expected_path, result):
66
        self._test = test
67
        self._expected_path = expected_path
68
        self._result = result
69
70
    def __call__(self, path):
71
        self._test.assertEqual(self._expected_path, path)
72
        return self
73
74
    def submit(self, service):
3193.5.2 by Tim Penhey
Updated the tests to handle unknown launchpad instances.
75
        self._service_url = service.service_url
2898.4.3 by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL.
76
        return self._result
2245.8.1 by Martin Pool
Start adding tests for launchpad indirection
77
2245.8.7 by Martin Pool
small review cleanups
78
3777.1.18 by Aaron Bentley
Fix None handling wrt auth upgrades
79
class DirectoryUrlTests(TestCaseInTempDir):
3251.4.3 by Aaron Bentley
More renames and cleanups
80
    """Tests for branch urls through Launchpad.net directory"""
2245.8.1 by Martin Pool
Start adding tests for launchpad indirection
81
2245.8.5 by Martin Pool
Add short-form lp:PRODUCT url form
82
    def test_short_form(self):
83
        """A launchpad url should map to a http url"""
2898.4.3 by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL.
84
        factory = FakeResolveFactory(
2898.4.4 by James Henstridge
Changes to account for modifications to the XMLRPC API.
85
            self, 'apt', dict(urls=[
86
                    'http://bazaar.launchpad.net/~apt/apt/devel']))
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
87
        directory = LaunchpadDirectory()
2898.4.8 by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets
88
        self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
89
                          directory._resolve('lp:apt', factory))
3193.5.2 by Tim Penhey
Updated the tests to handle unknown launchpad instances.
90
        # Make sure that resolve went to the production server.
5243.1.1 by Martin
Use the production server in the launchpad plugin rather than edge
91
        self.assertEquals('https://xmlrpc.launchpad.net/bazaar/',
3193.5.2 by Tim Penhey
Updated the tests to handle unknown launchpad instances.
92
                          factory._service_url)
93
5615.2.1 by Jelmer Vernooij
Support the 'qastaging' instance of Launchpad.
94
    def test_qastaging(self):
95
        """A launchpad url should map to a http url"""
96
        factory = FakeResolveFactory(
97
            self, 'apt', dict(urls=[
98
                    'http://bazaar.qastaging.launchpad.net/~apt/apt/devel']))
99
        url = 'lp://qastaging/apt'
100
        directory = LaunchpadDirectory()
101
        self.assertEquals('http://bazaar.qastaging.launchpad.net/~apt/apt/devel',
102
                          directory._resolve(url, factory))
103
        # Make sure that resolve went to the qastaging server.
104
        self.assertEquals('https://xmlrpc.qastaging.launchpad.net/bazaar/',
105
                          factory._service_url)
106
3193.5.2 by Tim Penhey
Updated the tests to handle unknown launchpad instances.
107
    def test_staging(self):
108
        """A launchpad url should map to a http url"""
109
        factory = FakeResolveFactory(
110
            self, 'apt', dict(urls=[
111
                    'http://bazaar.staging.launchpad.net/~apt/apt/devel']))
112
        url = 'lp://staging/apt'
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
113
        directory = LaunchpadDirectory()
3193.5.2 by Tim Penhey
Updated the tests to handle unknown launchpad instances.
114
        self.assertEquals('http://bazaar.staging.launchpad.net/~apt/apt/devel',
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
115
                          directory._resolve(url, factory))
3193.5.2 by Tim Penhey
Updated the tests to handle unknown launchpad instances.
116
        # Make sure that resolve went to the staging server.
117
        self.assertEquals('https://xmlrpc.staging.launchpad.net/bazaar/',
118
                          factory._service_url)
2245.8.5 by Martin Pool
Add short-form lp:PRODUCT url form
119
3251.4.3 by Aaron Bentley
More renames and cleanups
120
    def test_url_from_directory(self):
2245.8.3 by Martin Pool
Start adding indirection transport
121
        """A launchpad url should map to a http url"""
2898.4.3 by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL.
122
        factory = FakeResolveFactory(
2898.4.4 by James Henstridge
Changes to account for modifications to the XMLRPC API.
123
            self, 'apt', dict(urls=[
124
                    'http://bazaar.launchpad.net/~apt/apt/devel']))
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
125
        directory = LaunchpadDirectory()
2898.4.8 by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets
126
        self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
127
                          directory._resolve('lp:///apt', factory))
2898.4.3 by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL.
128
3251.4.3 by Aaron Bentley
More renames and cleanups
129
    def test_directory_skip_bad_schemes(self):
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
130
        factory = FakeResolveFactory(
131
            self, 'apt', dict(urls=[
132
                    'bad-scheme://bazaar.launchpad.net/~apt/apt/devel',
133
                    'http://bazaar.launchpad.net/~apt/apt/devel',
134
                    'http://another/location']))
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
135
        directory = LaunchpadDirectory()
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
136
        self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
137
                          directory._resolve('lp:///apt', factory))
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
138
3251.4.3 by Aaron Bentley
More renames and cleanups
139
    def test_directory_no_matching_schemes(self):
2898.4.3 by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL.
140
        # If the XMLRPC call does not return any protocols we support,
141
        # invalidURL is raised.
142
        factory = FakeResolveFactory(
2898.4.4 by James Henstridge
Changes to account for modifications to the XMLRPC API.
143
            self, 'apt', dict(urls=[
144
                    'bad-scheme://bazaar.launchpad.net/~apt/apt/devel']))
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
145
        directory = LaunchpadDirectory()
2898.4.11 by James Henstridge
Switch back to RedirectRequested based implementation.
146
        self.assertRaises(errors.InvalidURL,
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
147
                          directory._resolve, 'lp:///apt', factory)
2898.4.4 by James Henstridge
Changes to account for modifications to the XMLRPC API.
148
3251.4.3 by Aaron Bentley
More renames and cleanups
149
    def test_directory_fault(self):
2898.4.4 by James Henstridge
Changes to account for modifications to the XMLRPC API.
150
        # Test that XMLRPC faults get converted to InvalidURL errors.
151
        factory = FakeResolveFactory(self, 'apt', None)
152
        def submit(service):
153
            raise xmlrpclib.Fault(42, 'something went wrong')
154
        factory.submit = submit
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
155
        directory = LaunchpadDirectory()
2898.4.11 by James Henstridge
Switch back to RedirectRequested based implementation.
156
        self.assertRaises(errors.InvalidURL,
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
157
                          directory._resolve, 'lp:///apt', factory)
2245.8.4 by Martin Pool
lp:/// indirection works
158
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
159
    def test_skip_bzr_ssh_launchpad_net_when_anonymous(self):
160
        # Test that bzr+ssh://bazaar.launchpad.net gets skipped if
161
        # Bazaar does not know the user's Launchpad ID:
162
        self.assertEqual(None, get_lp_login())
163
        factory = FakeResolveFactory(
164
            self, 'apt', dict(urls=[
165
                    'bzr+ssh://bazaar.launchpad.net/~apt/apt/devel',
166
                    'http://bazaar.launchpad.net/~apt/apt/devel']))
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
167
        directory = LaunchpadDirectory()
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
168
        self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
169
                          directory._resolve('lp:///apt', factory))
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
170
3031.2.2 by jml at canonical
Failing test for skipping SFTP.
171
    def test_skip_sftp_launchpad_net_when_anonymous(self):
172
        # Test that sftp://bazaar.launchpad.net gets skipped if
173
        # Bazaar does not know the user's Launchpad ID:
174
        self.assertEqual(None, get_lp_login())
175
        factory = FakeResolveFactory(
176
            self, 'apt', dict(urls=[
177
                    'sftp://bazaar.launchpad.net/~apt/apt/devel',
178
                    'http://bazaar.launchpad.net/~apt/apt/devel']))
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
179
        directory = LaunchpadDirectory()
3031.2.2 by jml at canonical
Failing test for skipping SFTP.
180
        self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
181
                          directory._resolve('lp:///apt', factory))
3031.2.2 by jml at canonical
Failing test for skipping SFTP.
182
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
183
    def test_rewrite_bzr_ssh_launchpad_net(self):
184
        # Test that bzr+ssh URLs get rewritten to include the user's
185
        # Launchpad ID (assuming we know the Launchpad ID).
186
        factory = FakeResolveFactory(
187
            self, 'apt', dict(urls=[
188
                    'bzr+ssh://bazaar.launchpad.net/~apt/apt/devel',
189
                    'http://bazaar.launchpad.net/~apt/apt/devel']))
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
190
        directory = LaunchpadDirectory()
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
191
        self.assertEquals(
3777.1.21 by Aaron Bentley
Stop including usernames in resolved lp: urls
192
            'bzr+ssh://bazaar.launchpad.net/~apt/apt/devel',
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
193
            directory._resolve('lp:///apt', factory, _lp_login='username'))
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
194
195
    def test_no_rewrite_of_other_bzr_ssh(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
196
        # Test that we don't rewrite bzr+ssh URLs for other
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
197
        self.assertEqual(None, get_lp_login())
198
        factory = FakeResolveFactory(
199
            self, 'apt', dict(urls=[
200
                    'bzr+ssh://example.com/~apt/apt/devel',
201
                    'http://bazaar.launchpad.net/~apt/apt/devel']))
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
202
        directory = LaunchpadDirectory()
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
203
        self.assertEquals('bzr+ssh://example.com/~apt/apt/devel',
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
204
                          directory._resolve('lp:///apt', factory))
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
205
2245.8.4 by Martin Pool
lp:/// indirection works
206
    # TODO: check we get an error if the url is unreasonable
3251.4.3 by Aaron Bentley
More renames and cleanups
207
    def test_error_for_bad_url(self):
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
208
        directory = LaunchpadDirectory()
2245.8.4 by Martin Pool
lp:/// indirection works
209
        self.assertRaises(errors.InvalidURL,
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
210
            directory._resolve, 'lp://ratotehunoahu')
2898.4.12 by James Henstridge
Add tests that redirects get issued by appropriate transport methods.
211
5361.1.1 by John Arbash Meinel
Handle a simple ~ in lp: urls.
212
    def test_resolve_tilde_to_user(self):
213
        factory = FakeResolveFactory(
214
            self, '~username/apt/test', dict(urls=[
215
                    'bzr+ssh://bazaar.launchpad.net/~username/apt/test']))
216
        directory = LaunchpadDirectory()
217
        self.assertEquals(
218
            'bzr+ssh://bazaar.launchpad.net/~username/apt/test',
219
            directory._resolve('lp:~/apt/test', factory, _lp_login='username'))
220
        # Should also happen when the login is just set by config
221
        set_lp_login('username')
222
        self.assertEquals(
223
            'bzr+ssh://bazaar.launchpad.net/~username/apt/test',
224
            directory._resolve('lp:~/apt/test', factory))
225
226
    def test_tilde_fails_no_login(self):
227
        factory = FakeResolveFactory(
228
            self, '~username/apt/test', dict(urls=[
229
                    'bzr+ssh://bazaar.launchpad.net/~username/apt/test']))
230
        self.assertIs(None, get_lp_login())
231
        directory = LaunchpadDirectory()
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
232
        self.assertRaises(errors.InvalidURL,
233
                          directory._resolve, 'lp:~/apt/test', factory)
5361.1.1 by John Arbash Meinel
Handle a simple ~ in lp: urls.
234
2898.4.17 by James Henstridge
Add a test that the redirect actually occurs when opening an lp: URL.
235
3251.4.3 by Aaron Bentley
More renames and cleanups
236
class DirectoryOpenBranchTests(TestCaseWithMemoryTransport):
2898.4.17 by James Henstridge
Add a test that the redirect actually occurs when opening an lp: URL.
237
3251.4.3 by Aaron Bentley
More renames and cleanups
238
    def test_directory_open_branch(self):
2898.4.17 by James Henstridge
Add a test that the redirect actually occurs when opening an lp: URL.
239
        # Test that opening an lp: branch redirects to the real location.
240
        target_branch = self.make_branch('target')
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
241
        class FooService(object):
242
            """A directory service that maps the name to a FILE url"""
243
244
            def look_up(self, name, url):
245
                if 'lp:///apt' == url:
246
                    return target_branch.base.rstrip('/')
3251.4.2 by Aaron Bentley
Clean up Launchpad directory service code
247
                return '!unexpected look_up value!'
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
248
249
        directories.remove('lp:')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
250
        directories.remove('ubuntu:')
251
        directories.remove('debianlp:')
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
252
        directories.register('lp:', FooService, 'Map lp URLs to local urls')
3251.4.2 by Aaron Bentley
Clean up Launchpad directory service code
253
        self.addCleanup(_register_directory)
4985.2.1 by Vincent Ladeuil
Deploy addAttrCleanup on the whole test suite.
254
        self.addCleanup(directories.remove, 'lp:')
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
255
        t = transport.get_transport('lp:///apt')
256
        branch = Branch.open_from_transport(t)
2898.4.17 by James Henstridge
Add a test that the redirect actually occurs when opening an lp: URL.
257
        self.assertEqual(target_branch.base, branch.base)
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
258
259
260
class PredefinedRequestHandler(http_server.TestingHTTPRequestHandler):
261
    """Request handler for a unique and pre-defined request.
262
263
    The only thing we care about here is that we receive a connection. But
264
    since we want to dialog with a real http client, we have to send it correct
265
    responses.
266
267
    We expect to receive a *single* request nothing more (and we won't even
268
    check what request it is), the tests will recognize us from our response.
269
    """
270
271
    def handle_one_request(self):
272
        tcs = self.server.test_case_server
273
        requestline = self.rfile.readline()
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
274
        self.MessageClass(self.rfile, 0)
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
275
        if requestline.startswith('POST'):
276
            # The body should be a single line (or we don't know where it ends
277
            # and we don't want to issue a blocking read)
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
278
            self.rfile.readline()
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
279
280
        self.wfile.write(tcs.canned_response)
281
4776.2.6 by Vincent Ladeuil
Fixed as per review comments.
282
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
283
class PreCannedServerMixin(object):
284
285
    def __init__(self):
286
        super(PreCannedServerMixin, self).__init__(
287
            request_handler=PredefinedRequestHandler)
288
        # Bytes read and written by the server
289
        self.bytes_read = 0
290
        self.bytes_written = 0
291
        self.canned_response = None
292
293
294
class PreCannedHTTPServer(PreCannedServerMixin, http_server.HttpServer):
295
    pass
296
297
298
if tests.HTTPSServerFeature.available():
299
    from bzrlib.tests import https_server
300
    class PreCannedHTTPSServer(PreCannedServerMixin, https_server.HTTPSServer):
301
        pass
302
303
4776.2.6 by Vincent Ladeuil
Fixed as per review comments.
304
class TestXMLRPCTransport(tests.TestCase):
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
305
306
    # set by load_tests
307
    server_class = None
308
309
    def setUp(self):
310
        tests.TestCase.setUp(self)
311
        self.server = self.server_class()
4934.3.3 by Martin Pool
Rename Server.setUp to Server.start_server
312
        self.server.start_server()
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
313
        # Ensure we don't clobber env
5570.3.6 by Vincent Ladeuil
Get rid of all _captureVar() calls, no test failures, pfew.
314
        self.overrideEnv('BZR_LP_XMLRPC_URL', None)
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
315
316
    def tearDown(self):
4934.3.1 by Martin Pool
Rename Server.tearDown to .stop_server
317
        self.server.stop_server()
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
318
        tests.TestCase.tearDown(self)
319
320
    def set_canned_response(self, server, path):
321
        response_format = '''HTTP/1.1 200 OK\r
322
Date: Tue, 11 Jul 2006 04:32:56 GMT\r
323
Server: Apache/2.0.54 (Fedora)\r
324
Last-Modified: Sun, 23 Apr 2006 19:35:20 GMT\r
325
ETag: "56691-23-38e9ae00"\r
326
Accept-Ranges: bytes\r
327
Content-Length: %(length)d\r
328
Connection: close\r
329
Content-Type: text/plain; charset=UTF-8\r
330
\r
331
<?xml version='1.0'?>
332
<methodResponse>
333
<params>
334
<param>
335
<value><struct>
336
<member>
337
<name>urls</name>
338
<value><array><data>
339
<value><string>bzr+ssh://bazaar.launchpad.net/%(path)s</string></value>
340
<value><string>http://bazaar.launchpad.net/%(path)s</string></value>
341
</data></array></value>
342
</member>
343
</struct></value>
344
</param>
345
</params>
346
</methodResponse>
347
'''
348
        length = 334 + 2 * len(path)
349
        server.canned_response = response_format % dict(length=length,
350
                                                        path=path)
351
4776.2.3 by Vincent Ladeuil
Add NEWS entry.
352
    def do_request(self, server_url):
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
353
        os.environ['BZR_LP_XMLRPC_URL'] = self.server.get_url()
354
        service = lp_registration.LaunchpadService()
355
        resolve = lp_registration.ResolveLaunchpadPathRequest('bzr')
356
        result = resolve.submit(service)
4776.2.3 by Vincent Ladeuil
Add NEWS entry.
357
        return result
358
359
    def test_direct_request(self):
360
        self.set_canned_response(self.server, '~bzr-pqm/bzr/bzr.dev')
361
        result = self.do_request(self.server.get_url())
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
362
        urls = result.get('urls', None)
363
        self.assertIsNot(None, urls)
364
        self.assertEquals(
365
            ['bzr+ssh://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev',
366
             'http://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev'],
367
            urls)
4776.2.3 by Vincent Ladeuil
Add NEWS entry.
368
    # FIXME: we need to test with a real proxy, I can't find a way so simulate
369
    # CONNECT without leaving one server hanging the test :-/ Since that maybe
370
    # related to the leaking tests problems, I'll punt for now -- vila 20091030
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
371
372
373
class TestDebuntuExpansions(TestCaseInTempDir):
374
    """Test expansions for ubuntu: and debianlp: schemes."""
375
376
    def setUp(self):
5558.1.1 by Vincent Ladeuil
Catch the fugitive TestDebuntuExpansions tests and bring them back in the isolation jail
377
        super(TestDebuntuExpansions, self).setUp()
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
378
        self.directory = LaunchpadDirectory()
379
380
    def _make_factory(self, package='foo', distro='ubuntu', series=None):
381
        if series is None:
382
            path = '%s/%s' % (distro, package)
383
            url_suffix = '~branch/%s/%s' % (distro, package)
384
        else:
385
            path = '%s/%s/%s' % (distro, series, package)
386
            url_suffix = '~branch/%s/%s/%s' % (distro, series, package)
387
        return FakeResolveFactory(
388
            self, path, dict(urls=[
389
                'http://bazaar.launchpad.net/' + url_suffix]))
390
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
391
    def assertURL(self, expected_url, shortcut, package='foo', distro='ubuntu',
392
                  series=None):
393
        factory = self._make_factory(package=package, distro=distro,
394
                                     series=series)
395
        self.assertEqual('http://bazaar.launchpad.net/~branch/' + expected_url,
396
                         self.directory._resolve(shortcut, factory))
397
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
398
    # Bogus distro.
399
400
    def test_bogus_distro(self):
401
        self.assertRaises(errors.InvalidURL,
402
                          self.directory._resolve, 'gentoo:foo')
403
404
    def test_trick_bogus_distro_u(self):
405
        self.assertRaises(errors.InvalidURL,
406
                          self.directory._resolve, 'utube:foo')
407
408
    def test_trick_bogus_distro_d(self):
409
        self.assertRaises(errors.InvalidURL,
410
                          self.directory._resolve, 'debuntu:foo')
411
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
412
    def test_missing_ubuntu_distroseries_without_project(self):
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
413
        # Launchpad does not hold source packages for Intrepid.  Missing or
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
414
        # bogus distroseries with no project name is treated like a project.
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
415
        self.assertURL('ubuntu/intrepid', 'ubuntu:intrepid', package='intrepid')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
416
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
417
    def test_missing_ubuntu_distroseries_with_project(self):
418
        # Launchpad does not hold source packages for Intrepid.  Missing or
419
        # bogus distroseries with a project name is treated like an unknown
420
        # series (i.e. we keep it verbatim).
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
421
        self.assertURL('ubuntu/intrepid/foo',
422
                       'ubuntu:intrepid/foo', series='intrepid')
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
423
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
424
    def test_missing_debian_distroseries(self):
425
        # Launchpad does not hold source packages for unstable.  Missing or
426
        # bogus distroseries is treated like a project.
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
427
        self.assertURL('debian/sid',
428
                       'debianlp:sid', package='sid', distro='debian')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
429
430
    # Ubuntu Default distro series.
431
432
    def test_ubuntu_default_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
433
        self.assertURL('ubuntu/foo', 'ubuntu:foo')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
434
5462.4.2 by Barry Warsaw
Might as well support natty.
435
    def test_ubuntu_natty_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
436
        self.assertURL('ubuntu/natty/foo', 'ubuntu:natty/foo', series='natty')
5462.4.2 by Barry Warsaw
Might as well support natty.
437
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
438
    def test_ubuntu_n_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
439
        self.assertURL('ubuntu/natty/foo', 'ubuntu:n/foo', series='natty')
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
440
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
441
    def test_ubuntu_maverick_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
442
        self.assertURL('ubuntu/maverick/foo', 'ubuntu:maverick/foo',
443
                       series='maverick')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
444
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
445
    def test_ubuntu_m_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
446
        self.assertURL('ubuntu/maverick/foo', 'ubuntu:m/foo', series='maverick')
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
447
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
448
    def test_ubuntu_lucid_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
449
        self.assertURL('ubuntu/lucid/foo', 'ubuntu:lucid/foo', series='lucid')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
450
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
451
    def test_ubuntu_l_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
452
        self.assertURL('ubuntu/lucid/foo', 'ubuntu:l/foo', series='lucid')
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
453
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
454
    def test_ubuntu_karmic_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
455
        self.assertURL('ubuntu/karmic/foo', 'ubuntu:karmic/foo',
456
                       series='karmic')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
457
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
458
    def test_ubuntu_k_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
459
        self.assertURL('ubuntu/karmic/foo', 'ubuntu:k/foo', series='karmic')
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
460
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
461
    def test_ubuntu_jaunty_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
462
        self.assertURL('ubuntu/jaunty/foo', 'ubuntu:jaunty/foo',
463
                       series='jaunty')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
464
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
465
    def test_ubuntu_j_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
466
        self.assertURL('ubuntu/jaunty/foo', 'ubuntu:j/foo', series='jaunty')
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
467
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
468
    def test_ubuntu_hardy_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
469
        self.assertURL('ubuntu/hardy/foo', 'ubuntu:hardy/foo', series='hardy')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
470
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
471
    def test_ubuntu_h_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
472
        self.assertURL('ubuntu/hardy/foo', 'ubuntu:h/foo', series='hardy')
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
473
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
474
    def test_ubuntu_dapper_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
475
        self.assertURL('ubuntu/dapper/foo', 'ubuntu:dapper/foo',
476
                       series='dapper')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
477
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
478
    def test_ubuntu_d_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
479
        self.assertURL('ubuntu/dapper/foo', 'ubuntu:d/foo', series='dapper')
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
480
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
481
    # Debian default distro series.
482
483
    def test_debian_default_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
484
        self.assertURL('debian/foo', 'debianlp:foo', distro='debian')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
485
486
    def test_debian_squeeze_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
487
        self.assertURL('debian/squeeze/foo', 'debianlp:squeeze/foo',
488
                       distro='debian', series='squeeze')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
489
490
    def test_debian_lenny_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
491
        self.assertURL('debian/lenny/foo', 'debianlp:lenny/foo',
492
                       distro='debian', series='lenny')