diff --git a/onadata/apps/api/tests/viewsets/test_data_viewset.py b/onadata/apps/api/tests/viewsets/test_data_viewset.py index d84df44f41..b45e11e5b4 100644 --- a/onadata/apps/api/tests/viewsets/test_data_viewset.py +++ b/onadata/apps/api/tests/viewsets/test_data_viewset.py @@ -1109,21 +1109,12 @@ 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='mango', - ) + 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 @@ -1131,16 +1122,17 @@ def test_filter_by_date_modified(self): 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()