352
366
self.assertEqual('B', b.last_revision())
353
367
self.assertEqual('tip-1.0',
354
368
lp_api_lite.get_most_recent_tag(tag_dict, b))
371
class StubLatestPublication(object):
373
def __init__(self, latest):
377
def get_latest_version(self):
382
return 'Ubuntu Natty'
385
class TestReportFreshness(tests.TestCaseWithMemoryTransport):
388
super(TestReportFreshness, self).setUp()
389
builder = self.make_branch_builder('tip')
390
builder.build_snapshot('A', [], [
391
('add', ('', 'root-id', 'directory', None))])
392
self.branch = builder.get_branch()
394
def assertFreshnessReports(self, verbosity, latest_version, content):
395
"""Assert that lp_api_lite.report_freshness reports the given content.
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(self.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
# We force _get_package_branch_info so that we know it would otherwise
420
# try to connect to launcphad
421
self.overrideAttr(launchpad, '_get_package_branch_info',
422
lambda x: ('ubuntu', 'natty', 'bzr'))
423
self.overrideAttr(lp_api_lite, 'LatestPublication',
424
lambda *args: self.fail('Tried to query launchpad'))
425
c = self.branch.get_config()
426
c.set_user_option('launchpad.packaging_verbosity', 'off')
427
orig_log_len = len(self.get_log())
428
launchpad._check_is_up_to_date(self.branch)
429
new_content = self.get_log()[orig_log_len:]
430
self.assertContainsRe(new_content,
431
'not checking memory.*/tip/ because verbosity is turned off')
433
def test_verbosity_off(self):
434
latest_pub = StubLatestPublication('1.0-1ubuntu2')
435
lp_api_lite.report_freshness(self.branch, 'off', latest_pub)
436
self.assertFalse(latest_pub.called)
438
def test_verbosity_all_out_of_date_smoke(self):
439
self.branch.tags.set_tag('1.0-1ubuntu1', 'A')
440
self.assertFreshnessReports('all', '1.0-1ubuntu2',
441
' INFO Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
442
'Packaging branch version: 1.0-1ubuntu1\n'
443
'Packaging branch status: OUT-OF-DATE\n')
446
class Test_GetNewestVersions(tests.TestCaseWithMemoryTransport):
449
super(Test_GetNewestVersions, self).setUp()
450
builder = self.make_branch_builder('tip')
451
builder.build_snapshot('A', [], [
452
('add', ('', 'root-id', 'directory', None))])
453
self.branch = builder.get_branch()
455
def assertLatestVersions(self, latest_branch_version, pub_version):
456
if latest_branch_version is not None:
457
self.branch.tags.set_tag(latest_branch_version, 'A')
458
latest_pub = StubLatestPublication(pub_version)
459
self.assertEqual((pub_version, latest_branch_version),
460
lp_api_lite._get_newest_versions(self.branch, latest_pub))
462
def test_no_tags(self):
463
self.assertLatestVersions(None, '1.0-1ubuntu2')
465
def test_out_of_date(self):
466
self.assertLatestVersions('1.0-1ubuntu1', '1.0-1ubuntu2')
468
def test_up_to_date(self):
469
self.assertLatestVersions('1.0-1ubuntu2', '1.0-1ubuntu2')
471
def test_missing(self):
472
self.assertLatestVersions(None, None)
475
class Test_ReportFreshness(tests.TestCase):
477
def assertReportedFreshness(self, verbosity, latest_ver, branch_latest_ver,
478
content, place='Ubuntu Natty'):
479
"""Assert that lp_api_lite.report_freshness reports the given content.
482
def report_func(value):
483
reported.append(value)
485
lp_api_lite._report_freshness(latest_ver, branch_latest_ver, place,
486
verbosity, report_func)
487
new_content = '\n'.join(reported)
488
self.assertThat(new_content,
489
DocTestMatches(content,
490
doctest.ELLIPSIS | doctest.REPORT_UDIFF))
492
def test_verbosity_minimal_no_tags(self):
493
self.assertReportedFreshness('minimal', '1.0-1ubuntu2', None,
494
'Branch is OUT-OF-DATE, Ubuntu Natty has 1.0-1ubuntu2\n')
496
def test_verbosity_minimal_out_of_date(self):
497
self.assertReportedFreshness('minimal', '1.0-1ubuntu2', '1.0-1ubuntu1',
498
'1.0-1ubuntu1 is OUT-OF-DATE,'
499
' Ubuntu Natty has 1.0-1ubuntu2\n')
501
def test_verbosity_minimal_up_to_date(self):
502
self.assertReportedFreshness('minimal', '1.0-1ubuntu2', '1.0-1ubuntu2',
505
def test_verbosity_minimal_missing(self):
506
self.assertReportedFreshness('minimal', None, None,
509
def test_verbosity_short_out_of_date(self):
510
self.assertReportedFreshness('short', '1.0-1ubuntu2', '1.0-1ubuntu1',
511
'1.0-1ubuntu1 is OUT-OF-DATE,'
512
' Ubuntu Natty has 1.0-1ubuntu2\n')
514
def test_verbosity_short_up_to_date(self):
515
self.assertReportedFreshness('short', '1.0-1ubuntu2', '1.0-1ubuntu2',
516
'1.0-1ubuntu2 is CURRENT in Ubuntu Natty')
518
def test_verbosity_short_missing(self):
519
self.assertReportedFreshness('short', None, None,
520
'Ubuntu Natty is MISSING a version')
522
def test_verbosity_all_no_tags(self):
523
self.assertReportedFreshness('all', '1.0-1ubuntu2', None,
524
'Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
525
'Packaging branch version: None\n'
526
'Packaging branch status: OUT-OF-DATE\n')
528
def test_verbosity_all_out_of_date(self):
529
self.assertReportedFreshness('all', '1.0-1ubuntu2', '1.0-1ubuntu1',
530
'Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
531
'Packaging branch version: 1.0-1ubuntu1\n'
532
'Packaging branch status: OUT-OF-DATE\n')
534
def test_verbosity_all_up_to_date(self):
535
self.assertReportedFreshness('all', '1.0-1ubuntu2', '1.0-1ubuntu2',
536
'Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
537
'Packaging branch status: CURRENT\n')
539
def test_verbosity_all_missing(self):
540
self.assertReportedFreshness('all', None, None,
541
'Most recent Ubuntu Natty version: MISSING\n')
543
def test_verbosity_None_is_all(self):
544
self.assertReportedFreshness(None, '1.0-1ubuntu2', '1.0-1ubuntu2',
545
'Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
546
'Packaging branch status: CURRENT\n')