Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrong status code on insufficient storage #3312

Merged
merged 3 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contentcuration/contentcuration/frontend/shared/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
36 changes: 36 additions & 0 deletions contentcuration/contentcuration/tests/viewsets/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 3 additions & 4 deletions contentcuration/contentcuration/viewsets/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down