diff --git a/contentcuration/contentcuration/frontend/shared/client.js b/contentcuration/contentcuration/frontend/shared/client.js index 05885bb813..ee70893723 100644 --- a/contentcuration/contentcuration/frontend/shared/client.js +++ b/contentcuration/contentcuration/frontend/shared/client.js @@ -43,12 +43,12 @@ client.interceptors.response.use( // we should silence those on the front end and try // to catch legitimate request issues in the backend. // - // Allow 418 too as that's specific to out of storage checks + // Allow 412 too as that's specific to out of storage checks if ( error.response.status === 403 || error.response.status === 404 || error.response.status === 405 || - error.response.status === 418 + error.response.status === 412 ) { return Promise.reject(error); } diff --git a/contentcuration/contentcuration/frontend/shared/vuex/file/actions.js b/contentcuration/contentcuration/frontend/shared/vuex/file/actions.js index 5d2a3a18e8..821a25d181 100644 --- a/contentcuration/contentcuration/frontend/shared/vuex/file/actions.js +++ b/contentcuration/contentcuration/frontend/shared/vuex/file/actions.js @@ -225,7 +225,7 @@ export function uploadFile(context, { file, preset = null } = {}) { }) .catch(error => { let errorType = fileErrors.UPLOAD_FAILED; - if (error.response && error.response.status === 418) { + if (error.response && error.response.status === 412) { errorType = fileErrors.NO_STORAGE; } const fileObject = { diff --git a/contentcuration/contentcuration/tests/viewsets/test_file.py b/contentcuration/contentcuration/tests/viewsets/test_file.py index 32f475aac3..51f0968e37 100644 --- a/contentcuration/contentcuration/tests/viewsets/test_file.py +++ b/contentcuration/contentcuration/tests/viewsets/test_file.py @@ -414,3 +414,39 @@ def test_delete_file(self): self.fail("File was not deleted") except models.File.DoesNotExist: pass + + +class UploadFileURLTestCase(StudioAPITestCase): + def setUp(self): + super(UploadFileURLTestCase, self).setUp() + self.user = testdata.user() + self.file = { + "size": 1000, + "checksum": uuid.uuid4().hex, + "name": "le_studio", + "file_format": file_formats.MP3, + "preset": format_presets.AUDIO, + } + + def test_required_keys(self): + del self.file["name"] + + self.client.force_authenticate(user=self.user) + response = self.client.post( + reverse("file-upload-url"), self.file, format="json", + ) + + self.assertEqual(response.status_code, 400) + + def test_insufficient_storage(self): + self.file["size"] = 100000000000000 + + self.client.force_authenticate(user=self.user) + response = self.client.post(reverse("file-upload-url"), self.file, format="json",) + + self.assertEqual(response.status_code, 412) + + def test_upload_url(self): + self.client.force_authenticate(user=self.user) + response = self.client.post(reverse("file-upload-url"), self.file, format="json",) + self.assertEqual(response.status_code, 200) diff --git a/contentcuration/contentcuration/viewsets/file.py b/contentcuration/contentcuration/viewsets/file.py index 6c65582a56..dd49c3d304 100644 --- a/contentcuration/contentcuration/viewsets/file.py +++ b/contentcuration/contentcuration/viewsets/file.py @@ -136,15 +136,14 @@ def upload_url(self, request): file_format = request.data["file_format"] preset = request.data["preset"] except KeyError: - raise HttpResponseBadRequest( + return HttpResponseBadRequest( reason="Must specify: size, checksum, name, file_format, and preset" ) try: request.user.check_space(float(size), checksum) - - except PermissionDenied as e: - return HttpResponseBadRequest(reason=str(e), status=418) + except PermissionDenied: + return HttpResponseBadRequest(reason="Not enough space. Check your storage under Settings page.", status=412) might_skip = File.objects.filter(checksum=checksum).exists()