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