~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Andrew Bennetts
  • Date: 2008-04-08 08:13:33 UTC
  • mto: This revision was merged to the branch mainline in revision 3355.
  • Revision ID: andrew.bennetts@canonical.com-20080408081333-lov0qqto26hyycoj
Add more tests, handle NoSuchRevision in case the remote branch's format can raise it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
478
478
 
479
479
class TestSmartServerBranchRequestSetLastRevisionInfo(tests.TestCaseWithTransport):
480
480
 
481
 
    def test_revision_id_present(self):
 
481
    def lock_branch(self, branch):
 
482
        branch_token = branch.lock_write()
 
483
        repo_token = branch.repository.lock_write()
 
484
        branch.repository.unlock()
 
485
        self.addCleanup(branch.unlock)
 
486
        return branch_token, repo_token
 
487
 
 
488
    def make_locked_branch(self, format=None):
 
489
        branch = self.make_branch('.', format=format)
 
490
        branch_token, repo_token = self.lock_branch(branch)
 
491
        return branch, branch_token, repo_token
 
492
 
 
493
    def test_empty(self):
 
494
        """An empty branch can have its last revision set to 'null:'."""
 
495
        b, branch_token, repo_token = self.make_locked_branch()
482
496
        backing = self.get_transport()
483
 
        request = smart.branch.SmartServerBranchRequestSetLastRevision(backing)
 
497
        request = smart.branch.SmartServerBranchRequestSetLastRevisionInfo(
 
498
            backing)
 
499
        response = request.execute('', branch_token, repo_token, '0', 'null:')
 
500
        self.assertEqual(SmartServerResponse(('ok',)), response)
 
501
 
 
502
    def assertBranchLastRevisionInfo(self, expected_info, branch_relpath):
 
503
        branch = bzrdir.BzrDir.open(branch_relpath).open_branch()
 
504
        self.assertEqual(expected_info, branch.last_revision_info())
 
505
 
 
506
    def test_branch_revision_info_is_updated(self):
 
507
        """This method really does update the branch last revision info."""
484
508
        tree = self.make_branch_and_memory_tree('.')
485
509
        tree.lock_write()
486
510
        tree.add('')
487
 
        rev_id_utf8 = u'\xc8'.encode('utf-8')
488
 
        r1 = tree.commit('1st commit', rev_id=rev_id_utf8)
489
 
        r2 = tree.commit('2nd commit')
 
511
        tree.commit('First commit', rev_id='revision-1')
 
512
        tree.commit('Second commit', rev_id='revision-2')
490
513
        tree.unlock()
491
 
        branch_token = tree.branch.lock_write()
492
 
        repo_token = tree.branch.repository.lock_write()
493
 
        tree.branch.repository.unlock()
494
 
        try:
495
 
            self.assertEqual(
496
 
                SmartServerResponse(('ok',)),
497
 
                request.execute(
498
 
                    '', branch_token, repo_token,
499
 
                    rev_id_utf8))
500
 
            self.assertEqual([rev_id_utf8], tree.branch.revision_history())
501
 
        finally:
502
 
            tree.branch.unlock()
 
514
        branch = tree.branch
 
515
 
 
516
        branch_token, repo_token = self.lock_branch(branch)
 
517
        backing = self.get_transport()
 
518
        request = smart.branch.SmartServerBranchRequestSetLastRevisionInfo(
 
519
            backing)
 
520
        self.assertBranchLastRevisionInfo((2, 'revision-2'), '.')
 
521
        response = request.execute(
 
522
            '', branch_token, repo_token, '1', 'revision-1')
 
523
        self.assertEqual(SmartServerResponse(('ok',)), response)
 
524
        self.assertBranchLastRevisionInfo((1, 'revision-1'), '.')
 
525
 
 
526
    def test_not_present_revid(self):
 
527
        """Some branch formats will check that the revision is present in the
 
528
        repository.  When that check fails, a NoSuchRevision error is returned
 
529
        to the client.
 
530
        """
 
531
        # Make a knit format branch, because that format checks the values
 
532
        # given to set_last_revision_info.
 
533
        b, branch_token, repo_token = self.make_locked_branch(format='knit')
 
534
        backing = self.get_transport()
 
535
        request = smart.branch.SmartServerBranchRequestSetLastRevisionInfo(
 
536
            backing)
 
537
        response = request.execute(
 
538
            '', branch_token, repo_token, '1', 'not-present')
 
539
        self.assertEqual(
 
540
            SmartServerResponse(('NoSuchRevision', 'not-present')), response)
503
541
 
504
542
 
505
543
class TestSmartServerBranchRequestLockWrite(tests.TestCaseWithMemoryTransport):