From ac58ee15a4d80b4f117e9ab78ad59f7be050ed04 Mon Sep 17 00:00:00 2001 From: Monte Mishkin Date: Fri, 13 Nov 2015 00:23:56 -0800 Subject: [PATCH] added tests for allowing content-type "application/graphql" in django view --- tests/contrib_django/test_views.py | 38 +++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/tests/contrib_django/test_views.py b/tests/contrib_django/test_views.py index c04e8b6a..27033281 100644 --- a/tests/contrib_django/test_views.py +++ b/tests/contrib_django/test_views.py @@ -29,7 +29,7 @@ def test_client_post_malformed_json(settings, client): {'message': 'Malformed json body in the post data'}]} -def test_client_post_empty_query(settings, client): +def test_client_post_empty_query_json(settings, client): settings.ROOT_URLCONF = 'tests.contrib_django.test_urls' response = client.post( '/graphql', json.dumps({'query': ''}), 'application/json') @@ -38,7 +38,16 @@ def test_client_post_empty_query(settings, client): {'message': 'Must provide query string.'}]} -def test_client_post_bad_query(settings, client): +def test_client_post_empty_query_graphql(settings, client): + settings.ROOT_URLCONF = 'tests.contrib_django.test_urls' + response = client.post( + '/graphql', '', 'application/graphql') + json_response = format_response(response) + assert json_response == {'errors': [ + {'message': 'Must provide query string.'}]} + + +def test_client_post_bad_query_json(settings, client): settings.ROOT_URLCONF = 'tests.contrib_django.test_urls' response = client.post( '/graphql', json.dumps({'query': '{ MALFORMED'}), 'application/json') @@ -48,6 +57,16 @@ def test_client_post_bad_query(settings, client): assert 'Syntax Error GraphQL' in json_response['errors'][0]['message'] +def test_client_post_bad_query_graphql(settings, client): + settings.ROOT_URLCONF = 'tests.contrib_django.test_urls' + response = client.post( + '/graphql', '{ MALFORMED', 'application/graphql') + json_response = format_response(response) + assert 'errors' in json_response + assert len(json_response['errors']) == 1 + assert 'Syntax Error GraphQL' in json_response['errors'][0]['message'] + + def test_client_get_good_query(settings, client): settings.ROOT_URLCONF = 'tests.contrib_django.test_urls' response = client.get('/graphql', {'query': '{ headline }'}) @@ -69,7 +88,7 @@ def test_client_get_good_query_with_raise(settings, client): assert json_response['data']['raises'] is None -def test_client_post_good_query(settings, client): +def test_client_post_good_query_json(settings, client): settings.ROOT_URLCONF = 'tests.contrib_django.test_urls' response = client.post( '/graphql', json.dumps({'query': '{ headline }'}), 'application/json') @@ -82,6 +101,19 @@ def test_client_post_good_query(settings, client): assert json_response == expected_json +def test_client_post_good_query_graphql(settings, client): + settings.ROOT_URLCONF = 'tests.contrib_django.test_urls' + response = client.post( + '/graphql', '{ headline }'), 'application/graphql') + json_response = format_response(response) + expected_json = { + 'data': { + 'headline': None + } + } + assert json_response == expected_json + + # def test_client_get_bad_query(settings, client): # settings.ROOT_URLCONF = 'tests.contrib_django.test_urls' # response = client.get('/graphql')