~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Andrew Bennetts
  • Date: 2008-04-08 07:44:39 UTC
  • mto: This revision was merged to the branch mainline in revision 3355.
  • Revision ID: andrew.bennetts@canonical.com-20080408074439-n3j4ic7bcliq9s05
Add backwards compatibility for servers older than 1.4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
496
496
 
497
497
class TestBranchSetLastRevisionInfo(tests.TestCase):
498
498
 
499
 
    def test_set_empty(self):
 
499
    def test_set_last_revision_info(self):
500
500
        # set_last_revision_info(num, 'rev-id') is translated to calling
501
501
        # Branch.set_last_revision_info(num, 'rev-id') on the wire.
502
502
        transport = MemoryTransport()
553
553
            errors.NoSuchRevision, branch.set_last_revision_info, 123, 'revid')
554
554
        branch.unlock()
555
555
 
 
556
    def lock_remote_branch(self, branch):
 
557
        """Trick a RemoteBranch into thinking it is locked."""
 
558
        branch._lock_mode = 'w'
 
559
        branch._lock_count = 2
 
560
        branch._lock_token = 'branch token'
 
561
        branch._repo_lock_token = 'repo token'
 
562
 
 
563
    def test_backwards_compatibility(self):
 
564
        """If the server does not support the Branch.set_last_revision_info
 
565
        verb (which is new in 1.4), then the client falls back to VFS methods.
 
566
        """
 
567
        # This test is a little messy.  Unlike most tests in this file, it
 
568
        # doesn't purely test what a Remote* object sends over the wire, and
 
569
        # how it reacts to responses from the wire.  It instead relies partly
 
570
        # on asserting that the RemoteBranch will call
 
571
        # self._real_branch.set_last_revision_info(...).
 
572
 
 
573
        # First, set up our RemoteBranch with a FakeClient that raises
 
574
        # UnknownSmartMethod, and a StubRealBranch that logs how it is called.
 
575
        transport = MemoryTransport()
 
576
        transport.mkdir('branch')
 
577
        transport = transport.clone('branch')
 
578
        client = FakeClient(
 
579
            [(('unknown verb', 'Branch.set_last_revision_info',), ),],
 
580
            transport.base)
 
581
        bzrdir = RemoteBzrDir(transport, _client=False)
 
582
        branch = RemoteBranch(bzrdir, None, _client=client)
 
583
        class StubRealBranch(object):
 
584
            def __init__(self):
 
585
                self.calls = []
 
586
            def set_last_revision_info(self, revno, revision_id):
 
587
                self.calls.append(
 
588
                    ('set_last_revision_info', revno, revision_id))
 
589
        real_branch = StubRealBranch()
 
590
        branch._real_branch = real_branch
 
591
        self.lock_remote_branch(branch)
 
592
 
 
593
        # Call set_last_revision_info, and verify it behaved as expected.
 
594
        result = branch.set_last_revision_info(1234, 'a-revision-id')
 
595
        self.assertEqual(
 
596
            [('call', 'Branch.set_last_revision_info',
 
597
                ('branch/', 'branch token', 'repo token',
 
598
                 '1234', 'a-revision-id')),],
 
599
            client._calls)
 
600
        self.assertEqual(
 
601
            [('set_last_revision_info', 1234, 'a-revision-id')],
 
602
            real_branch.calls)
 
603
 
556
604
 
557
605
class TestBranchControlGetBranchConf(tests.TestCaseWithMemoryTransport):
558
606
    """Test branch.control_files api munging...