Skip to content

Commit

Permalink
Add a test case for making a GET request for a deleted dataview
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankApiyo committed Oct 22, 2024
1 parent 02962ec commit a3b56ee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions onadata/apps/api/tests/viewsets/test_dataview_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,36 @@ def test_get_dataview_no_perms(self):

self.assertEqual(response.status_code, 200)

def test_can_not_get_deleted_dataview(self):
data = {
"name": "Agriculture Dataview",
"xform": f"http://testserver/api/v1/forms/{self.xform.pk}",
"project": f"http://testserver/api/v1/projects/{self.project.pk}",
"columns": '["name", "age", "gender"]',
"query": '[{"column":"age","filter":">","value":"20"},'
'{"column":"age","filter":"<","value":"50"}]',
}

self._create_dataview(data=data)

view = DataViewViewSet.as_view(
{
"get": "retrieve",
}
)

request = self.factory.get("/", **self.extra)
response = view(request, pk=self.data_view.pk)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["dataviewid"], self.data_view.pk)

dataview = DataView.objects.get(id=response.data["dataviewid"])
dataview.soft_delete(user=self.user)

request = self.factory.get("/", **self.extra)
response = view(request, pk=self.data_view.pk)
self.assertEqual(response.status_code, 404)

# pylint: disable=invalid-name
def test_dataview_data_filter_integer(self):
data = {
Expand Down
2 changes: 1 addition & 1 deletion onadata/libs/tests/serializers/test_dataview_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_no_error_thrown_for_a_dataview_with_deleted_by_set(self):
serialized_dataview = DataViewSerializer(
dataview, context={"request": request}
).data
self.assertEqual(serialized_dataview["deleted_by"], None)
self.assertFalse("deleted_by" in serialized_dataview)
self.assertFalse("deleted_at" in serialized_dataview)

def test_name_and_xform_are_unique(self):
Expand Down

0 comments on commit a3b56ee

Please sign in to comment.