diff --git a/onadata/apps/api/tests/viewsets/test_project_viewset.py b/onadata/apps/api/tests/viewsets/test_project_viewset.py index b90c0fbd69..1b96ca546c 100644 --- a/onadata/apps/api/tests/viewsets/test_project_viewset.py +++ b/onadata/apps/api/tests/viewsets/test_project_viewset.py @@ -309,6 +309,25 @@ def test_project_get_deleted_form(self): self.assertEqual(len(response.data.get("forms")), 0) self.assertEqual(response.status_code, 200) + def test_xform_delete_project_forms_endpoint(self): + self._publish_xls_form_to_project() + + view = ProjectViewSet.as_view({"get": "forms"}) + request = self.factory.get("/", **self.extra) + response = view(request, pk=self.project.pk) + + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.data), 1) + + # soft delete form + self.xform.soft_delete(user=self.user) + + request = self.factory.get("/", **self.extra) + response = view(request, pk=self.project.pk) + + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.data), 0) + # pylint: disable=invalid-name def test_none_empty_forms_and_dataview_properties_in_returned_json(self): self._publish_xls_form_to_project() diff --git a/onadata/apps/api/viewsets/project_viewset.py b/onadata/apps/api/viewsets/project_viewset.py index b5d168708a..3f72099143 100644 --- a/onadata/apps/api/viewsets/project_viewset.py +++ b/onadata/apps/api/viewsets/project_viewset.py @@ -163,7 +163,7 @@ def forms(self, request, **kwargs): return Response(survey, status=status.HTTP_400_BAD_REQUEST) - xforms = XForm.objects.filter(project=project) + xforms = XForm.objects.filter(project=project, deleted_at__isnull=True) serializer = XFormSerializer(xforms, context={"request": request}, many=True) return Response(serializer.data)