Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvin-muchiri committed Sep 17, 2024
1 parent 0e92adf commit 352a3b4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion docs/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions onadata/apps/api/tests/viewsets/test_data_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3528,6 +3528,16 @@ def test_data_query_or_metadata(self):
last_edited=datetime.datetime(2024, 4, 1, tzinfo=timezone.utc),
xml='<data id="b"><fruit>mango</fruit></data>',
)
# 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='<data id="b"><fruit>mango</fruit></data>',
)
query_str = (
'{"$or": [{"_submission_time":{"$gte": "2024-09-17", "$lte": "2024-09-17"}}, '
'{"_last_edited":{"$gte": "2024-04-01", "$lte": "2024-04-01"}}]}'
Expand All @@ -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"""
Expand Down

0 comments on commit 352a3b4

Please sign in to comment.