def test_simple_batch_call(monkeypatch): service = RemoteService(DUMMY_SERVICE_URL) monkeypatch.setattr(urllib.request, 'urlopen', dummy_urlopen_batch) calls = [ MethodCall("test", []), MethodCall("test2", []), MethodCall("test3", []) ] result = service.call_batch(*calls) assert isinstance(result, BatchResult) assert len(result) == 3 assert result.get_response_for_call(calls[0]).id == calls[0].id assert result.get_response_for_call(calls[1]).id == calls[1].id assert result.get_response_for_call(calls[2]).id == calls[2].id assert result.get_response_for_call(MethodCall("invalid")) is None
def test_client_batch_call(microservice_url): client = RemoteService(microservice_url) requests = [ MethodCall("sum", [1, 2]), MethodCall("divide", [10, 5]), MethodCall("sum", [10, -10]), MethodCall("sum", ["hello", " world"]), MethodCall("sum", [1, 2, 3]), # error Notification("sum", [1, 2]) ] resp = client.call_batch(*requests) assert len(resp) == 5 assert resp.get_response_for_call(requests[0]).result == 3 assert resp.get_response_for_call(requests[1]).result == 2. assert resp.get_response_for_call(requests[2]).result == 0 assert resp.get_response_for_call(requests[3]).result == "hello world" assert resp.get_response_for_call(requests[5]) is None # it was a notification
def test_batch_call_errors(): service = RemoteService(DUMMY_SERVICE_URL) with pytest.raises(TypeError): service.call_batch(1, 2, 3)