Skip to content

Commit e5c0534

Browse files
Joshua Massoverpavlov99
authored andcommitted
Add support for positional params
1 parent 77ccded commit e5c0534

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

jsonrpc/backend/django.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def jsonrpc(self, request):
5959
jsonrpc_request_params = copy.copy(jsonrpc_request.params)
6060
if isinstance(jsonrpc_request.params, dict):
6161
jsonrpc_request.params.update(request=request)
62+
if isinstance(jsonrpc_request.params, list):
63+
jsonrpc_request.params.insert(0, request)
6264

6365
t1 = time.time()
6466
response = JSONRPCResponseManager.handle_request(

jsonrpc/tests/test_backend_django/tests.py renamed to jsonrpc/tests/test_backend_django/test_backend.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ def dummy(request):
4444
data = json.loads(response.content.decode('utf8'))
4545
self.assertEqual(data['result'], '')
4646

47+
def test_positional_args(self):
48+
@api.dispatcher.add_method
49+
def positional_args(request, name):
50+
return name
51+
52+
json_data = {
53+
"id": "0",
54+
"jsonrpc": "2.0",
55+
"method": "positional_args",
56+
"params": ["echome!"],
57+
}
58+
response = self.client.post(
59+
'',
60+
json.dumps(json_data),
61+
content_type='application/json',
62+
)
63+
self.assertEqual(response.status_code, 200)
64+
data = json.loads(response.content.decode('utf8'))
65+
self.assertEqual(data['result'], json_data['params'][0])
66+
4767
def test_method_not_allowed(self):
4868
response = self.client.get(
4969
'',

0 commit comments

Comments
 (0)