Skip to content

Commit

Permalink
changed the try expect block to ContentNodeTreeViewset
Browse files Browse the repository at this point in the history
  • Loading branch information
manzil-infinity180 committed Nov 19, 2024
1 parent e1902fe commit a6cbeeb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
15 changes: 8 additions & 7 deletions kolibri/core/content/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,13 +864,6 @@ def retrieve(self, request, pk=None):
if pk is None:
raise Http404

try:
UUID(pk)
except ValueError:
return Response(
{"error": "Invalid UUID format."}, status=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 Expand Up @@ -1175,6 +1168,14 @@ class ContentNodeTreeViewset(BaseContentNodeTreeViewset, RemoteMixin):
def retrieve(self, request, pk=None):
if pk is None:
raise Http404

try:
UUID(pk)
except ValueError:
return Response(
{"error": "Invalid UUID format."}, status=status.HTTP_400_BAD_REQUEST
)

if self._should_proxy_request(request):
try:
queryset = self.get_tree_queryset(request, pk)
Expand Down
3 changes: 2 additions & 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_none_pk(self):
kwargs={"pk": None},
)
)
self.assertEqual(response.status_code, 404)
self.assertEqual(response.status_code, 400)

def test_contentnode_tree_bad_pk(self):
response = self.client.get(
Expand All @@ -523,6 +523,7 @@ def test_contentnode_tree_bad_pk(self):
)
)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.data["error"], "Invalid UUID format.")

@unittest.skipIf(
getattr(settings, "DATABASES")["default"]["ENGINE"]
Expand Down
2 changes: 1 addition & 1 deletion kolibri/core/content/test/test_public_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_import_metadata_none_pk(self):
kwargs={"pk": None},
)
)
self.assertEqual(response.status_code, 404)
self.assertEqual(response.status_code, 400)

def test_import_metadata_bad_pk(self):
response = self.client.get(
Expand Down

0 comments on commit a6cbeeb

Please sign in to comment.