/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 bzrlib/plugins/launchpad/test_lp_api_lite.py

  • Committer: John Arbash Meinel
  • Date: 2011-07-20 15:05:29 UTC
  • mto: This revision was merged to the branch mainline in revision 6038.
  • Revision ID: john@arbash-meinel.com-20110720150529-rf9k30hizsegp1sy
Move 'place' logic onto LatestPublication.
Add tests for it directly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tools for dealing with the Launchpad API without using launchpadlib.
18
18
"""
19
19
 
 
20
import doctest
20
21
import socket
21
22
 
22
23
from bzrlib import tests
23
24
from bzrlib.plugins import launchpad
24
25
from bzrlib.plugins.launchpad import lp_api_lite
25
26
 
 
27
from testtools.matchers import DocTestMatches
 
28
 
 
29
 
26
30
class _JSONParserFeature(tests.Feature):
27
31
 
28
32
    def _probe(self):
76
80
                                project='bzr'):
77
81
        return lp_api_lite.LatestPublication(archive, series, project)
78
82
 
 
83
    def assertPlace(self, place, archive, series, project):
 
84
        lp = lp_api_lite.LatestPublication(archive, series, project)
 
85
        self.assertEqual(place, lp.place())
 
86
 
79
87
    def test_init(self):
80
88
        latest_pub = self.make_latest_publication()
81
89
        self.assertEqual('ubuntu', latest_pub._archive)
262
270
        latest_pub = self.make_latest_publication()
263
271
        self.assertIsNot(None, latest_pub.get_latest_version())
264
272
 
 
273
    def test_place(self):
 
274
        self.assertPlace('Ubuntu', 'ubuntu', None, 'bzr')
 
275
        self.assertPlace('Ubuntu Natty', 'ubuntu', 'natty', 'bzr')
 
276
        self.assertPlace('Ubuntu Natty Proposed', 'ubuntu', 'natty-proposed',
 
277
                         'bzr')
 
278
        self.assertPlace('Debian', 'debian', None, 'bzr')
 
279
        self.assertPlace('Debian Sid', 'debian', 'sid', 'bzr')
 
280
 
265
281
 
266
282
class TestIsUpToDate(tests.TestCase):
267
283
 
348
364
        self.assertEqual('B', b.last_revision())
349
365
        self.assertEqual('tip-1.0',
350
366
                         lp_api_lite.get_most_recent_tag(tag_dict, b))
 
367
 
 
368
 
 
369
class StubLatestPublication(object):
 
370
 
 
371
    def __init__(self, latest):
 
372
        self.called = False
 
373
        self.latest = latest
 
374
 
 
375
    def get_latest_version(self):
 
376
        self.called = True
 
377
        return self.latest
 
378
 
 
379
    def place(self):
 
380
        return 'Ubuntu Natty'
 
381
 
 
382
 
 
383
class TestReportFreshness(tests.TestCaseWithMemoryTransport):
 
384
 
 
385
    def make_trivial_branch(self):
 
386
        builder = self.make_branch_builder('tip')
 
387
        builder.build_snapshot('A', [], [
 
388
            ('add', ('', 'root-id', 'directory', None))])
 
389
        b = builder.get_branch()
 
390
        return b
 
391
 
 
392
    def assertFreshnessReports(self, the_branch, verbosity, latest_version,
 
393
                               content):
 
394
        """Assert that lp_api_lite.report_freshness reports the given content.
 
395
 
 
396
        :param the_branch: The branch we are inspecting
 
397
        :param verbosity: The reporting level
 
398
        :param latest_version: The version reported by StubLatestPublication
 
399
        :param content: The expected content. This should be in DocTest form.
 
