mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-02-06 06:30:36 +03:00
Merge branch 'master' of github.com:graphql-python/graphene-django
This commit is contained in:
commit
328cd50821
|
@ -183,6 +183,15 @@ def test_batch_allows_post_with_json_encoding(client):
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
|
||||||
|
def test_batch_fails_if_is_empty(client):
|
||||||
|
response = client.post(batch_url_string(), '[]', 'application/json')
|
||||||
|
|
||||||
|
assert response.status_code == 400
|
||||||
|
assert response_json(response) == {
|
||||||
|
'errors': [{'message': 'Received an empty list in the batch request.'}]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_allows_sending_a_mutation_via_post(client):
|
def test_allows_sending_a_mutation_via_post(client):
|
||||||
response = client.post(url_string(), j(query='mutation TestMutation { writeTest { test } }'), 'application/json')
|
response = client.post(url_string(), j(query='mutation TestMutation { writeTest { test } }'), 'application/json')
|
||||||
|
|
||||||
|
@ -432,9 +441,18 @@ def test_handles_errors_caused_by_a_lack_of_query(client):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_handles_invalid_json_bodies(client):
|
def test_handles_not_expected_json_bodies(client):
|
||||||
response = client.post(url_string(), '[]', 'application/json')
|
response = client.post(url_string(), '[]', 'application/json')
|
||||||
|
|
||||||
|
assert response.status_code == 400
|
||||||
|
assert response_json(response) == {
|
||||||
|
'errors': [{'message': 'The received data is not a valid JSON query.'}]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_handles_invalid_json_bodies(client):
|
||||||
|
response = client.post(url_string(), '[oh}', 'application/json')
|
||||||
|
|
||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
assert response_json(response) == {
|
assert response_json(response) == {
|
||||||
'errors': [{'message': 'POST body sent invalid JSON.'}]
|
'errors': [{'message': 'POST body sent invalid JSON.'}]
|
||||||
|
|
|
@ -193,10 +193,19 @@ class GraphQLView(View):
|
||||||
try:
|
try:
|
||||||
request_json = json.loads(request.body.decode('utf-8'))
|
request_json = json.loads(request.body.decode('utf-8'))
|
||||||
if self.batch:
|
if self.batch:
|
||||||
assert isinstance(request_json, list)
|
assert isinstance(request_json, list), (
|
||||||
|
'Batch requests should receive a list, but received {}.'
|
||||||
|
).format(repr(request_json))
|
||||||
|
assert len(request_json) > 0, (
|
||||||
|
'Received an empty list in the batch request.'
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
assert isinstance(request_json, dict)
|
assert isinstance(request_json, dict), (
|
||||||
|
'The received data is not a valid JSON query.'
|
||||||
|
)
|
||||||
return request_json
|
return request_json
|
||||||
|
except AssertionError as e:
|
||||||
|
raise HttpError(HttpResponseBadRequest(str(e)))
|
||||||
except:
|
except:
|
||||||
raise HttpError(HttpResponseBadRequest('POST body sent invalid JSON.'))
|
raise HttpError(HttpResponseBadRequest('POST body sent invalid JSON.'))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user