/brz/remove-bazaar

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