315
315
SourcePackage(branch.sourcepackagename, branch.distroseries),
316
316
branch.sourcepackage)
319
class TestBranchUpgrade(TestCaseWithFactory):
320
"""Test the upgrade functionalities of branches."""
322
layer = DatabaseFunctionalLayer
324
def test_needsUpgrading_already_requested(self):
325
# A branch has a needs_upgrading attribute that returns whether or not
326
# a branch needs to be upgraded or not. If the format is
327
# unrecognized, we don't try to upgrade it.
328
branch = self.factory.makePersonalBranch(
329
branch_format=BranchFormat.BZR_BRANCH_6,
330
repository_format=RepositoryFormat.BZR_CHK_2A)
331
owner = removeSecurityProxy(branch).owner
333
self.addCleanup(logout)
334
branch.requestUpgrade()
336
self.assertFalse(branch.needs_upgrading)
318
338
def test_needsUpgrading_branch_format_unrecognized(self):
319
339
# A branch has a needs_upgrading attribute that returns whether or not
320
340
# a branch needs to be upgraded or not. If the format is
321
341
# unrecognized, we don't try to upgrade it.
322
342
branch = self.factory.makePersonalBranch(
323
branch_format=BranchFormat.UNRECOGNIZED)
343
branch_format=BranchFormat.UNRECOGNIZED,
344
repository_format=RepositoryFormat.BZR_CHK_2A)
324
345
self.assertFalse(branch.needs_upgrading)
326
347
def test_needsUpgrading_branch_format_upgrade_not_needed(self):
327
348
# A branch has a needs_upgrading attribute that returns whether or not
328
# a branch needs to be upgraded or not. If a branch is up to date, it
349
# a branch needs to be upgraded or not. If a branch is up-to-date, it
329
350
# doesn't need to be upgraded.
331
# XXX: JonathanLange 2009-06-06: This test needs to be changed every
332
# time Bazaar adds a new branch format. Surely we can think of a
333
# better way of testing this?
334
351
branch = self.factory.makePersonalBranch(
335
branch_format=BranchFormat.BZR_BRANCH_8)
352
branch_format=BranchFormat.BZR_BRANCH_8,
353
repository_format=RepositoryFormat.BZR_CHK_2A)
336
354
self.assertFalse(branch.needs_upgrading)
338
356
def test_needsUpgrading_branch_format_upgrade_needed(self):
340
358
# a branch needs to be upgraded or not. If a branch doesn't support
341
359
# stacking, it needs to be upgraded.
342
360
branch = self.factory.makePersonalBranch(
343
branch_format=BranchFormat.BZR_BRANCH_6)
361
branch_format=BranchFormat.BZR_BRANCH_6,
362
repository_format=RepositoryFormat.BZR_CHK_2A)
344
363
self.assertTrue(branch.needs_upgrading)
346
365
def test_needsUpgrading_repository_format_unrecognized(self):
348
367
# a branch needs to be upgraded or not. In the repo format is
349
368
# unrecognized, we don't try to upgrade it.
350
369
branch = self.factory.makePersonalBranch(
370
branch_format=BranchFormat.BZR_BRANCH_8,
351
371
repository_format=RepositoryFormat.UNRECOGNIZED)
352
372
self.assertFalse(branch.needs_upgrading)
356
376
# branch needs to be upgraded or not. If the repo format is up to
357
377
# date, there's no need to upgrade it.
358
378
branch = self.factory.makePersonalBranch(
359
repository_format=RepositoryFormat.BZR_KNITPACK_6)
379
branch_format=BranchFormat.BZR_BRANCH_8,
380
repository_format=RepositoryFormat.BZR_CHK_2A)
360
381
self.assertFalse(branch.needs_upgrading)
362
383
def test_needsUpgrading_repository_format_upgrade_needed(self):
364
385
# branch needs to be upgraded or not. If the format doesn't support
365
386
# stacking, it needs to be upgraded.
366
387
branch = self.factory.makePersonalBranch(
388
branch_format=BranchFormat.BZR_BRANCH_8,
367
389
repository_format=RepositoryFormat.BZR_REPOSITORY_4)
368
390
self.assertTrue(branch.needs_upgrading)
371
393
# A BranchUpgradeJob can be created by calling IBranch.requestUpgrade.
372
394
branch = self.factory.makeAnyBranch(
373
395
branch_format=BranchFormat.BZR_BRANCH_6)
396
owner = removeSecurityProxy(branch).owner
398
self.addCleanup(logout)
374
399
job = removeSecurityProxy(branch.requestUpgrade())
376
401
jobs = list(getUtility(IBranchUpgradeJobSource).iterReady())
406
def test_requestUpgrade_no_upgrade_needed(self):
407
# If a branch doesn't need to be upgraded, requestUpgrade raises an
409
branch = self.factory.makeAnyBranch(
410
branch_format=BranchFormat.BZR_BRANCH_8,
411
repository_format=RepositoryFormat.BZR_CHK_2A)
412
owner = removeSecurityProxy(branch).owner
414
self.addCleanup(logout)
415
self.assertRaises(AssertionError, branch.requestUpgrade)
417
def test_requestUpgrade_upgrade_pending(self):
418
# If there is a pending upgrade already requested, requestUpgrade
419
# raises an AssertionError.
420
branch = self.factory.makeAnyBranch(
421
branch_format=BranchFormat.BZR_BRANCH_6)
422
owner = removeSecurityProxy(branch).owner
424
self.addCleanup(logout)
425
branch.requestUpgrade()
427
self.assertRaises(AssertionError, branch.requestUpgrade)
429
def test_upgradePending(self):
430
# If there is a BranchUpgradeJob pending for the branch, return True.
431
branch = self.factory.makeAnyBranch(
432
branch_format=BranchFormat.BZR_BRANCH_6)
433
owner = removeSecurityProxy(branch).owner
435
self.addCleanup(logout)
436
branch.requestUpgrade()
438
self.assertTrue(branch.upgrade_pending)
440
def test_upgradePending_no_upgrade_requested(self):
441
# If the branch never had an upgrade requested, return False.
442
branch = self.factory.makeAnyBranch()
444
self.assertFalse(branch.upgrade_pending)
382
447
class TestBzrIdentity(TestCaseWithFactory):
383
448
"""Test IBranch.bzr_identity."""