Reputation: 1991
Inside integration tests, I try to make a POST request with a nested JSON parameter (this is just one of the approaches I tried):
test_function(admin_client):
admin_client.post(some_url,
json.dumps(some_nested_json),
content_type='application/json',
headers={'Content-type': 'application/json; charset=utf-8'})
I've also tried all sorts of different combinations for the parameters etc., everything I could find on the web, but I can't get the proper JSON output in the received request.JSON
.
I get one of these three cases:
request.POST
contains the first level of JSON plus the arrays of second level JSON keysrequest.POST
contains the first level of JSON plus an empty second level JSONrequest.POST
is empty, but request.body
contains the whole nested JSON, in expected formatWhat am I missing here? I'm using Python 2.7.
Upvotes: 0
Views: 503
Reputation: 364
This is expected behavior in django. Json requests are not in in request.POST
but in request.body
. You need to manually do json.loads(request.body)
in your view.
Upvotes: 1