93
92
"""Tests for branch urls that we try to pass through local resolution."""
95
94
def assertResolve(self, expected, url, submitted=False):
96
path = url[url.index(':')+1:].lstrip('/')
95
path = url[url.index(':') + 1:].lstrip('/')
97
96
factory = FakeResolveFactory(self, path,
98
dict(urls=['bzr+ssh://fake-resolved']))
97
dict(urls=['bzr+ssh://fake-resolved']))
99
98
directory = LaunchpadDirectory()
100
99
self.assertEqual(expected,
101
directory._resolve(url, factory, _lp_login='user'))
100
directory._resolve(url, factory, _lp_login='user'))
102
101
# We are testing local resolution, and the fallback when necessary.
103
102
self.assertEqual(submitted, factory._submitted)
233
237
"""A launchpad url should map to a http url"""
234
238
factory = FakeResolveFactory(
235
239
self, 'apt', dict(urls=[
236
'http://bazaar.launchpad.net/~apt/apt/devel']))
240
'http://bazaar.launchpad.net/~apt/apt/devel']))
237
241
directory = LaunchpadDirectory()
238
242
self.assertEqual('http://bazaar.launchpad.net/~apt/apt/devel',
239
directory._resolve('lp:apt', factory))
243
directory._resolve('lp:apt', factory))
240
244
# Make sure that resolve went to the production server.
241
245
self.assertEqual('https://xmlrpc.launchpad.net/bazaar/',
242
factory._service_url)
246
factory._service_url)
244
248
def test_qastaging(self):
245
249
"""A launchpad url should map to a http url"""
246
250
factory = FakeResolveFactory(
247
251
self, 'apt', dict(urls=[
248
'http://bazaar.qastaging.launchpad.net/~apt/apt/devel']))
252
'http://bazaar.qastaging.launchpad.net/~apt/apt/devel']))
249
253
url = 'lp://qastaging/apt'
250
254
directory = LaunchpadDirectory()
251
255
self.assertEqual('http://bazaar.qastaging.launchpad.net/~apt/apt/devel',
252
directory._resolve(url, factory))
256
directory._resolve(url, factory))
253
257
# Make sure that resolve went to the qastaging server.
254
258
self.assertEqual('https://xmlrpc.qastaging.launchpad.net/bazaar/',
255
factory._service_url)
259
factory._service_url)
257
261
def test_staging(self):
258
262
"""A launchpad url should map to a http url"""
259
263
factory = FakeResolveFactory(
260
264
self, 'apt', dict(urls=[
261
'http://bazaar.staging.launchpad.net/~apt/apt/devel']))
265
'http://bazaar.staging.launchpad.net/~apt/apt/devel']))
262
266
url = 'lp://staging/apt'
263
267
directory = LaunchpadDirectory()
264
268
self.assertEqual('http://bazaar.staging.launchpad.net/~apt/apt/devel',
265
directory._resolve(url, factory))
269
directory._resolve(url, factory))
266
270
# Make sure that resolve went to the staging server.
267
271
self.assertEqual('https://xmlrpc.staging.launchpad.net/bazaar/',
268
factory._service_url)
272
factory._service_url)
270
274
def test_url_from_directory(self):
271
275
"""A launchpad url should map to a http url"""
272
276
factory = FakeResolveFactory(
273
277
self, 'apt', dict(urls=[
274
'http://bazaar.launchpad.net/~apt/apt/devel']))
278
'http://bazaar.launchpad.net/~apt/apt/devel']))
275
279
directory = LaunchpadDirectory()
276
280
self.assertEqual('http://bazaar.launchpad.net/~apt/apt/devel',
277
directory._resolve('lp:///apt', factory))
281
directory._resolve('lp:///apt', factory))
279
283
def test_directory_skip_bad_schemes(self):
280
284
factory = FakeResolveFactory(
281
285
self, 'apt', dict(urls=[
282
'bad-scheme://bazaar.launchpad.net/~apt/apt/devel',
283
'http://bazaar.launchpad.net/~apt/apt/devel',
284
'http://another/location']))
286
'bad-scheme://bazaar.launchpad.net/~apt/apt/devel',
287
'http://bazaar.launchpad.net/~apt/apt/devel',
288
'http://another/location']))
285
289
directory = LaunchpadDirectory()
286
290
self.assertEqual('http://bazaar.launchpad.net/~apt/apt/devel',
287
directory._resolve('lp:///apt', factory))
291
directory._resolve('lp:///apt', factory))
289
293
def test_directory_no_matching_schemes(self):
290
294
# If the XMLRPC call does not return any protocols we support,
291
295
# invalidURL is raised.
292
296
factory = FakeResolveFactory(
293
297
self, 'apt', dict(urls=[
294
'bad-scheme://bazaar.launchpad.net/~apt/apt/devel']))
298
'bad-scheme://bazaar.launchpad.net/~apt/apt/devel']))
295
299
directory = LaunchpadDirectory()
296
300
self.assertRaises(lp_registration.InvalidURL,
297
301
directory._resolve, 'lp:///apt', factory)
312
317
self.assertEqual(None, get_lp_login())
313
318
factory = FakeResolveFactory(
314
319
self, 'apt', dict(urls=[
315
'bzr+ssh://bazaar.launchpad.net/~apt/apt/devel',
316
'http://bazaar.launchpad.net/~apt/apt/devel']))
320
'bzr+ssh://bazaar.launchpad.net/~apt/apt/devel',
321
'http://bazaar.launchpad.net/~apt/apt/devel']))
317
322
directory = LaunchpadDirectory()
318
323
self.assertEqual('http://bazaar.launchpad.net/~apt/apt/devel',
319
directory._resolve('lp:///apt', factory))
324
directory._resolve('lp:///apt', factory))
321
326
def test_skip_sftp_launchpad_net_when_anonymous(self):
322
327
# Test that sftp://bazaar.launchpad.net gets skipped if
324
329
self.assertEqual(None, get_lp_login())
325
330
factory = FakeResolveFactory(
326
331
self, 'apt', dict(urls=[
327
'sftp://bazaar.launchpad.net/~apt/apt/devel',
328
'http://bazaar.launchpad.net/~apt/apt/devel']))
332
'sftp://bazaar.launchpad.net/~apt/apt/devel',
333
'http://bazaar.launchpad.net/~apt/apt/devel']))
329
334
directory = LaunchpadDirectory()
330
335
self.assertEqual('http://bazaar.launchpad.net/~apt/apt/devel',
331
directory._resolve('lp:///apt', factory))
336
directory._resolve('lp:///apt', factory))
333
338
def test_with_login_avoid_resolve_factory(self):
334
339
# Test that bzr+ssh URLs get rewritten to include the user's
335
340
# Launchpad ID (assuming we know the Launchpad ID).
336
341
factory = FakeResolveFactory(
337
342
self, 'apt', dict(urls=[
338
'bzr+ssh://my-super-custom/special/devel',
339
'http://bazaar.launchpad.net/~apt/apt/devel']))
343
'bzr+ssh://my-super-custom/special/devel',
344
'http://bazaar.launchpad.net/~apt/apt/devel']))
340
345
directory = LaunchpadDirectory()
341
346
self.assertEqual(
342
347
'bzr+ssh://bazaar.launchpad.net/+branch/apt',
347
352
self.assertEqual(None, get_lp_login())
348
353
factory = FakeResolveFactory(
349
354
self, 'apt', dict(urls=[
350
'bzr+ssh://example.com/~apt/apt/devel',
351
'http://bazaar.launchpad.net/~apt/apt/devel']))
355
'bzr+ssh://example.com/~apt/apt/devel',
356
'http://bazaar.launchpad.net/~apt/apt/devel']))
352
357
directory = LaunchpadDirectory()
353
358
self.assertEqual('bzr+ssh://example.com/~apt/apt/devel',
354
directory._resolve('lp:///apt', factory))
359
directory._resolve('lp:///apt', factory))
356
361
# TODO: check we get an error if the url is unreasonable
357
362
def test_error_for_bad_url(self):
358
363
directory = LaunchpadDirectory()
359
364
self.assertRaises(lp_registration.InvalidURL,
360
directory._resolve, 'lp://ratotehunoahu')
365
directory._resolve, 'lp://ratotehunoahu')
362
367
def test_resolve_tilde_to_user(self):
363
368
factory = FakeResolveFactory(
388
393
def test_directory_open_branch(self):
389
394
# Test that opening an lp: branch redirects to the real location.
390
395
target_branch = self.make_branch('target')
391
397
class FooService(object):
392
398
"""A directory service that maps the name to a FILE url"""
394
def look_up(self, name, url):
400
def look_up(self, name, url, purpose=None):
395
401
if 'lp:///apt' == url:
396
402
return target_branch.base.rstrip('/')
397
403
return '!unexpected look_up value!'
399
405
directories.remove('lp:')
406
directories.remove('lp+bzr:')
400
407
directories.remove('ubuntu:')
401
408
directories.remove('debianlp:')
402
409
directories.register('lp:', FooService, 'Map lp URLs to local urls')
594
603
def test_ubuntu_natty_distroseries_expansion(self):
595
604
self.assertURL('ubuntu/natty/foo', 'ubuntu:natty/foo', series='natty')
597
def test_ubuntu_n_distroseries_expansion(self):
598
self.assertURL('ubuntu/natty/foo', 'ubuntu:n/foo', series='natty')
600
606
def test_ubuntu_maverick_distroseries_expansion(self):
601
607
self.assertURL('ubuntu/maverick/foo', 'ubuntu:maverick/foo',
602
608
series='maverick')
604
def test_ubuntu_m_distroseries_expansion(self):
605
self.assertURL('ubuntu/maverick/foo', 'ubuntu:m/foo', series='maverick')
607
610
def test_ubuntu_lucid_distroseries_expansion(self):
608
611
self.assertURL('ubuntu/lucid/foo', 'ubuntu:lucid/foo', series='lucid')
610
def test_ubuntu_l_distroseries_expansion(self):
611
self.assertURL('ubuntu/lucid/foo', 'ubuntu:l/foo', series='lucid')
613
613
def test_ubuntu_karmic_distroseries_expansion(self):
614
614
self.assertURL('ubuntu/karmic/foo', 'ubuntu:karmic/foo',
617
def test_ubuntu_k_distroseries_expansion(self):
618
self.assertURL('ubuntu/karmic/foo', 'ubuntu:k/foo', series='karmic')
620
617
def test_ubuntu_jaunty_distroseries_expansion(self):
621
618
self.assertURL('ubuntu/jaunty/foo', 'ubuntu:jaunty/foo',
624
def test_ubuntu_j_distroseries_expansion(self):
625
self.assertURL('ubuntu/jaunty/foo', 'ubuntu:j/foo', series='jaunty')
627
621
def test_ubuntu_hardy_distroseries_expansion(self):
628
622
self.assertURL('ubuntu/hardy/foo', 'ubuntu:hardy/foo', series='hardy')
630
def test_ubuntu_h_distroseries_expansion(self):
631
self.assertURL('ubuntu/hardy/foo', 'ubuntu:h/foo', series='hardy')
633
624
def test_ubuntu_dapper_distroseries_expansion(self):
634
625
self.assertURL('ubuntu/dapper/foo', 'ubuntu:dapper/foo',
637
def test_ubuntu_d_distroseries_expansion(self):
638
self.assertURL('ubuntu/dapper/foo', 'ubuntu:d/foo', series='dapper')
640
628
# Debian default distro series.
642
630
def test_debian_default_distroseries_expansion(self):