@@ -29,7 +29,7 @@ def test_client_post_malformed_json(settings, client):
29
29
{'message' : 'Malformed json body in the post data' }]}
30
30
31
31
32
- def test_client_post_empty_query (settings , client ):
32
+ def test_client_post_empty_query_json (settings , client ):
33
33
settings .ROOT_URLCONF = 'tests.contrib_django.test_urls'
34
34
response = client .post (
35
35
'/graphql' , json .dumps ({'query' : '' }), 'application/json' )
@@ -38,7 +38,16 @@ def test_client_post_empty_query(settings, client):
38
38
{'message' : 'Must provide query string.' }]}
39
39
40
40
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 ):
42
51
settings .ROOT_URLCONF = 'tests.contrib_django.test_urls'
43
52
response = client .post (
44
53
'/graphql' , json .dumps ({'query' : '{ MALFORMED' }), 'application/json' )
@@ -48,6 +57,16 @@ def test_client_post_bad_query(settings, client):
48
57
assert 'Syntax Error GraphQL' in json_response ['errors' ][0 ]['message' ]
49
58
50
59
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
+
51
70
def test_client_get_good_query (settings , client ):
52
71
settings .ROOT_URLCONF = 'tests.contrib_django.test_urls'
53
72
response = client .get ('/graphql' , {'query' : '{ headline }' })
@@ -69,7 +88,7 @@ def test_client_get_good_query_with_raise(settings, client):
69
88
assert json_response ['data' ]['raises' ] is None
70
89
71
90
72
- def test_client_post_good_query (settings , client ):
91
+ def test_client_post_good_query_json (settings , client ):
73
92
settings .ROOT_URLCONF = 'tests.contrib_django.test_urls'
74
93
response = client .post (
75
94
'/graphql' , json .dumps ({'query' : '{ headline }' }), 'application/json' )
@@ -82,6 +101,19 @@ def test_client_post_good_query(settings, client):
82
101
assert json_response == expected_json
83
102
84
103
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
+
85
117
# def test_client_get_bad_query(settings, client):
86
118
# settings.ROOT_URLCONF = 'tests.contrib_django.test_urls'
87
119
# response = client.get('/graphql')
0 commit comments