~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/code/model/tests/test_branch.py

  • Committer: Paul Hummer
  • Date: 2010-01-22 06:03:19 UTC
  • mto: (7675.442.106 launchpad)
  • mto: This revision was merged to the branch mainline in revision 10225.
  • Revision ID: paul@canonical.com-20100122060319-lj1tn8sc8s2wd03e
Reverted the reversion of the patch that went into devel by mistake

Show diffs side-by-side

added added

removed removed

Lines of Context:
315
315
            SourcePackage(branch.sourcepackagename, branch.distroseries),
316
316
            branch.sourcepackage)
317
317
 
 
318
 
 
319
class TestBranchUpgrade(TestCaseWithFactory):
 
320
    """Test the upgrade functionalities of branches."""
 
321
 
 
322
    layer = DatabaseFunctionalLayer
 
323
 
 
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
 
332
        login_person(owner)
 
333
        self.addCleanup(logout)
 
334
        branch.requestUpgrade()
 
335
 
 
336
        self.assertFalse(branch.needs_upgrading)
 
337
 
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)
325
346
 
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.
330
 
        #
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)
337
355
 
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)
345
364
 
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)
353
373
 
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)
361
382
 
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)
369
391
 
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
 
397
        login_person(owner)
 
398
        self.addCleanup(logout)
374
399
        job = removeSecurityProxy(branch.requestUpgrade())
375
400
 
376
401
        jobs = list(getUtility(IBranchUpgradeJobSource).iterReady())
378
403
            jobs,
379
404
            [job,])
380
405
 
 
406
    def test_requestUpgrade_no_upgrade_needed(self):
 
407
        # If a branch doesn't need to be upgraded, requestUpgrade raises an
 
408
        # AssertionError.
 
409
        branch = self.factory.makeAnyBranch(
 
410
            branch_format=BranchFormat.BZR_BRANCH_8,
 
411
            repository_format=RepositoryFormat.BZR_CHK_2A)
 
412
        owner = removeSecurityProxy(branch).owner
 
413
        login_person(owner)
 
414
        self.addCleanup(logout)
 
415
        self.assertRaises(AssertionError, branch.requestUpgrade)
 
416
 
 
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
 
423
        login_person(owner)
 
424
        self.addCleanup(logout)
 
425
        branch.requestUpgrade()
 
426
 
 
427
        self.assertRaises(AssertionError, branch.requestUpgrade)
 
428
 
 
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
 
434
        login_person(owner)
 
435
        self.addCleanup(logout)
 
436
        branch.requestUpgrade()
 
437
 
 
438
        self.assertTrue(branch.upgrade_pending)
 
439
 
 
440
    def test_upgradePending_no_upgrade_requested(self):
 
441
        # If the branch never had an upgrade requested, return False.
 
442
        branch = self.factory.makeAnyBranch()
 
443
 
 
444
        self.assertFalse(branch.upgrade_pending)
 
445
 
381
446
 
382
447
class TestBzrIdentity(TestCaseWithFactory):
383
448
    """Test IBranch.bzr_identity."""