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):
386
super(TestReportFreshness, self).setUp()
387
builder = self.make_branch_builder('tip')
388
builder.build_snapshot('A', [], [
389
('add', ('', 'root-id', 'directory', None))])
390
self.branch = builder.get_branch()
392
def assertFreshnessReports(self, verbosity, latest_version, content):
393
"""Assert that lp_api_lite.report_freshness reports the given content.
395
:param verbosity: The reporting level
396
:param latest_version: The version reported by StubLatestPublication
397
:param content: The expected content. This should be in DocTest form.
399
orig_log_len = len(self.get_log())
400
lp_api_lite.report_freshness(self.branch, verbosity,
401
StubLatestPublication(latest_version))
402
new_content = self.get_log()[orig_log_len:]
403
# Strip out lines that have LatestPublication.get_* because those are
404
# timing related lines. While interesting to log for now, they aren't
405
# something we want to be testing
406
new_content = new_content.split('\n')
408
if (len(new_content) > 0
409
and 'LatestPublication.get_' in new_content[0]):
410
new_content = new_content[1:]
411
new_content = '\n'.join(new_content)
412
self.assertThat(new_content,
413
DocTestMatches(content,
414
doctest.ELLIPSIS | doctest.REPORT_UDIFF))
416
def test_verbosity_off_skips_check(self):
417
# We force _get_package_branch_info so that we know it would otherwise
418
# try to connect to launcphad
419
self.overrideAttr(launchpad, '_get_package_branch_info',
420
lambda x: ('ubuntu', 'natty', 'bzr'))
421
self.overrideAttr(lp_api_lite, 'LatestPublication',
422
lambda *args: self.fail('Tried to query launchpad'))
423
c = self.branch.get_config()
424
c.set_user_option('launchpad.packaging_verbosity', 'off')
425
orig_log_len = len(self.get_log())
426
launchpad._check_is_up_to_date(self.branch)
427
new_content = self.get_log()[orig_log_len:]
428
self.assertContainsRe(new_content,
429
'not checking memory.*/tip/ because verbosity is turned off')
431
def test_verbosity_off(self):
432
latest_pub = StubLatestPublication('1.0-1ubuntu2')
433
lp_api_lite.report_freshness(self.branch, 'off', latest_pub)
434
self.assertFalse(latest_pub.called)
436
def test_verbosity_all_out_of_date_smoke(self):
437
self.branch.tags.set_tag('1.0-1ubuntu1', 'A')
438
self.assertFreshnessReports('all', '1.0-1ubuntu2',
439
' INFO Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
440
'Packaging branch version: 1.0-1ubuntu1\n'
441
'Packaging branch status: OUT-OF-DATE\n')
444
class Test_GetNewestVersions(tests.TestCaseWithMemoryTransport):
447
super(Test_GetNewestVersions, self).setUp()
448
builder = self.make_branch_builder('tip')
449
builder.build_snapshot('A', [], [
450
('add', ('', 'root-id', 'directory', None))])
451
self.branch = builder.get_branch()
453
def assertLatestVersions(self, latest_branch_version, pub_version):
454
if latest_branch_version is not None:
455
self.branch.tags.set_tag(latest_branch_version, 'A')
456
latest_pub = StubLatestPublication(pub_version)
457
self.assertEqual((pub_version, latest_branch_version),
458
lp_api_lite._get_newest_versions(self.branch, latest_pub))
460
def test_no_tags(self):
461
self.assertLatestVersions(None, '1.0-1ubuntu2')
463
def test_out_of_date(self):
464
self.assertLatestVersions('1.0-1ubuntu1', '1.0-1ubuntu2')
466
def test_up_to_date(self):
467
self.assertLatestVersions('1.0-1ubuntu2', '1.0-1ubuntu2')
469
def test_missing(self):
470
self.assertLatestVersions(None, None)
473
class Test_ReportFreshness(tests.TestCase):
475
def assertReportedFreshness(self, verbosity, latest_ver, branch_latest_ver,
476
content, place='Ubuntu Natty'):
477
"""Assert that lp_api_lite.report_freshness reports the given content.
480
def report_func(value):
481
reported.append(value)
482
lp_api_lite._report_freshness(latest_ver, branch_latest_ver, place,
483
verbosity, report_func)
484
new_content = '\n'.join(reported)
485
self.assertThat(new_content,
486
DocTestMatches(content,
487
doctest.ELLIPSIS | doctest.REPORT_UDIFF))
489
def test_verbosity_minimal_no_tags(self):
490
self.assertReportedFreshness('minimal', '1.0-1ubuntu2', None,
491
'Branch is OUT-OF-DATE, Ubuntu Natty has 1.0-1ubuntu2\n')
493
def test_verbosity_minimal_out_of_date(self):
494
self.assertReportedFreshness('minimal', '1.0-1ubuntu2', '1.0-1ubuntu1',
495
'1.0-1ubuntu1 is OUT-OF-DATE,'
496
' Ubuntu Natty has 1.0-1ubuntu2\n')
498
def test_verbosity_minimal_up_to_date(self):
499
self.assertReportedFreshness('minimal', '1.0-1ubuntu2', '1.0-1ubuntu2',
502
def test_verbosity_minimal_missing(self):
503
self.assertReportedFreshness('minimal', None, None,
506
def test_verbosity_short_out_of_date(self):
507
self.assertReportedFreshness('short', '1.0-1ubuntu2', '1.0-1ubuntu1',
508
'1.0-1ubuntu1 is OUT-OF-DATE,'
509
' Ubuntu Natty has 1.0-1ubuntu2\n')
511
def test_verbosity_short_up_to_date(self):
512
self.assertReportedFreshness('short', '1.0-1ubuntu2', '1.0-1ubuntu2',
513
'1.0-1ubuntu2 is CURRENT in Ubuntu Natty')
515
def test_verbosity_short_missing(self):
516
self.assertReportedFreshness('short', None, None,
517
'Ubuntu Natty is MISSING a version')
519
def test_verbosity_all_no_tags(self):
520
self.assertReportedFreshness('all', '1.0-1ubuntu2', None,
521
'Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
522
'Packaging branch version: None\n'
523
'Packaging branch status: OUT-OF-DATE\n')
525
def test_verbosity_all_out_of_date(self):
526
self.assertReportedFreshness('all', '1.0-1ubuntu2', '1.0-1ubuntu1',
527
'Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
528
'Packaging branch version: 1.0-1ubuntu1\n'
529
'Packaging branch status: OUT-OF-DATE\n')
531
def test_verbosity_all_up_to_date(self):
532
self.assertReportedFreshness('all', '1.0-1ubuntu2', '1.0-1ubuntu2',
533
'Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
534
'Packaging branch status: CURRENT\n')
536
def test_verbosity_all_missing(self):
537
self.assertReportedFreshness('all', None, None,
538
'Most recent Ubuntu Natty version: MISSING\n')
540
def test_verbosity_None_is_all(self):
541
self.assertReportedFreshness(None, '1.0-1ubuntu2', '1.0-1ubuntu2',
542
'Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
543
'Packaging branch status: CURRENT\n')