Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Use the passed-in name for constructing repr() of JsonMethod. #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aiohttp_json_rpc/auth/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
7 changes: 4 additions & 3 deletions aiohttp_json_rpc/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -80,7 +81,7 @@ def __init__(self, method):
]

self._repr_str = 'JsonRpcMethod({}({}))'.format(
self.method.__name__,
name or self.method.__name__,
', '.join(args),
)

Expand Down Expand Up @@ -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):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])