Skip to content

Commit

Permalink
"not found" enhancement for buld destory overrides with query param.
Browse files Browse the repository at this point in the history
Return 404 instead of 200 if not found any matched objects.
JIRA: PDC-940
  • Loading branch information
ycheng-aa committed Sep 9, 2015
1 parent 8a65888 commit ebdb2b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pdc/apps/compose/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,10 @@ def test_clear(self):
self.assertEqual(models.OverrideRPM.objects.count(), 0)
self.assertItemsEqual(response.data, [self.override_rpm])

def test_clear_with_no_matched_record(self):
response = self.client.delete(reverse('overridesrpm-list'), {'release': 'no_such_release'})
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

def test_clear_preserve_do_not_delete(self):
models.OverrideRPM.objects.create(release=self.release, variant="Server", arch="x86_64",
rpm_name="bash-doc", rpm_arch="src", include=True,
Expand Down
6 changes: 5 additions & 1 deletion pdc/apps/compose/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,11 @@ def bulk_destroy(self, *args, **kwargs):
return Response(status=status.HTTP_400_BAD_REQUEST,
data=["Allowed keys are release and force (optional, default false)."])
release_obj = get_object_or_404(Release, release_id=data["release"])
return Response(status=status.HTTP_200_OK, data=self._clear(release_obj, data))
data = self._clear(release_obj, data)
if data:
return Response(status=status.HTTP_200_OK, data=data)
else:
return Response(status=status.HTTP_404_NOT_FOUND, data={'detail': 'Not found.'})

if isinstance(data, list):
return bulk_operations.bulk_destroy_impl(self, *args, **kwargs)
Expand Down

0 comments on commit ebdb2b4

Please sign in to comment.