~bzr-pqm/bzr/1.18

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-09-09 10:28:26 UTC
  • mfrom: (4599.2.2 prepare-1.18)
  • Revision ID: pqm@pqm.ubuntu.com-20090909102826-jkrd7cavj2qv5m2m
(mbp) prepare 1.18.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
277
277
        self.expecting_body = True
278
278
        return result[1], FakeProtocol(result[2], self)
279
279
 
 
280
    def call_with_body_bytes(self, method, args, body):
 
281
        self._check_call(method, args)
 
282
        self._calls.append(('call_with_body_bytes', method, args, body))
 
283
        result = self._get_next_response()
 
284
        return result[1], FakeProtocol(result[2], self)
 
285
 
280
286
    def call_with_body_bytes_expecting_body(self, method, args, body):
281
287
        self._check_call(method, args)
282
288
        self._calls.append(('call_with_body_bytes_expecting_body', method,
856
862
 
857
863
class RemoteBranchTestCase(RemoteBzrDirTestCase):
858
864
 
 
865
    def lock_remote_branch(self, branch):
 
866
        """Trick a RemoteBranch into thinking it is locked."""
 
867
        branch._lock_mode = 'w'
 
868
        branch._lock_count = 2
 
869
        branch._lock_token = 'branch token'
 
870
        branch._repo_lock_token = 'repo token'
 
871
        branch.repository._lock_mode = 'w'
 
872
        branch.repository._lock_count = 2
 
873
        branch.repository._lock_token = 'repo token'
 
874
 
859
875
    def make_remote_branch(self, transport, client):
860
876
        """Make a RemoteBranch using 'client' as its _SmartClient.
861
877
 
1000
1016
        self.assertEqual({}, result)
1001
1017
 
1002
1018
 
 
1019
class TestBranchSetTagsBytes(RemoteBranchTestCase):
 
1020
 
 
1021
    def test_trivial(self):
 
1022
        transport = MemoryTransport()
 
1023
        client = FakeClient(transport.base)
 
1024
        client.add_expected_call(
 
1025
            'Branch.get_stacked_on_url', ('quack/',),
 
1026
            'error', ('NotStacked',))
 
1027
        client.add_expected_call(
 
1028
            'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
 
1029
            'success', ('',))
 
1030
        transport.mkdir('quack')
 
1031
        transport = transport.clone('quack')
 
1032
        branch = self.make_remote_branch(transport, client)
 
1033
        self.lock_remote_branch(branch)
 
1034
        branch._set_tags_bytes('tags bytes')
 
1035
        self.assertFinished(client)
 
1036
        self.assertEqual('tags bytes', client._calls[-1][-1])
 
1037
 
 
1038
    def test_backwards_compatible(self):
 
1039
        transport = MemoryTransport()
 
1040
        client = FakeClient(transport.base)
 
1041
        client.add_expected_call(
 
1042
            'Branch.get_stacked_on_url', ('quack/',),
 
1043
            'error', ('NotStacked',))
 
1044
        client.add_expected_call(
 
1045
            'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
 
1046
            'unknown', ('Branch.set_tags_bytes',))
 
1047
        transport.mkdir('quack')
 
1048
        transport = transport.clone('quack')
 
1049
        branch = self.make_remote_branch(transport, client)
 
1050
        self.lock_remote_branch(branch)
 
1051
        class StubRealBranch(object):
 
1052
            def __init__(self):
 
1053
                self.calls = []
 
1054
            def _set_tags_bytes(self, bytes):
 
1055
                self.calls.append(('set_tags_bytes', bytes))
 
1056
        real_branch = StubRealBranch()
 
1057
        branch._real_branch = real_branch
 
1058
        branch._set_tags_bytes('tags bytes')
 
1059
        # Call a second time, to exercise the 'remote version already inferred'
 
1060
        # code path.
 
1061
        branch._set_tags_bytes('tags bytes')
 
1062
        self.assertFinished(client)
 
1063
        self.assertEqual(
 
1064
            [('set_tags_bytes', 'tags bytes')] * 2, real_branch.calls)
 
1065
 
 
1066
 
1003
1067
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
1004
1068
 
1005
1069
    def test_empty_branch(self):
1347
1411
            errors.NoSuchRevision, branch.set_last_revision_info, 123, 'revid')
1348
1412
        branch.unlock()
1349
1413
 
1350
 
    def lock_remote_branch(self, branch):
1351
 
        """Trick a RemoteBranch into thinking it is locked."""
1352
 
        branch._lock_mode = 'w'
1353
 
        branch._lock_count = 2
1354
 
        branch._lock_token = 'branch token'
1355
 
        branch._repo_lock_token = 'repo token'
1356
 
        branch.repository._lock_mode = 'w'
1357
 
        branch.repository._lock_count = 2
1358
 
        branch.repository._lock_token = 'repo token'
1359
 
 
1360
1414
    def test_backwards_compatibility(self):
1361
1415
        """If the server does not support the Branch.set_last_revision_info
1362
1416
        verb (which is new in 1.4), then the client falls back to VFS methods.