1089
1088
def test_hello(self):
1090
cmd = request.HelloRequest(None)
1089
cmd = _mod_request.HelloRequest(None, '/')
1091
1090
response = cmd.execute()
1092
1091
self.assertEqual(('ok', '2'), response.args)
1093
1092
self.assertEqual(None, response.body)
1099
1098
wt.add('hello')
1100
1099
rev_id = wt.commit('add hello')
1102
cmd = request.GetBundleRequest(self.get_transport())
1101
cmd = _mod_request.GetBundleRequest(self.get_transport(), '/')
1103
1102
response = cmd.execute('.', rev_id)
1104
1103
bundle = serializer.read_bundle(StringIO(response.body))
1105
1104
self.assertEqual((), response.args)
1115
1114
def build_handler(self, transport):
1116
1115
"""Returns a handler for the commands in protocol version one."""
1117
return request.SmartServerRequestHandler(transport,
1118
request.request_handlers)
1116
return _mod_request.SmartServerRequestHandler(
1117
transport, _mod_request.request_handlers, '/')
1120
1119
def test_construct_request_handler(self):
1121
1120
"""Constructing a request handler should be easy and set defaults."""
1122
handler = request.SmartServerRequestHandler(None, None)
1121
handler = _mod_request.SmartServerRequestHandler(None, commands=None,
1122
root_client_path='/')
1123
1123
self.assertFalse(handler.finished_reading)
1125
1125
def test_hello(self):
1131
1131
def test_disable_vfs_handler_classes_via_environment(self):
1132
1132
# VFS handler classes will raise an error from "execute" if
1133
1133
# BZR_NO_SMART_VFS is set.
1134
handler = vfs.HasRequest(None)
1134
handler = vfs.HasRequest(None, '/')
1135
1135
# set environment variable after construction to make sure it's
1137
1137
# Note that we can safely clobber BZR_NO_SMART_VFS here, because setUp
1279
1279
self.to_server)
1280
1280
self.client_protocol = self.client_protocol_class(self.client_medium)
1281
1281
self.smart_server = InstrumentedServerProtocol(self.server_to_client)
1282
self.smart_server_request = request.SmartServerRequestHandler(
1283
None, request.request_handlers)
1282
self.smart_server_request = _mod_request.SmartServerRequestHandler(
1283
None, _mod_request.request_handlers, root_client_path='/')
1285
1285
def assertOffsetSerialisation(self, expected_offsets, expected_serialised,
1296
1296
# XXX: '_deserialise_offsets' should be a method of the
1297
1297
# SmartServerRequestProtocol in future.
1298
readv_cmd = vfs.ReadvRequest(None)
1298
readv_cmd = vfs.ReadvRequest(None, '/')
1299
1299
offsets = readv_cmd._deserialise_offsets(expected_serialised)
1300
1300
self.assertEqual(expected_offsets, offsets)
1301
1301
serialised = client._serialise_offsets(offsets)
1310
1310
def do_body(cmd, body_bytes):
1311
1311
self.end_received = True
1312
1312
self.assertEqual('abcdefg', body_bytes)
1313
return request.SuccessfulSmartServerResponse(('ok', ))
1313
return _mod_request.SuccessfulSmartServerResponse(('ok', ))
1314
1314
smart_protocol.request._command = FakeCommand()
1315
1315
# Call accept_bytes to make sure that internal state like _body_decoder
1316
1316
# is initialised. This test should probably be given a clearer
1462
1462
None, lambda x: None)
1463
1463
self.assertEqual(1, smart_protocol.next_read_size())
1464
1464
smart_protocol._send_response(
1465
request.SuccessfulSmartServerResponse(('x',)))
1465
_mod_request.SuccessfulSmartServerResponse(('x',)))
1466
1466
self.assertEqual(0, smart_protocol.next_read_size())
1468
1468
def test__send_response_errors_with_base_response(self):
1470
1470
smart_protocol = protocol.SmartServerRequestProtocolOne(
1471
1471
None, lambda x: None)
1472
1472
self.assertRaises(AttributeError, smart_protocol._send_response,
1473
request.SmartServerResponse(('x',)))
1473
_mod_request.SmartServerResponse(('x',)))
1475
1475
def test_query_version(self):
1476
1476
"""query_version on a SmartClientProtocolOne should return a number.
1697
1697
None, lambda x: None)
1698
1698
self.assertEqual(1, smart_protocol.next_read_size())
1699
1699
smart_protocol._send_response(
1700
request.SuccessfulSmartServerResponse(('x',)))
1700
_mod_request.SuccessfulSmartServerResponse(('x',)))
1701
1701
self.assertEqual(0, smart_protocol.next_read_size())
1703
1703
def test__send_response_errors_with_base_response(self):
1705
1705
smart_protocol = protocol.SmartServerRequestProtocolTwo(
1706
1706
None, lambda x: None)
1707
1707
self.assertRaises(AttributeError, smart_protocol._send_response,
1708
request.SmartServerResponse(('x',)))
1708
_mod_request.SmartServerResponse(('x',)))
1710
1710
def test__send_response_includes_failure_marker(self):
1711
1711
"""FailedSmartServerResponse have 'failed\n' after the version."""
1713
1713
smart_protocol = protocol.SmartServerRequestProtocolTwo(
1714
1714
None, out_stream.write)
1715
1715
smart_protocol._send_response(
1716
request.FailedSmartServerResponse(('x',)))
1716
_mod_request.FailedSmartServerResponse(('x',)))
1717
1717
self.assertEqual(protocol.RESPONSE_VERSION_TWO + 'failed\nx\n',
1718
1718
out_stream.getvalue())
1723
1723
smart_protocol = protocol.SmartServerRequestProtocolTwo(
1724
1724
None, out_stream.write)
1725
1725
smart_protocol._send_response(
1726
request.SuccessfulSmartServerResponse(('x',)))
1726
_mod_request.SuccessfulSmartServerResponse(('x',)))
1727
1727
self.assertEqual(protocol.RESPONSE_VERSION_TWO + 'success\nx\n',
1728
1728
out_stream.getvalue())
1957
1957
class TestSuccessfulSmartServerResponse(tests.TestCase):
1959
1959
def test_construct(self):
1960
response = request.SuccessfulSmartServerResponse(('foo', 'bar'))
1960
response = _mod_request.SuccessfulSmartServerResponse(('foo', 'bar'))
1961
1961
self.assertEqual(('foo', 'bar'), response.args)
1962
1962
self.assertEqual(None, response.body)
1963
response = request.SuccessfulSmartServerResponse(('foo', 'bar'), 'bytes')
1963
response = _mod_request.SuccessfulSmartServerResponse(('foo', 'bar'), 'bytes')
1964
1964
self.assertEqual(('foo', 'bar'), response.args)
1965
1965
self.assertEqual('bytes', response.body)
1967
1967
def test_is_successful(self):
1968
1968
"""is_successful should return True for SuccessfulSmartServerResponse."""
1969
response = request.SuccessfulSmartServerResponse(('error',))
1969
response = _mod_request.SuccessfulSmartServerResponse(('error',))
1970
1970
self.assertEqual(True, response.is_successful())
1973
1973
class TestFailedSmartServerResponse(tests.TestCase):
1975
1975
def test_construct(self):
1976
response = request.FailedSmartServerResponse(('foo', 'bar'))
1976
response = _mod_request.FailedSmartServerResponse(('foo', 'bar'))
1977
1977
self.assertEqual(('foo', 'bar'), response.args)
1978
1978
self.assertEqual(None, response.body)
1979
response = request.FailedSmartServerResponse(('foo', 'bar'), 'bytes')
1979
response = _mod_request.FailedSmartServerResponse(('foo', 'bar'), 'bytes')
1980
1980
self.assertEqual(('foo', 'bar'), response.args)
1981
1981
self.assertEqual('bytes', response.body)
1983
1983
def test_is_successful(self):
1984
1984
"""is_successful should return False for FailedSmartServerResponse."""
1985
response = request.FailedSmartServerResponse(('error',))
1985
response = _mod_request.FailedSmartServerResponse(('error',))
1986
1986
self.assertEqual(False, response.is_successful())