~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Aaron Bentley
  • Date: 2008-04-24 04:58:42 UTC
  • mfrom: (3377 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3380.
  • Revision ID: aaron@aaronbentley.com-20080424045842-0cajl9v6s4u52kaw
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
476
476
            tree.branch.unlock()
477
477
 
478
478
 
 
479
class TestSmartServerBranchRequestSetLastRevisionInfo(tests.TestCaseWithTransport):
 
480
 
 
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()
 
496
        backing = self.get_transport()
 
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."""
 
508
        tree = self.make_branch_and_memory_tree('.')
 
509
        tree.lock_write()
 
510
        tree.add('')
 
511
        tree.commit('First commit', rev_id='revision-1')
 
512
        tree.commit('Second commit', rev_id='revision-2')
 
513
        tree.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)
 
541
 
 
542
 
479
543
class TestSmartServerBranchRequestLockWrite(tests.TestCaseWithMemoryTransport):
480
544
 
481
545
    def setUp(self):
1014
1078
            smart.request.request_handlers.get('Branch.set_last_revision'),
1015
1079
            smart.branch.SmartServerBranchRequestSetLastRevision)
1016
1080
        self.assertEqual(
 
1081
            smart.request.request_handlers.get('Branch.set_last_revision_info'),
 
1082
            smart.branch.SmartServerBranchRequestSetLastRevisionInfo)
 
1083
        self.assertEqual(
1017
1084
            smart.request.request_handlers.get('Branch.unlock'),
1018
1085
            smart.branch.SmartServerBranchRequestUnlock)
1019
1086
        self.assertEqual(