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):
183183 }]
184184
185185
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+
186195def test_allows_sending_a_mutation_via_post (client ):
187196 response = client .post (url_string (), j (query = 'mutation TestMutation { writeTest { test } }' ), 'application/json' )
188197
Original file line number Diff line number Diff line change @@ -193,10 +193,19 @@ def parse_body(self, request):
193193 try :
194194 request_json = json .loads (request .body .decode ('utf-8' ))
195195 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+ )
197202 else :
198- assert isinstance (request_json , dict )
203+ assert isinstance (request_json , dict ), (
204+ 'The received data is not a valid JSON query.'
205+ )
199206 return request_json
207+ except AssertionError as e :
208+ raise HttpError (HttpResponseBadRequest (str (e )))
200209 except :
201210 raise HttpError (HttpResponseBadRequest ('POST body sent invalid JSON.' ))
202211
You can’t perform that action at this time.
0 commit comments