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))
369
class StubLatestPublication(object):
371
def __init__(self, latest):
375
def get_latest_version(self):
380
return 'Ubuntu Natty'
383
class TestReportFreshness(tests.TestCaseWithMemoryTransport):
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()
392
def assertFreshnessReports(self, the_branch, verbosity, latest_version,
394
"""Assert that lp_api_lite.report_freshness reports the given content.
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.
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')
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))
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'))
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')
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)
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')
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')
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',
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,
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')
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')
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')
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')
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')
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')
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')
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')