~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Andrew Bennetts
  • Date: 2009-09-09 13:05:33 UTC
  • mfrom: (4634.6.29 2.0)
  • mto: This revision was merged to the branch mainline in revision 4680.
  • Revision ID: andrew.bennetts@canonical.com-20090909130533-sj6boqxko6panyo2
Merge 2.0 tip, including fixes for 408841, 423506, 406687, 418931.

Show diffs side-by-side

added added

removed removed

Lines of Context:
280
280
        self.expecting_body = True
281
281
        return result[1], FakeProtocol(result[2], self)
282
282
 
 
283
    def call_with_body_bytes(self, method, args, body):
 
284
        self._check_call(method, args)
 
285
        self._calls.append(('call_with_body_bytes', method, args, body))
 
286
        result = self._get_next_response()
 
287
        return result[1], FakeProtocol(result[2], self)
 
288
 
283
289
    def call_with_body_bytes_expecting_body(self, method, args, body):
284
290
        self._check_call(method, args)
285
291
        self._calls.append(('call_with_body_bytes_expecting_body', method,
851
857
 
852
858
class RemoteBranchTestCase(RemoteBzrDirTestCase):
853
859
 
 
860
    def lock_remote_branch(self, branch):
 
861
        """Trick a RemoteBranch into thinking it is locked."""
 
862
        branch._lock_mode = 'w'
 
863
        branch._lock_count = 2
 
864
        branch._lock_token = 'branch token'
 
865
        branch._repo_lock_token = 'repo token'
 
866
        branch.repository._lock_mode = 'w'
 
867
        branch.repository._lock_count = 2
 
868
        branch.repository._lock_token = 'repo token'
 
869
 
854
870
    def make_remote_branch(self, transport, client):
855
871
        """Make a RemoteBranch using 'client' as its _SmartClient.
856
872
 
995
1011
        self.assertEqual({}, result)
996
1012
 
997
1013
 
 
1014
class TestBranchSetTagsBytes(RemoteBranchTestCase):
 
1015
 
 
1016
    def test_trivial(self):
 
1017
        transport = MemoryTransport()
 
1018
        client = FakeClient(transport.base)
 
1019
        client.add_expected_call(
 
1020
            'Branch.get_stacked_on_url', ('quack/',),
 
1021
            'error', ('NotStacked',))
 
1022
        client.add_expected_call(
 
1023
            'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
 
1024
            'success', ('',))
 
1025
        transport.mkdir('quack')
 
1026
        transport = transport.clone('quack')
 
1027
        branch = self.make_remote_branch(transport, client)
 
1028
        self.lock_remote_branch(branch)
 
1029
        branch._set_tags_bytes('tags bytes')
 
1030
        self.assertFinished(client)
 
1031
        self.assertEqual('tags bytes', client._calls[-1][-1])
 
1032
 
 
1033
    def test_backwards_compatible(self):
 
1034
        transport = MemoryTransport()
 
1035
        client = FakeClient(transport.base)
 
1036
        client.add_expected_call(
 
1037
            'Branch.get_stacked_on_url', ('quack/',),
 
1038
            'error', ('NotStacked',))
 
1039
        client.add_expected_call(
 
1040
            'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
 
1041
            'unknown', ('Branch.set_tags_bytes',))
 
1042
        transport.mkdir('quack')
 
1043
        transport = transport.clone('quack')
 
1044
        branch = self.make_remote_branch(transport, client)
 
1045
        self.lock_remote_branch(branch)
 
1046
        class StubRealBranch(object):
 
1047
            def __init__(self):
 
1048
                self.calls = []
 
1049
            def _set_tags_bytes(self, bytes):
 
1050
                self.calls.append(('set_tags_bytes', bytes))
 
1051
        real_branch = StubRealBranch()
 
1052
        branch._real_branch = real_branch
 
1053
        branch._set_tags_bytes('tags bytes')
 
1054
        # Call a second time, to exercise the 'remote version already inferred'
 
1055
        # code path.
 
1056
        branch._set_tags_bytes('tags bytes')
 
1057
        self.assertFinished(client)
 
1058
        self.assertEqual(
 
1059
            [('set_tags_bytes', 'tags bytes')] * 2, real_branch.calls)
 
1060
 
 
1061
 
998
1062
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
999
1063
 
1000
1064
    def test_empty_branch(self):
1342
1406
            errors.NoSuchRevision, branch.set_last_revision_info, 123, 'revid')
1343
1407
        branch.unlock()
1344
1408
 
1345
 
    def lock_remote_branch(self, branch):
1346
 
        """Trick a RemoteBranch into thinking it is locked."""
1347
 
        branch._lock_mode = 'w'
1348
 
        branch._lock_count = 2
1349
 
        branch._lock_token = 'branch token'
1350
 
        branch._repo_lock_token = 'repo token'
1351
 
        branch.repository._lock_mode = 'w'
1352
 
        branch.repository._lock_count = 2
1353
 
        branch.repository._lock_token = 'repo token'
1354
 
 
1355
1409
    def test_backwards_compatibility(self):
1356
1410
        """If the server does not support the Branch.set_last_revision_info
1357
1411
        verb (which is new in 1.4), then the client falls back to VFS methods.
2325
2379
        class FakeRealRepository:
2326
2380
            def _get_sink(self):
2327
2381
                return fake_real_sink
 
2382
            def is_in_write_group(self):
 
2383
                return False
 
2384
            def refresh_data(self):
 
2385
                return True
2328
2386
        repo._real_repository = FakeRealRepository()
2329
2387
        sink = repo._get_sink()
2330
2388
        fmt = repository.RepositoryFormat.get_default_format()