@@ -29,7 +29,7 @@ def test_client_post_malformed_json(settings, client):
2929 {'message' : 'Malformed json body in the post data' }]}
3030
3131
32- def test_client_post_empty_query (settings , client ):
32+ def test_client_post_empty_query_json (settings , client ):
3333 settings .ROOT_URLCONF = 'tests.contrib_django.test_urls'
3434 response = client .post (
3535 '/graphql' , json .dumps ({'query' : '' }), 'application/json' )
@@ -38,7 +38,16 @@ def test_client_post_empty_query(settings, client):
3838 {'message' : 'Must provide query string.' }]}
3939
4040
41- def test_client_post_bad_query (settings , client ):
41+ def test_client_post_empty_query_graphql (settings , client ):
42+ settings .ROOT_URLCONF = 'tests.contrib_django.test_urls'
43+ response = client .post (
44+ '/graphql' , '' , 'application/graphql' )
45+ json_response = format_response (response )
46+ assert json_response == {'errors' : [
47+ {'message' : 'Must provide query string.' }]}
48+
49+
50+ def test_client_post_bad_query_json (settings , client ):
4251 settings .ROOT_URLCONF = 'tests.contrib_django.test_urls'
4352 response = client .post (
4453 '/graphql' , json .dumps ({'query' : '{ MALFORMED' }), 'application/json' )
@@ -48,6 +57,16 @@ def test_client_post_bad_query(settings, client):
4857 assert 'Syntax Error GraphQL' in json_response ['errors' ][0 ]['message' ]
4958
5059
60+ def test_client_post_bad_query_graphql (settings , client ):
61+ settings .ROOT_URLCONF = 'tests.contrib_django.test_urls'
62+ response = client .post (
63+ '/graphql' , '{ MALFORMED' , 'application/graphql' )
64+ json_response = format_response (response )
65+ assert 'errors' in json_response
66+ assert len (json_response ['errors' ]) == 1
67+ assert 'Syntax Error GraphQL' in json_response ['errors' ][0 ]['message' ]
68+
69+
5170def test_client_get_good_query (settings , client ):
5271 settings .ROOT_URLCONF = 'tests.contrib_django.test_urls'
5372 response = client .get ('/graphql' , {'query' : '{ headline }' })
@@ -69,7 +88,7 @@ def test_client_get_good_query_with_raise(settings, client):
6988 assert json_response ['data' ]['raises' ] is None
7089
7190
72- def test_client_post_good_query (settings , client ):
91+ def test_client_post_good_query_json (settings , client ):
7392 settings .ROOT_URLCONF = 'tests.contrib_django.test_urls'
7493 response = client .post (
7594 '/graphql' , json .dumps ({'query' : '{ headline }' }), 'application/json' )
@@ -82,6 +101,19 @@ def test_client_post_good_query(settings, client):
82101 assert json_response == expected_json
83102
84103
104+ def test_client_post_good_query_graphql (settings , client ):
105+ settings .ROOT_URLCONF = 'tests.contrib_django.test_urls'
106+ response = client .post (
107+ '/graphql' , '{ headline }' , 'application/graphql' )
108+ json_response = format_response (response )
109+ expected_json = {
110+ 'data' : {
111+ 'headline' : None
112+ }
113+ }
114+ assert json_response == expected_json
115+
116+
85117# def test_client_get_bad_query(settings, client):
86118# settings.ROOT_URLCONF = 'tests.contrib_django.test_urls'
87119# response = client.get('/graphql')
0 commit comments