Skip to content
Snippets Groups Projects

rpc_client: Allow http method declaration consistently with the rpc server

1 unresolved thread
Compare and
3 files
+ 70
19
Compare changes
  • Side-by-side
  • Inline
Files
3
# Copyright (C) 2018-2019 The Software Heritage developers
# Copyright (C) 2018-2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -27,6 +27,10 @@ def rpc_client(requests_mock):
def serializer_test(self, data, db=None, cur=None):
...
@remote_api_endpoint("another_endpoint", method="GET")
def some_get_method(self, data):
...
@remote_api_endpoint("overridden/endpoint")
def overridden_method(self, data):
return "foo"
@@ -39,7 +43,7 @@ def rpc_client(requests_mock):
def overridden_method(self, data):
return "bar"
def callback(request, context):
def callback_post(request, context):
assert request.headers["Content-Type"] == "application/x-msgpack"
context.headers["Content-Type"] = "application/x-msgpack"
if request.path == "/test_endpoint_url":
@@ -55,7 +59,17 @@ def rpc_client(requests_mock):
assert False
return context.content
requests_mock.post(re.compile("mock://example.com/"), content=callback)
def callback_get(request, context):
context.headers["Content-Type"] = "application/x-msgpack"
if request.path == "/another_endpoint":
context.content = b"\xc4\x0eanother-result"
else:
assert False
return context.content
requests_mock.post(re.compile("mock://example.com/"), content=callback_post)
requests_mock.get(re.compile("mock://example.com/"), content=callback_get)
return Testclient(url="mock://example.com")
@@ -75,6 +89,9 @@ def test_client(rpc_client):
res = rpc_client.something(data="whatever")
assert res == "spam"
res = rpc_client.some_get_method(data="something")
assert res == b"another-result"
def test_client_extra_serializers(rpc_client):
res = rpc_client.serializer_test(["foo", ExtraType("bar", b"baz")])
Loading