summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Friedli2020-07-14 22:49:24 +0200
committerJan Friedli2020-07-14 22:49:24 +0200
commit2ba8d74fa7e104ddfaac365c1efe1bb99c632ed3 (patch)
tree729829e623860ade3895f62ba5b938e880461a18
parent5d1e6b3235f9cddf66611e7cf4f4d0b41ffd7368 (diff)
catch no bulk post body
-rw-r--r--matweb/rest_api.py2
-rw-r--r--test/test_api.py8
2 files changed, 10 insertions, 0 deletions
diff --git a/matweb/rest_api.py b/matweb/rest_api.py
index 429b82e..2909cf6 100644
--- a/matweb/rest_api.py
+++ b/matweb/rest_api.py
@@ -106,6 +106,8 @@ class APIBulkDownloadCreator(Resource):
106 def post(self): 106 def post(self):
107 utils.check_upload_folder(current_app.config['UPLOAD_FOLDER']) 107 utils.check_upload_folder(current_app.config['UPLOAD_FOLDER'])
108 data = request.json 108 data = request.json
109 if not data:
110 abort(400, message="Post Body Required")
109 if not self.v.validate(data): 111 if not self.v.validate(data):
110 abort(400, message=self.v.errors) 112 abort(400, message=self.v.errors)
111 # prevent the zip file from being overwritten 113 # prevent the zip file from being overwritten
diff --git a/test/test_api.py b/test/test_api.py
index be9cb29..6961197 100644
--- a/test/test_api.py
+++ b/test/test_api.py
@@ -263,6 +263,14 @@ class Mat2APITestCase(unittest.TestCase):
263 request = self.app.get(upload_two['download_link']) 263 request = self.app.get(upload_two['download_link'])
264 self.assertEqual(request.status_code, 404) 264 self.assertEqual(request.status_code, 404)
265 265
266 def test_api_bulk_empty_body(self):
267 request = self.app.post(
268 '/api/download/bulk',
269 )
270 self.assertEqual(400, request.status_code)
271 error_message = request.get_json()['message']
272 self.assertEqual("Post Body Required", error_message)
273
266 def test_api_bulk_download_validation(self): 274 def test_api_bulk_download_validation(self):
267 post_body = { 275 post_body = {
268 u'download_list': [ 276 u'download_list': [