Skip to content

Commit

Permalink
revert modified test
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvin-muchiri committed Sep 18, 2024
1 parent 0d818c4 commit 5e39685
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions onadata/apps/api/tests/viewsets/test_data_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,38 +1109,30 @@ def test_filter_by_submission_time_and_submitted_by(self):
self.assertEqual(len(response.data), 2)

def test_filter_by_date_modified(self):
# Mock date_created
with patch(
"django.utils.timezone.now",
Mock(return_value=datetime.datetime(2024, 1, 1, tzinfo=timezone.utc)),
):
self._make_submissions()

instance = Instance.objects.create(
xform=self.xform,
xml='<data id="b"><fruit>mango</fruit></data>',
)
self._make_submissions()
view = DataViewSet.as_view({"get": "list"})
request = self.factory.get("/", **self.extra)
instances = self.xform.instances.all().order_by("pk")
self.assertEqual(len(instances), 5)
self.assertEqual(len(instances), 4)
instance = instances[2]
date_modified = instance.date_modified.isoformat()
# greater than or equal to
query_str = '{"_date_modified": {"$gte": "%s"}}' % date_modified
data = {"query": query_str}
request = self.factory.get("/", data=data, **self.extra)
response = view(request, pk=self.xform.pk)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 1)
self.assertEqual(response.data[0]["_id"], instance.pk)
self.assertEqual(len(response.data), 2)
self.assertEqual(response.data[0]["_id"], instances[2].pk)
self.assertEqual(response.data[1]["_id"], instances[3].pk)
# greater than
date_modified = instance.date_modified.isoformat()
query_str = '{"_date_modified": {"$gt": "%s"}}' % date_modified
data = {"query": query_str}
request = self.factory.get("/", data=data, **self.extra)
response = view(request, pk=self.xform.pk)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 0)
self.assertEqual(len(response.data), 1)
self.assertEqual(response.data[0]["_id"], instances[3].pk)

def test_filter_by_submission_time_and_submitted_by_with_data_arg(self):
self._make_submissions()
Expand Down

0 comments on commit 5e39685

Please sign in to comment.