def test_client_simple_method_call(microservice_url): client = RemoteService(microservice_url) result = client.call_method("sum", params=[1, 2]) assert isinstance(result, Result) assert result.result == 3 result = client.call_method("sum", params={"a": 1, "b": 2}) assert isinstance(result, Result) assert result.result == 3
def test_client_simple_method_call_with_objects(microservice_url): client = RemoteService(microservice_url) req = MethodCall("sum", [1, 2]) result = client.call_method(req) assert isinstance(result, Result) assert result.result == 3 req = MethodCall("sum", {"a": 1, "b": 2}) result = client.call_method(req) assert isinstance(result, Result) assert result.result == 3
def test_simple_call(monkeypatch): service = RemoteService(DUMMY_SERVICE_URL) monkeypatch.setattr(urllib.request, 'urlopen', dummy_urlopen) result = service.call_method("test", []) assert isinstance(result, Result) assert result.id == result.method_call.id
def test_client_simple_method_call_with_errors(microservice_url): client = RemoteService(microservice_url) # too few positional args result = client.call_method("sum", params=[1]) assert isinstance(result, Result) assert result.result is None assert result.error["code"] == -32602 # too many positional args result = client.call_method("sum", params=[1, 2, 3]) assert isinstance(result, Result) assert result.result is None assert result.error["code"] == -32602 # too few kw args result = client.call_method("sum", params={"a": 1}) assert isinstance(result, Result) assert result.result is None assert result.error["code"] == -32602 # too many kw args result = client.call_method("sum", params={"a": 1, "b": 2, "c": 3}) assert isinstance(result, Result) assert result.result is None assert result.error["code"] == -32602 # method not found result = client.call_method("invalid", params={"a": 1, "b": 2, "c": 3}) assert isinstance(result, Result) assert result.result is None assert result.error["code"] == -32601 # internal error result = client.call_method("sum", params=[None, 3]) assert isinstance(result, Result) assert result.result is None assert result.error["code"] == -32603