diff --git a/aiohttp_json_rpc/auth/django.py b/aiohttp_json_rpc/auth/django.py index e27cd23..a710499 100644 --- a/aiohttp_json_rpc/auth/django.py +++ b/aiohttp_json_rpc/auth/django.py @@ -213,7 +213,7 @@ async def prepare_request(self, request, user=None): if action in ('view', 'add', 'change', 'delete', ): request.methods[method_name] = JsonRpcMethod( - self.handle_orm_call) + self.handle_orm_call, method_name) # rpc defined methods for name, method in request.rpc.methods.items(): diff --git a/aiohttp_json_rpc/rpc.py b/aiohttp_json_rpc/rpc.py index be2e91d..dd482ff 100644 --- a/aiohttp_json_rpc/rpc.py +++ b/aiohttp_json_rpc/rpc.py @@ -31,8 +31,9 @@ class JsonRpcMethod: CREDENTIAL_KEYS = ['request', 'worker_pool'] - def __init__(self, method): + def __init__(self, method, name=None): self.method = method + self.name = name # method introspection try: @@ -80,7 +81,7 @@ def __init__(self, method): ] self._repr_str = 'JsonRpcMethod({}({}))'.format( - self.method.__name__, + name or self.method.__name__, ', '.join(args), ) @@ -179,7 +180,7 @@ def _add_method(self, method, name='', prefix=''): if prefix: name = '{}__{}'.format(prefix, name) - self.methods[name] = JsonRpcMethod(method) + self.methods[name] = JsonRpcMethod(method, name) def _add_methods_from_object(self, obj, prefix='', ignore=[]): for attr_name in dir(obj): diff --git a/tests/test_methods.py b/tests/test_methods.py index e8c8e1d..3bf13fc 100644 --- a/tests/test_methods.py +++ b/tests/test_methods.py @@ -101,3 +101,19 @@ async def unnamed_method(request): assert await client.call('method1') == 'method1' assert await client.call('method2') == 'method2' + + assert 'method1' in repr(rpc_context.rpc.methods['method1']) + + +@pytest.mark.asyncio +async def test_partial_method(rpc_context, caplog): + from functools import partial + + async def pong(request, msg): + return msg + + rpc_context.rpc.add_methods( + ('', partial(pong, msg="pong"), "pong"), + ) + + assert 'pong' in repr(rpc_context.rpc.methods['pong'])