Skip to content

Commit

Permalink
Filter dataviews queryset with only 'deleted_at'
Browse files Browse the repository at this point in the history
Remove redundant test case
  • Loading branch information
FrankApiyo committed Oct 22, 2024
1 parent d2ef27e commit 8f1cea4
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 35 deletions.
4 changes: 1 addition & 3 deletions onadata/apps/api/viewsets/dataview_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ def filter_queryset(self, queryset):
"""
Remove deleted DataViews
"""
return super().filter_queryset(
queryset.filter(deleted_at=None, deleted_by=None)
)
return super().filter_queryset(queryset.filter(deleted_at=None))

def list(self, request, *args, **kwargs):
"""
Expand Down
32 changes: 0 additions & 32 deletions onadata/libs/tests/serializers/test_dataview_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,6 @@ def get_has_hxl_support_value(data_view_name):
self.assertTrue(get_has_hxl_support_value("age_only"))
self.assertTrue(get_has_hxl_support_value("age_and_name"))

def test_no_error_thrown_for_a_dataview_with_deleted_by_set(self):
"""
When `deleted_by` is set, don't throw error when serializing a DataView
"""
self._publish_form_with_hxl_support()
request = self.factory.get("/", **self.extra)
request.user = self.user

dataview_name = "My deleted DataView"
payload = {
"name": dataview_name,
"xform": "http://testserver/api/v1/forms/%s" % self.xform.pk,
"project": "http://testserver/api/v1/projects/%s" % self.project.pk,
"columns": '["name", "age"]',
"query": "[]",
}
serializer = DataViewSerializer(data=payload, context={"request": request})
is_valid = serializer.is_valid()
self.assertTrue(is_valid)

serializer.save()
self.assertEqual(DataView.objects.count(), 1)

# delete dataview and check dataviews endpoint
dataview = DataView.objects.get(name=dataview_name)
dataview.soft_delete(self.user)
serialized_dataview = DataViewSerializer(
dataview, context={"request": request}
).data
self.assertFalse("deleted_by" in serialized_dataview)
self.assertFalse("deleted_at" in serialized_dataview)

def test_name_and_xform_are_unique(self):
"""
Test that we are preventing the creation of exactly the same dataview
Expand Down

0 comments on commit 8f1cea4

Please sign in to comment.