280
279
self.expecting_body = True
281
280
return result[1], FakeProtocol(result[2], self)
282
def call_with_body_bytes(self, method, args, body):
283
self._check_call(method, args)
284
self._calls.append(('call_with_body_bytes', method, args, body))
285
result = self._get_next_response()
286
return result[1], FakeProtocol(result[2], self)
283
288
def call_with_body_bytes_expecting_body(self, method, args, body):
284
289
self._check_call(method, args)
285
290
self._calls.append(('call_with_body_bytes_expecting_body', method,
468
473
self.assertFinished(client)
476
class TestBzrDirOpen(TestRemote):
478
def make_fake_client_and_transport(self, path='quack'):
479
transport = MemoryTransport()
480
transport.mkdir(path)
481
transport = transport.clone(path)
482
client = FakeClient(transport.base)
483
return client, transport
485
def test_absent(self):
486
client, transport = self.make_fake_client_and_transport()
487
client.add_expected_call(
488
'BzrDir.open_2.1', ('quack/',), 'success', ('no',))
489
self.assertRaises(errors.NotBranchError, RemoteBzrDir, transport,
490
remote.RemoteBzrDirFormat(), _client=client, _force_probe=True)
491
self.assertFinished(client)
493
def test_present_without_workingtree(self):
494
client, transport = self.make_fake_client_and_transport()
495
client.add_expected_call(
496
'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'no'))
497
bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
498
_client=client, _force_probe=True)
499
self.assertIsInstance(bd, RemoteBzrDir)
500
self.assertFalse(bd.has_workingtree())
501
self.assertRaises(errors.NoWorkingTree, bd.open_workingtree)
502
self.assertFinished(client)
504
def test_present_with_workingtree(self):
505
client, transport = self.make_fake_client_and_transport()
506
client.add_expected_call(
507
'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'yes'))
508
bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
509
_client=client, _force_probe=True)
510
self.assertIsInstance(bd, RemoteBzrDir)
511
self.assertTrue(bd.has_workingtree())
512
self.assertRaises(errors.NotLocalUrl, bd.open_workingtree)
513
self.assertFinished(client)
515
def test_backwards_compat(self):
516
client, transport = self.make_fake_client_and_transport()
517
client.add_expected_call(
518
'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
519
client.add_expected_call(
520
'BzrDir.open', ('quack/',), 'success', ('yes',))
521
bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
522
_client=client, _force_probe=True)
523
self.assertIsInstance(bd, RemoteBzrDir)
524
self.assertFinished(client)
471
527
class TestBzrDirOpenBranch(TestRemote):
473
529
def test_backwards_compat(self):
683
739
# fallback all the way to the first version.
684
740
reference_format = self.get_repo_format()
685
741
network_name = reference_format.network_name()
686
client = FakeClient('bzr://example.com/')
742
server_url = 'bzr://example.com/'
743
self.permit_url(server_url)
744
client = FakeClient(server_url)
687
745
client.add_unknown_method_response('BzrDir.find_repositoryV3')
688
746
client.add_unknown_method_response('BzrDir.find_repositoryV2')
689
747
client.add_success_response('ok', '', 'no', 'no')
695
753
reference_format.get_format_string(), 'ok')
696
754
# PackRepository wants to do a stat
697
755
client.add_success_response('stat', '0', '65535')
698
remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
756
remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
700
758
bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
715
773
# fallback to find_repositoryV2
716
774
reference_format = self.get_repo_format()
717
775
network_name = reference_format.network_name()
718
client = FakeClient('bzr://example.com/')
776
server_url = 'bzr://example.com/'
777
self.permit_url(server_url)
778
client = FakeClient(server_url)
719
779
client.add_unknown_method_response('BzrDir.find_repositoryV3')
720
780
client.add_success_response('ok', '', 'no', 'no', 'no')
721
781
# A real repository instance will be created to determine the network
726
786
reference_format.get_format_string(), 'ok')
727
787
# PackRepository wants to do a stat
728
788
client.add_success_response('stat', '0', '65535')
729
remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
789
remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
731
791
bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
852
912
class RemoteBranchTestCase(RemoteBzrDirTestCase):
914
def lock_remote_branch(self, branch):
915
"""Trick a RemoteBranch into thinking it is locked."""
916
branch._lock_mode = 'w'
917
branch._lock_count = 2
918
branch._lock_token = 'branch token'
919
branch._repo_lock_token = 'repo token'
920
branch.repository._lock_mode = 'w'
921
branch.repository._lock_count = 2
922
branch.repository._lock_token = 'repo token'
854
924
def make_remote_branch(self, transport, client):
855
925
"""Make a RemoteBranch using 'client' as its _SmartClient.
995
1065
self.assertEqual({}, result)
1068
class TestBranchSetTagsBytes(RemoteBranchTestCase):
1070
def test_trivial(self):
1071
transport = MemoryTransport()
1072
client = FakeClient(transport.base)
1073
client.add_expected_call(
1074
'Branch.get_stacked_on_url', ('quack/',),
1075
'error', ('NotStacked',))
1076
client.add_expected_call(
1077
'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
1079
transport.mkdir('quack')
1080
transport = transport.clone('quack')
1081
branch = self.make_remote_branch(transport, client)
1082
self.lock_remote_branch(branch)
1083
branch._set_tags_bytes('tags bytes')
1084
self.assertFinished(client)
1085
self.assertEqual('tags bytes', client._calls[-1][-1])
1087
def test_backwards_compatible(self):
1088
transport = MemoryTransport()
1089
client = FakeClient(transport.base)
1090
client.add_expected_call(
1091
'Branch.get_stacked_on_url', ('quack/',),
1092
'error', ('NotStacked',))
1093
client.add_expected_call(
1094
'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
1095
'unknown', ('Branch.set_tags_bytes',))
1096
transport.mkdir('quack')
1097
transport = transport.clone('quack')
1098
branch = self.make_remote_branch(transport, client)
1099
self.lock_remote_branch(branch)
1100
class StubRealBranch(object):
1103
def _set_tags_bytes(self, bytes):
1104
self.calls.append(('set_tags_bytes', bytes))
1105
real_branch = StubRealBranch()
1106
branch._real_branch = real_branch
1107
branch._set_tags_bytes('tags bytes')
1108
# Call a second time, to exercise the 'remote version already inferred'
1110
branch._set_tags_bytes('tags bytes')
1111
self.assertFinished(client)
1113
[('set_tags_bytes', 'tags bytes')] * 2, real_branch.calls)
998
1116
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
1000
1118
def test_empty_branch(self):
1342
1460
errors.NoSuchRevision, branch.set_last_revision_info, 123, 'revid')
1343
1461
branch.unlock()
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'
1355
1463
def test_backwards_compatibility(self):
1356
1464
"""If the server does not support the Branch.set_last_revision_info
1357
1465
verb (which is new in 1.4), then the client falls back to VFS methods.
1673
1781
return repo, client
1784
def remoted_description(format):
1785
return 'Remote: ' + format.get_format_description()
1788
class TestBranchFormat(tests.TestCase):
1790
def test_get_format_description(self):
1791
remote_format = RemoteBranchFormat()
1792
real_format = branch.BranchFormat.get_default_format()
1793
remote_format._network_name = real_format.network_name()
1794
self.assertEqual(remoted_description(real_format),
1795
remote_format.get_format_description())
1676
1798
class TestRepositoryFormat(TestRemoteRepository):
1678
1800
def test_fast_delta(self):
1685
1807
false_format._network_name = false_name
1686
1808
self.assertEqual(False, false_format.fast_deltas)
1810
def test_get_format_description(self):
1811
remote_repo_format = RemoteRepositoryFormat()
1812
real_format = repository.RepositoryFormat.get_default_format()
1813
remote_repo_format._network_name = real_format.network_name()
1814
self.assertEqual(remoted_description(real_format),
1815
remote_repo_format.get_format_description())
1689
1818
class TestRepositoryGatherStats(TestRemoteRepository):
2092
2221
repo.get_rev_id_for_revno, 5, (42, 'rev-foo'))
2093
2222
self.assertFinished(client)
2224
def test_branch_fallback_locking(self):
2225
"""RemoteBranch.get_rev_id takes a read lock, and tries to call the
2226
get_rev_id_for_revno verb. If the verb is unknown the VFS fallback
2227
will be invoked, which will fail if the repo is unlocked.
2229
self.setup_smart_server_with_call_log()
2230
tree = self.make_branch_and_memory_tree('.')
2232
rev1 = tree.commit('First')
2233
rev2 = tree.commit('Second')
2235
branch = tree.branch
2236
self.assertFalse(branch.is_locked())
2237
self.reset_smart_call_log()
2238
verb = 'Repository.get_rev_id_for_revno'
2239
self.disable_verb(verb)
2240
self.assertEqual(rev1, branch.get_rev_id(1))
2241
self.assertLength(1, [call for call in self.hpss_calls if
2242
call.call.method == verb])
2096
2245
class TestRepositoryIsShared(TestRemoteRepository):