400
        """
 
401
        orig_log_len = len(self.get_log())
 
402
        lp_api_lite.report_freshness(the_branch, verbosity,
 
403
            StubLatestPublication(latest_version))
 
404
        new_content = self.get_log()[orig_log_len:]
 
405
        # Strip out lines that have LatestPublication.get_* because those are
 
406
        # timing related lines. While interesting to log for now, they aren't
 
407
        # something we want to be testing
 
408
        new_content = new_content.split('\n')
 
409
        for i in range(2):
 
410
            if (len(new_content) > 0
 
411
                and 'LatestPublication.get_' in new_content[0]):
 
412
                new_content = new_content[1:]
 
413
        new_content = '\n'.join(new_content)
 
414
        self.assertThat(new_content,
 
415
            DocTestMatches(content,
 
416
                doctest.ELLIPSIS | doctest.REPORT_UDIFF))
 
417
 
 
418
    def test_verbosity_off_skips_check(self):
 
419
        b = self.make_trivial_branch()
 
420
        # We force _get_package_branch_info so that we know it would otherwise
 
421
        # try to connect to launcphad
 
422
        self.overrideAttr(launchpad, '_get_package_branch_info',
 
423
            lambda x: ('ubuntu', 'natty', 'bzr'))
 
424
        self.overrideAttr(lp_api_lite, 'LatestPublication',
 
425
            lambda *args: self.fail('Tried to query launchpad'))
 
426
        c = b.get_config()
 
427
        c.set_user_option('bzr.plugins.launchpad.packaging_verbosity', 'off')
 
428
        orig_log_len = len(self.get_log())
 
429
        launchpad._check_is_up_to_date(b)
 
430
        new_content = self.get_log()[orig_log_len:]
 
431
        self.assertContainsRe(new_content,
 
432
            'not checking memory.*/tip/ because verbosity is turned off')
 
433
 
 
434
    def test_verbosity_off(self):
 
435
        b = self.make_trivial_branch()
 
436
        latest_pub = StubLatestPublication('1.0-1ubuntu2')
 
437
        lp_api_lite.report_freshness(b, 'off', latest_pub)
 
438
        self.assertFalse(latest_pub.called)
 
439
 
 
440
    def test_verbosity_minimal_no_tags(self):
 
441
        b = self.make_trivial_branch()
 
442
        self.assertFreshnessReports(b, 'minimal', '1.0-1ubuntu2',
 
443
            ' WARNING  Branch is OUT-OF-DATE, Ubuntu Natty has 1.0-1ubuntu2\n')
 
444
 
 
445
    def test_verbosity_minimal_out_of_date(self):
 
446
        b = self.make_trivial_branch()
 
447
        b.tags.set_tag('1.0-1ubuntu1', 'A')
 
448
        self.assertFreshnessReports(b, 'minimal', '1.0-1ubuntu2',
 
449
            ' WARNING  1.0-1ubuntu1 is OUT-OF-DATE,'
 
450
             ' Ubuntu Natty has 1.0-1ubuntu2\n')
 
451
 
 
452
    def test_verbosity_minimal_up_to_date(self):
 
453
        b = self.make_trivial_branch()
 
454
        b.tags.set_tag('1.0-1ubuntu2', 'A')
 
455
        self.assertFreshnessReports(b, 'minimal', '1.0-1ubuntu2',
 
456
             '')
 
457
 
 
458
    def test_verbosity_minimal_missing(self):
 
459
        b = self.make_trivial_branch()
 
460
        b.tags.set_tag('1.0-1ubuntu2', 'A')
 
461
        self.assertFreshnessReports(b, 'minimal', None,
 
462
             '')
 
463
 
 
464
    def test_verbosity_short_out_of_date(self):
 
465
        b = self.make_trivial_branch()
 
466
        b.tags.set_tag('1.0-1ubuntu1', 'A')
 
467
        self.assertFreshnessReports(b, 'short', '1.0-1ubuntu2',
 
468
            ' WARNING  1.0-1ubuntu1 is OUT-OF-DATE,'
 
469
             ' Ubuntu Natty has 1.0-1ubuntu2\n')
 
470
 
 
471
    def test_verbosity_short_up_to_date(self):
 
472
        b = self.make_trivial_branch()
 
473
        b.tags.set_tag('1.0-1ubuntu2', 'A')
 
474
        self.assertFreshnessReports(b, 'short', '1.0-1ubuntu2',
 
475
             '    INFO  1.0-1ubuntu2 is CURRENT in Ubuntu Natty')
 
476
 
 
477
    def test_verbosity_short_missing(self):
 
478
        b = self.make_trivial_branch()
 
479
        b.tags.set_tag('1.0-1ubuntu2', 'A')
 
480
        self.assertFreshnessReports(b, 'short', None,
 
481
             '    INFO  Ubuntu Natty is MISSING a version')
 
482
 
 
483
    def test_verbosity_all_no_tags(self):
 
484
        b = self.make_trivial_branch()
 
485
        self.assertFreshnessReports(b, 'all', '1.0-1ubuntu2',
 
486
             ' WARNING  Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
 
487
             'Packaging branch version: None\n'
 
488
             'Packaging branch status: OUT-OF-DATE\n')
 
489
 
 
490
    def test_verbosity_all_out_of_date(self):
 
491
        b = self.make_trivial_branch()
 
492
        b.tags.set_tag('1.0-1ubuntu1', 'A')
 
493
        self.assertFreshnessReports(b, 'all', '1.0-1ubuntu2',
 
494
             ' WARNING  Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
 
495
             'Packaging branch version: 1.0-1ubuntu1\n'
 
496
             'Packaging branch status: OUT-OF-DATE\n')
 
497
 
 
498
    def test_verbosity_all_up_to_date(self):
 
499
        b = self.make_trivial_branch()
 
500
        b.tags.set_tag('1.0-1ubuntu2', 'A')
 
501
        self.assertFreshnessReports(b, 'all', '1.0-1ubuntu2',
 
502
             '    INFO  Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
 
503
             'Packaging branch status: CURRENT\n')
 
504
 
 
505
    def test_verbosity_all_missing(self):
 
506
        b = self.make_trivial_branch()
 
507
        b.tags.set_tag('1.0-1ubuntu2', 'A')
 
508
        self.assertFreshnessReports(b, 'all', None,
 
509
             '    INFO  Most recent Ubuntu Natty version: MISSING\n')
 
510
 
 
511
    def test_verbosity_None_is_all(self):
 
512
        b = self.make_trivial_branch()
 
513
        b.tags.set_tag('1.0-1ubuntu2', 'A')
 
514
        self.assertFreshnessReports(b, None, '1.0-1ubuntu2',
 
515
             '    INFO  Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
 
516
             'Packaging branch status: CURRENT\n')