135
135
"""Create a FakeClient.
137
137
:param responses: A list of response-tuple, body-data pairs to be sent
138
back to callers. A special case is if the response-tuple is
139
'unknown verb', then a UnknownSmartMethod will be raised for that
140
call, using the second element of the tuple as the verb in the
140
143
self.responses = responses
142
145
self.expecting_body = False
143
146
_SmartClient.__init__(self, FakeMedium(fake_medium_base, self._calls))
148
def _get_next_response(self):
149
response_tuple = self.responses.pop(0)
150
if response_tuple[0][0] == 'unknown verb':
151
raise errors.UnknownSmartMethod(response_tuple[0][1])
152
return response_tuple
145
154
def call(self, method, *args):
146
155
self._calls.append(('call', method, args))
147
return self.responses.pop(0)[0]
156
return self._get_next_response()[0]
149
158
def call_expecting_body(self, method, *args):
150
159
self._calls.append(('call_expecting_body', method, args))
151
result = self.responses.pop(0)
160
result = self._get_next_response()
152
161
self.expecting_body = True
153
162
return result[0], FakeProtocol(result[1], self)
155
164
def call_with_body_bytes_expecting_body(self, method, args, body):
156
165
self._calls.append(('call_with_body_bytes_expecting_body', method,
158
result = self.responses.pop(0)
167
result = self._get_next_response()
159
168
self.expecting_body = True
160
169
return result[0], FakeProtocol(result[1], self)
289
298
RemoteBzrDirFormat.probe_transport, OldServerTransport())
301
class TestBzrDirOpenRepository(tests.TestCase):
303
def test_backwards_compat_1_2(self):
304
transport = MemoryTransport()
305
transport.mkdir('quack')
306
transport = transport.clone('quack')
307
client = FakeClient([
308
(('unknown verb', 'RemoteRepository.find_repositoryV2'), ''),
309
(('ok', '', 'no', 'no'), ''),],
311
bzrdir = RemoteBzrDir(transport, _client=client)
312
repo = bzrdir.open_repository()
314
[('call', 'BzrDir.find_repositoryV2', ('quack/',)),
315
('call', 'BzrDir.find_repository', ('quack/',))],
292
319
class OldSmartClient(object):
293
320
"""A fake smart client for test_old_version that just returns a version one
294
321
response to the 'hello' (query version) command.
507
534
advisory anyway (a transport could be read-write, but then the
508
535
underlying filesystem could be readonly anyway).
510
client = FakeClient([(
511
('error', "Generic bzr smart protocol error: "
512
"bad request 'Transport.is_readonly'"), '')])
513
transport = RemoteTransport('bzr://example.com/', medium=False,
515
self.assertEqual(False, transport.is_readonly())
517
[('call', 'Transport.is_readonly', ())],
520
def test_error_from_old_0_11_server(self):
521
"""Same as test_error_from_old_server, but with the slightly different
522
error message from bzr 0.11 servers.
524
client = FakeClient([(
525
('error', "Generic bzr smart protocol error: "
526
"bad request u'Transport.is_readonly'"), '')])
537
client = FakeClient([(('unknown verb', 'Transport.is_readonly'), '')])
527
538
transport = RemoteTransport('bzr://example.com/', medium=False,
529
540
self.assertEqual(False, transport.is_readonly())
677
688
def test_get_parent_map_reconnects_if_unknown_method(self):
679
"Generic bzr smart protocol error: "
680
"bad request 'Repository.get_parent_map'")
682
(('error', error_msg), ''),
690
(('unknown verb', 'Repository.get_parent_map'), ''),
684
692
transport_path = 'quack'
685
693
repo, client = self.setup_fake_client_and_repository(
960
968
def test_backwards_compatibility(self):
961
969
"""If the server doesn't recognise this request, fallback to VFS."""
963
"Generic bzr smart protocol error: "
964
"bad request 'Repository.stream_revisions_chunked'")
966
(('error', error_msg), '')]
971
(('unknown verb', 'Repository.stream_revisions_chunked'), '')]
967
972
repo, client = self.setup_fake_client_and_repository(
968
973
responses, 'path')
969
974
self.mock_called = False