From ae886c0a592b0d3d52434821f171b74cdc123129 Mon Sep 17 00:00:00 2001 From: Kipchirchir Sigei Date: Thu, 23 Nov 2023 09:36:44 +0300 Subject: [PATCH 1/2] Filter out deleted forms from project forms endpoint Signed-off-by: Kipchirchir Sigei --- onadata/apps/api/viewsets/project_viewset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 702791b7c535b335858b8949696fc3d74389b7ff Mon Sep 17 00:00:00 2001 From: Kipchirchir Sigei Date: Thu, 23 Nov 2023 09:37:01 +0300 Subject: [PATCH 2/2] Add tests Signed-off-by: Kipchirchir Sigei --- .../tests/viewsets/test_project_viewset.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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()