def test_repr_with_results(self): response = Response("foo") response.data = JSONRPCResponse({ "jsonrpc": "2.0", "error": { "message": "foo" }, "id": 1 }) assert repr(response) == "<Response[0 ok, 1 errors]>"
def test_send_single_request_error(*_): with pytest.raises(ReceivedErrorResponseError): client = DummyClient() client.send_message = Mock(return_value=Response( '{"jsonrpc": "2.0", "error": {"code": 1, "message": "foo"}, "id": 1}' )) client.request("ping")
def test_trimmed(self): req = '{"jsonrpc": "2.0", "result": "%s", "id": 1}' % ("foo" * 100, ) with LogCapture() as capture: DummyClient().log_response(Response(req), trim_log_values=True) capture.check(( "jsonrpcclient.client.response", "INFO", StringComparison(r".*foofoofoof...ofoofoofoo.*"), ))
def test(self): with LogCapture() as capture: DummyClient().log_response( Response('{"jsonrpc": "2.0", "result": 5, "id": 1}')) capture.check(( "jsonrpcclient.client.response", "INFO", StringComparison(r'.*"result": 5.*'), ))
def test_untrimmed(self): """Should not trim""" res = '{"jsonrpc": "2.0", "result": {"foo": "%s"}}' % ("foo" * 100, ) with LogCapture() as capture: DummyClient().log_response(Response(res), trim_log_values=False) capture.check(( "jsonrpcclient.client.response", "INFO", StringComparison(r".*" + "foo" * 100 + ".*"), ))
async def send_message(self, request, **kwargs): res = '{"jsonrpc": "2.0", "result": 1, "id": 1}' return Response(res, raw=sentinel)
def test_repr(self): response = Response("foo") assert repr(response) == "<Response[0]>"
def test(self): response = Response("foo") assert response.text == "foo"
def send_message(self, request): return Response('{"jsonrpc": "2.0", "result": 1, "id": 1}')
def check_request(self, request, *args, **kwargs): data_seats = { "0810300ITA": { "I": 0, "W": 0 }, "0810600ITA": { "I": 0, "W": 0 }, "0810700ITA": { "I": 0, "W": 0 }, "0810110ITA": { "I": 0, "W": 0 }, "0100100ITA": { "I": 326, "W": 98 }, "0810500ITA": { "I": 0, "W": 0 }, "0810200ITA": { "I": 0, "W": 0 }, "0810010ITA": { "I": 0, "W": 0 }, "0810800ITA": { "I": 0, "W": 0 } } data_price = { "0810300ITA": { "I": 17.9, "W": 23.9 }, "0810600ITA": { "I": 15.9, "W": 19.9 }, "0810700ITA": { "I": 16.9, "W": 19.9 }, "0810110ITA": { "I": 14.9, "W": 18.9 }, "0100100ITA": { "I": 21.5, "W": 29.0 }, "0810500ITA": { "I": 15.9, "W": 18.9 }, "0810200ITA": { "I": 17.9, "W": 22.9 }, "0810010ITA": { "I": 17.9, "W": 21.9 }, "0810800ITA": { "I": 16.9, "W": 20.9 } } class MockData: def __init__(self, result): self.result = result res_seats = Response('') res_price = Response('') res_seats_data = MockData(data_seats) res_price_data = MockData(data_price) res_seats.data = res_seats_data res_price.data = res_price_data if request['method'] == 'get_availability': return res_seats elif request['method'] == 'get_price': return res_price
def test_response(): response = Response("foo") assert response.text == "foo"