/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/launchpad/test_lp_directory.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import breezy
28
28
from ... import (
29
29
    debug,
30
 
    errors,
31
30
    tests,
32
31
    transport,
33
32
    )
54
53
    result = loader.suiteClass()
55
54
    t_tests, remaining_tests = tests.split_suite_by_condition(
56
55
        standard_tests, tests.condition_isinstance((
57
 
                TestXMLRPCTransport,
58
 
                )))
 
56
            TestXMLRPCTransport,
 
57
            )))
59
58
    transport_scenarios = [
60
59
        ('http', dict(server_class=PreCannedHTTPServer,)),
61
60
        ]
93
92
    """Tests for branch urls that we try to pass through local resolution."""
94
93
 
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)
104
103
 
106
105
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt',
107
106
                           'lp:apt')
108
107
 
 
108
    def test_short_form_bzr(self):
 
109
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt',
 
110
                           'lp+bzr:apt')
 
111
 
109
112
    def test_two_part_form(self):
110
113
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt/2.2',
111
114
                           'lp:apt/2.2')
136
139
        """
137
140
        # This ought to be natty-updates.
138
141
        self.assertRaises(lp_registration.InvalidURL,
139
 
            self.assertResolve,
140
 
            '',
141
 
            'ubuntu:natty/updates/smartpm')
 
142
                          self.assertResolve,
 
143
                          '',
 
144
                          'ubuntu:natty/updates/smartpm')
142
145
 
143
146
    def test_ubuntu_apt(self):
144
147
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/ubuntu/apt',
204
207
            'lp:~jameinel/debian/sid/apt/branch/f')
205
208
 
206
209
    def test_handles_special_lp(self):
207
 
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt', 'lp:apt')
 
210
        self.assertResolve(
 
211
            'bzr+ssh://bazaar.launchpad.net/+branch/apt', 'lp:apt')
208
212
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt',
209
213
                           'lp:///apt')
210
214
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt',
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)
243
247
 
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)
256
260
 
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)
269
273
 
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))
278
282
 
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))
288
292
 
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)
299
303
    def test_directory_fault(self):
300
304
        # Test that XMLRPC faults get converted to InvalidURL errors.
301
305
        factory = FakeResolveFactory(self, 'apt', None)
 
306
 
302
307
        def submit(service):
303
308
            raise Fault(42, 'something went wrong')
304
309
        factory.submit = submit
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))
320
325
 
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))
332
337
 
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))
355
360
 
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')
361
366
 
362
367
    def test_resolve_tilde_to_user(self):
363
368
        factory = FakeResolveFactory(
376
381
    def test_tilde_fails_no_login(self):
377
382
        factory = FakeResolveFactory(
378
383
            self, '~username/apt/test', dict(urls=[
379
 
                    'bzr+ssh://bazaar.launchpad.net/~username/apt/test']))
 
384
                'bzr+ssh://bazaar.launchpad.net/~username/apt/test']))
380
385
        self.assertIs(None, get_lp_login())
381
386
        directory = LaunchpadDirectory()
382
387
        self.assertRaises(lp_registration.InvalidURL,
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')
 
396
 
391
397
        class FooService(object):
392
398
            """A directory service that maps the name to a FILE url"""
393
399
 
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!'
398
404
 
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')
450
457
 
451
458
if features.HTTPSServerFeature.available():
452
459
    from ...tests import https_server
 
460
 
453
461
    class PreCannedHTTPSServer(PreCannedServerMixin, https_server.HTTPSServer):
454
462
        pass
455
463
 
503
511
'''
504
512
        length = 334 + 2 * len(path)
505
513
        server.canned_response = response_format % {
506
 
                b'length': length, b'path': path}
 
514
            b'length': length, b'path': path}
507
515
 
508
516
    def do_request(self, server_url):
509
517
        os.environ['BRZ_LP_XMLRPC_URL'] = self.server.get_url()
571
579
    def test_missing_ubuntu_distroseries_without_project(self):
572
580
        # Launchpad does not hold source packages for Intrepid.  Missing or
573
581
        # bogus distroseries with no project name is treated like a project.
574
 
        self.assertURL('ubuntu/intrepid', 'ubuntu:intrepid', package='intrepid')
 
582
        self.assertURL('ubuntu/intrepid', 'ubuntu:intrepid',
 
583
                       package='intrepid')
575
584
 
576
585
    def test_missing_ubuntu_distroseries_with_project(self):
577
586
        # Launchpad does not hold source packages for Intrepid.  Missing or
594
603
    def test_ubuntu_natty_distroseries_expansion(self):
595
604
        self.assertURL('ubuntu/natty/foo', 'ubuntu:natty/foo', series='natty')
596
605
 
597
 
    def test_ubuntu_n_distroseries_expansion(self):
598
 
        self.assertURL('ubuntu/natty/foo', 'ubuntu:n/foo', series='natty')
599
 
 
600
606
    def test_ubuntu_maverick_distroseries_expansion(self):
601
607
        self.assertURL('ubuntu/maverick/foo', 'ubuntu:maverick/foo',
602
608
                       series='maverick')
603
609
 
604
 
    def test_ubuntu_m_distroseries_expansion(self):
605
 
        self.assertURL('ubuntu/maverick/foo', 'ubuntu:m/foo', series='maverick')
606
 
 
607
610
    def test_ubuntu_lucid_distroseries_expansion(self):
608
611
        self.assertURL('ubuntu/lucid/foo', 'ubuntu:lucid/foo', series='lucid')
609
612
 
610
 
    def test_ubuntu_l_distroseries_expansion(self):
611
 
        self.assertURL('ubuntu/lucid/foo', 'ubuntu:l/foo', series='lucid')
612
 
 
613
613
    def test_ubuntu_karmic_distroseries_expansion(self):
614
614
        self.assertURL('ubuntu/karmic/foo', 'ubuntu:karmic/foo',
615
615
                       series='karmic')
616
616
 
617
 
    def test_ubuntu_k_distroseries_expansion(self):
618
 
        self.assertURL('ubuntu/karmic/foo', 'ubuntu:k/foo', series='karmic')
619
 
 
620
617
    def test_ubuntu_jaunty_distroseries_expansion(self):
621
618
        self.assertURL('ubuntu/jaunty/foo', 'ubuntu:jaunty/foo',
622
619
                       series='jaunty')
623
620
 
624
 
    def test_ubuntu_j_distroseries_expansion(self):
625
 
        self.assertURL('ubuntu/jaunty/foo', 'ubuntu:j/foo', series='jaunty')
626
 
 
627
621
    def test_ubuntu_hardy_distroseries_expansion(self):
628
622
        self.assertURL('ubuntu/hardy/foo', 'ubuntu:hardy/foo', series='hardy')
629
623
 
630
 
    def test_ubuntu_h_distroseries_expansion(self):
631
 
        self.assertURL('ubuntu/hardy/foo', 'ubuntu:h/foo', series='hardy')
632
 
 
633
624
    def test_ubuntu_dapper_distroseries_expansion(self):
634
625
        self.assertURL('ubuntu/dapper/foo', 'ubuntu:dapper/foo',
635
626
                       series='dapper')
636
627
 
637
 
    def test_ubuntu_d_distroseries_expansion(self):
638
 
        self.assertURL('ubuntu/dapper/foo', 'ubuntu:d/foo', series='dapper')
639
 
 
640
628
    # Debian default distro series.
641
629
 
642
630
    def test_debian_default_distroseries_expansion(self):