From 352a3b4f8bbc2a8e2f45e5868a442e913f63af58 Mon Sep 17 00:00:00 2001 From: Kelvin Muchiri Date: Tue, 17 Sep 2024 12:07:47 +0300 Subject: [PATCH] add test --- docs/data.rst | 10 +++++++++- .../apps/api/tests/viewsets/test_data_viewset.py | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/data.rst b/docs/data.rst index 213191021a..34226a6e9d 100644 --- a/docs/data.rst +++ b/docs/data.rst @@ -674,12 +674,20 @@ Query submissions with `NULL` submission review status Example XIII -Query submissions collected within specific dates and submissions edited within specific dates +Query submissions collected within specific dates and edited within specific dates :: curl -X GET https://api.ona.io/api/v1/data/22845?query={"$or": [{"_submission_time":{"$gte": "2020-01-01", "$lte": "2020-08-31"}}, {"_last_edited":{"$gte": "2020-01-01", "$lte": "2020-08-31"}}]} +Example XIV + +Query submissions collected on specific dates and edited on specifc date + +:: + + curl -X GET https://api.ona.io/api/v1/data/22845?query={"$or": [{"_submission_time": "2020-01-01"}, {"_last_edited": "2020-01-01"}]} + All Filters Options diff --git a/onadata/apps/api/tests/viewsets/test_data_viewset.py b/onadata/apps/api/tests/viewsets/test_data_viewset.py index e3dee63b8c..7acd1c5ef5 100644 --- a/onadata/apps/api/tests/viewsets/test_data_viewset.py +++ b/onadata/apps/api/tests/viewsets/test_data_viewset.py @@ -3528,6 +3528,16 @@ def test_data_query_or_metadata(self): last_edited=datetime.datetime(2024, 4, 1, tzinfo=timezone.utc), xml='mango', ) + # Mock date_created + with patch( + "django.utils.timezone.now", + Mock(return_value=datetime.datetime(2023, 4, 1, tzinfo=timezone.utc)), + ): + Instance.objects.create( + xform=self.xform, + last_edited=datetime.datetime(2023, 4, 1, tzinfo=timezone.utc), + xml='mango', + ) query_str = ( '{"$or": [{"_submission_time":{"$gte": "2024-09-17", "$lte": "2024-09-17"}}, ' '{"_last_edited":{"$gte": "2024-04-01", "$lte": "2024-04-01"}}]}' @@ -3544,6 +3554,11 @@ def test_data_query_or_metadata(self): response = view(request, pk=self.xform.pk) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data), 5) + query_str = '{"$or": [{"_submission_time": "2024-09-17"}, {"_last_edited": "2024-04-01"}]}' + request = self.factory.get("/?query=%s" % query_str, **self.extra) + response = view(request, pk=self.xform.pk) + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.data), 5) def test_data_list_xml_format(self): """Test DataViewSet list XML"""