280
280
self.expecting_body = True
281
281
return result[1], FakeProtocol(result[2], self)
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)
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,
468
474
self.assertFinished(client)
477
class TestBzrDirOpen(TestRemote):
479
def make_fake_client_and_transport(self, path='quack'):
480
transport = MemoryTransport()
481
transport.mkdir(path)
482
transport = transport.clone(path)
483
client = FakeClient(transport.base)
484
return client, transport
486
def test_absent(self):
487
client, transport = self.make_fake_client_and_transport()
488
client.add_expected_call(
489
'BzrDir.open_2.1', ('quack/',), 'success', ('no',))
490
self.assertRaises(errors.NotBranchError, RemoteBzrDir, transport,
491
remote.RemoteBzrDirFormat(), _client=client, _force_probe=True)
492
self.assertFinished(client)
494
def test_present_without_workingtree(self):
495
client, transport = self.make_fake_client_and_transport()
496
client.add_expected_call(
497
'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'no'))
498
bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
499
_client=client, _force_probe=True)
500
self.assertIsInstance(bd, RemoteBzrDir)
501
self.assertFalse(bd.has_workingtree())
502
self.assertRaises(errors.NoWorkingTree, bd.open_workingtree)
503
self.assertFinished(client)
505
def test_present_with_workingtree(self):
506
client, transport = self.make_fake_client_and_transport()
507
client.add_expected_call(
508
'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'yes'))
509
bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
510
_client=client, _force_probe=True)
511
self.assertIsInstance(bd, RemoteBzrDir)
512
self.assertTrue(bd.has_workingtree())
513
self.assertRaises(errors.NotLocalUrl, bd.open_workingtree)
514
self.assertFinished(client)
516
def test_backwards_compat(self):
517
client, transport = self.make_fake_client_and_transport()
518
client.add_expected_call(
519
'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
520
client.add_expected_call(
521
'BzrDir.open', ('quack/',), 'success', ('yes',))
522
bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
523
_client=client, _force_probe=True)
524
self.assertIsInstance(bd, RemoteBzrDir)
525
self.assertFinished(client)
471
528
class TestBzrDirOpenBranch(TestRemote):
473
530
def test_backwards_compat(self):
683
740
# fallback all the way to the first version.
684
741
reference_format = self.get_repo_format()
685
742
network_name = reference_format.network_name()
686
client = FakeClient('bzr://example.com/')
743
server_url = 'bzr://example.com/'
744
self.permit_url(server_url)
745
client = FakeClient(server_url)
687
746
client.add_unknown_method_response('BzrDir.find_repositoryV3')
688
747
client.add_unknown_method_response('BzrDir.find_repositoryV2')
689
748
client.add_success_response('ok', '', 'no', 'no')
695
754
reference_format.get_format_string(), 'ok')
696
755
# PackRepository wants to do a stat
697
756
client.add_success_response('stat', '0', '65535')
698
remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
757
remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
700
759
bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
715
774
# fallback to find_repositoryV2
716
775
reference_format = self.get_repo_format()
717
776
network_name = reference_format.network_name()
718
client = FakeClient('bzr://example.com/')
777
server_url = 'bzr://example.com/'
778
self.permit_url(server_url)
779
client = FakeClient(server_url)
719
780
client.add_unknown_method_response('BzrDir.find_repositoryV3')
720
781
client.add_success_response('ok', '', 'no', 'no', 'no')
721
782
# A real repository instance will be created to determine the network
726
787
reference_format.get_format_string(), 'ok')
727
788
# PackRepository wants to do a stat
728
789
client.add_success_response('stat', '0', '65535')
729
remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
790
remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
731
792
bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
852
913
class RemoteBranchTestCase(RemoteBzrDirTestCase):
915
def lock_remote_branch(self, branch):
916
"""Trick a RemoteBranch into thinking it is locked."""
917
branch._lock_mode = 'w'
918
branch._lock_count = 2
919
branch._lock_token = 'branch token'
920
branch._repo_lock_token = 'repo token'
921
branch.repository._lock_mode = 'w'
922
branch.repository._lock_count = 2
923
branch.repository._lock_token = 'repo token'
854
925
def make_remote_branch(self, transport, client):
855
926
"""Make a RemoteBranch using 'client' as its _SmartClient.
995
1066
self.assertEqual({}, result)
1069
class TestBranchSetTagsBytes(RemoteBranchTestCase):
1071
def test_trivial(self):
1072
transport = MemoryTransport()
1073
client = FakeClient(transport.base)
1074
client.add_expected_call(
1075
'Branch.get_stacked_on_url', ('quack/',),
1076
'error', ('NotStacked',))
1077
client.add_expected_call(
1078
'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
1080
transport.mkdir('quack')
1081
transport = transport.clone('quack')
1082
branch = self.make_remote_branch(transport, client)
1083
self.lock_remote_branch(branch)
1084
branch._set_tags_bytes('tags bytes')
1085
self.assertFinished(client)
1086
self.assertEqual('tags bytes', client._calls[-1][-1])
1088
def test_backwards_compatible(self):
1089
transport = MemoryTransport()
1090
client = FakeClient(transport.base)
1091
client.add_expected_call(
1092
'Branch.get_stacked_on_url', ('quack/',),
1093
'error', ('NotStacked',))
1094
client.add_expected_call(
1095
'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
1096
'unknown', ('Branch.set_tags_bytes',))
1097
transport.mkdir('quack')
1098
transport = transport.clone('quack')
1099
branch = self.make_remote_branch(transport, client)
1100
self.lock_remote_branch(branch)
1101
class StubRealBranch(object):
1104
def _set_tags_bytes(self, bytes):
1105
self.calls.append(('set_tags_bytes', bytes))
1106
real_branch = StubRealBranch()
1107
branch._real_branch = real_branch
1108
branch._set_tags_bytes('tags bytes')
1109
# Call a second time, to exercise the 'remote version already inferred'
1111
branch._set_tags_bytes('tags bytes')
1112
self.assertFinished(client)
1114
[('set_tags_bytes', 'tags bytes')] * 2, real_branch.calls)
998
1117
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
1000
1119
def test_empty_branch(self):
1342
1461
errors.NoSuchRevision, branch.set_last_revision_info, 123, 'revid')
1343
1462
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
1464
def test_backwards_compatibility(self):
1356
1465
"""If the server does not support the Branch.set_last_revision_info
1357
1466
verb (which is new in 1.4), then the client falls back to VFS methods.
2668
2780
expected_error = errors.ReadError(path)
2669
2781
self.assertEqual(expected_error, translated_error)
2783
def test_IncompatibleRepositories(self):
2784
translated_error = self.translateTuple(('IncompatibleRepositories',
2785
"repo1", "repo2", "details here"))
2786
expected_error = errors.IncompatibleRepositories("repo1", "repo2",
2788
self.assertEqual(expected_error, translated_error)
2671
2790
def test_PermissionDenied_no_args(self):
2672
2791
path = 'a path'
2673
2792
translated_error = self.translateTuple(('PermissionDenied',), path=path)