Skip to content

Django backend positional arg support #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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: 2 additions & 0 deletions jsonrpc/backend/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def jsonrpc(self, request):
jsonrpc_request_params = copy.copy(jsonrpc_request.params)
if isinstance(jsonrpc_request.params, dict):
jsonrpc_request.params.update(request=request)
if isinstance(jsonrpc_request.params, list):
jsonrpc_request.params.insert(0, request)

t1 = time.time()
response = JSONRPCResponseManager.handle_request(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ def dummy(request):
data = json.loads(response.content.decode('utf8'))
self.assertEqual(data['result'], '')

def test_positional_args(self):
@api.dispatcher.add_method
def positional_args(request, name):
return name

json_data = {
"id": "0",
"jsonrpc": "2.0",
"method": "positional_args",
"params": ["echome!"],
}
response = self.client.post(
'',
json.dumps(json_data),
content_type='application/json',
)
self.assertEqual(response.status_code, 200)
data = json.loads(response.content.decode('utf8'))
self.assertEqual(data['result'], json_data['params'][0])

def test_method_not_allowed(self):
response = self.client.get(
'',
Expand Down