File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -183,6 +183,15 @@ def test_batch_allows_post_with_json_encoding(client):
183
183
}]
184
184
185
185
186
+ def test_batch_fails_if_is_empty (client ):
187
+ response = client .post (batch_url_string (), j ([]), 'application/json' )
188
+
189
+ assert response .status_code == 200
190
+ assert response_json (response ) == {
191
+ 'errors' : [{'message' : 'Received an empty list in the batch request.' }]
192
+ }
193
+
194
+
186
195
def test_allows_sending_a_mutation_via_post (client ):
187
196
response = client .post (url_string (), j (query = 'mutation TestMutation { writeTest { test } }' ), 'application/json' )
188
197
Original file line number Diff line number Diff line change @@ -193,10 +193,19 @@ def parse_body(self, request):
193
193
try :
194
194
request_json = json .loads (request .body .decode ('utf-8' ))
195
195
if self .batch :
196
- assert isinstance (request_json , list )
196
+ assert isinstance (request_json , list ), (
197
+ 'Batch requests should receive a list, but received {}.'
198
+ ).format (repr (request_json ))
199
+ assert len (request_json ) > 0 , (
200
+ 'Received an empty list in the batch request.'
201
+ )
197
202
else :
198
- assert isinstance (request_json , dict )
203
+ assert isinstance (request_json , dict ), (
204
+ 'The received data is not a valid JSON query.'
205
+ )
199
206
return request_json
207
+ except AssertionError as e :
208
+ raise HttpError (HttpResponseBadRequest (str (e )))
200
209
except :
201
210
raise HttpError (HttpResponseBadRequest ('POST body sent invalid JSON.' ))
202
211
You can’t perform that action at this time.
0 commit comments