Skip to content

Commit

Permalink
changed response 404 to 400
Browse files Browse the repository at this point in the history
  • Loading branch information
manzil-infinity180 committed Nov 11, 2024
1 parent 87418dd commit 37efcdb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion kolibri/core/content/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ class ContentNodeViewset(InternalContentNodeMixin, RemoteMixin, ReadOnlyValuesVi

def retrieve(self, request, pk=None):
if pk is None:
raise Http404
raise status.HTTP_400_BAD_REQUEST
if self._should_proxy_request(request):
if self.get_queryset().filter(admin_imported=True, pk=pk).exists():
# Used in the update method for remote request retrieval
Expand Down
3 changes: 3 additions & 0 deletions kolibri/core/content/public_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.db import connection
from django.db.models import Q
from django.http import HttpResponseBadRequest
from rest_framework import status
from rest_framework.response import Response
from rest_framework.serializers import Serializer
from rest_framework.viewsets import GenericViewSet
Expand Down Expand Up @@ -50,6 +51,8 @@ def retrieve(self, request, pk=None):
:param pk: id parent node
:return: an object with keys for each content metadata table and a schema_version key
"""
if pk is None:
raise status.HTTP_400_BAD_REQUEST

content_schema = request.query_params.get(
"schema_version", self.default_content_schema
Expand Down
2 changes: 1 addition & 1 deletion kolibri/core/content/test/test_content_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def test_contentnode_tree_bad_pk(self):
kwargs={"pk": "this is not a UUID"},
)
)
self.assertEqual(response.status_code, 404)
self.assertEqual(response.status_code, 400)

@unittest.skipIf(
getattr(settings, "DATABASES")["default"]["ENGINE"]
Expand Down
9 changes: 9 additions & 0 deletions kolibri/core/content/test/test_public_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ def test_schema_version_too_high(self):
)
self.assertEqual(response.status_code, 400)

def test_import_metadata_bad_pk(self):
response = self.client.get(
reverse(
"kolibri:core:importmetadata-detail",
kwargs={"pk": "this is not a UUID"},
)
)
self.assertEqual(response.status_code, 400)

def test_schema_version_just_right(self):
response = self.client.get(
reverse("kolibri:core:importmetadata-detail", kwargs={"pk": self.node.id})
Expand Down

0 comments on commit 37efcdb

Please sign in to comment.