Skip to content

Commit

Permalink
Handle form filter when a single record via pk is requested
Browse files Browse the repository at this point in the history
  • Loading branch information
ukanga committed Apr 18, 2024
1 parent 13f99e6 commit 05785b0
Show file tree
Hide file tree
Showing 7 changed files with 428 additions and 382 deletions.
8 changes: 4 additions & 4 deletions onadata/apps/api/tests/viewsets/test_attachment_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def test_retrieve_and_list_views_with_anonymous_user(self):
def test_list_view(self):
self._submit_transport_instance_w_attachment()

request = self.factory.get("/", **self.extra)
request = self.factory.get("/", data={"xform": self.xform.pk}, **self.extra)
response = self.list_view(request)
self.assertNotEqual(response.get("Cache-Control"), None)
self.assertEqual(response.status_code, 200)
Expand All @@ -192,15 +192,15 @@ def test_list_view(self):
self.attachment.instance.deleted_at = timezone.now()
self.attachment.instance.save()

request = self.factory.get("/", **self.extra)
request = self.factory.get("/", data={"xform": self.xform.pk}, **self.extra)
response = self.list_view(request)
self.assertTrue(isinstance(response.data, list))
self.assertEqual(len(response.data), 0)

def test_data_list_with_xform_in_delete_async(self):
self._submit_transport_instance_w_attachment()

request = self.factory.get("/", **self.extra)
request = self.factory.get("/", data={"xform": self.xform.pk}, **self.extra)
response = self.list_view(request)
self.assertNotEqual(response.get("Cache-Control"), None)
self.assertEqual(response.status_code, 200)
Expand All @@ -209,7 +209,7 @@ def test_data_list_with_xform_in_delete_async(self):

self.xform.deleted_at = timezone.now()
self.xform.save()
request = self.factory.get("/", **self.extra)
request = self.factory.get("/", data={"xform": self.xform.pk}, **self.extra)
response = self.list_view(request)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), initial_count - 1)
Expand Down
366 changes: 186 additions & 180 deletions onadata/apps/api/tests/viewsets/test_export_viewset.py

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions onadata/apps/api/tests/viewsets/test_messaging_stats_viewset.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""
Module containing test for the MessagingStatsViewset (api/v1/stats/messaging)
"""

import json
from datetime import date
from datetime import datetime, timezone

from django.test import RequestFactory
from onadata.apps.api.viewsets.messaging_stats_viewset import MessagingStatsViewSet
Expand Down Expand Up @@ -34,7 +35,7 @@ def test_filters(self):
"target_type": "xform",
"target_id": self.xform.id,
"group_by": "day",
"timestamp__day": date.today().day,
"timestamp__day": datetime.now().day, # .astimezone(timezone.utc).day,
},
**self.extra,
)
Expand All @@ -49,7 +50,7 @@ def test_filters(self):
returned_data,
[
{
"group": str(date.today()),
"group": str(datetime.now().astimezone(timezone.utc).date()),
"submission_created": self.xform.instances.count(),
}
],
Expand All @@ -61,7 +62,7 @@ def test_filters(self):
"target_type": "xform",
"target_id": self.xform.id,
"group_by": "day",
"timestamp__day": date.today().day + 1,
"timestamp__day": datetime.now().astimezone(timezone.utc).day + 1,
},
**self.extra,
)
Expand Down Expand Up @@ -98,7 +99,7 @@ def test_filters(self):
returned_data,
[
{
"group": str(date.today()),
"group": str(datetime.now().astimezone(timezone.utc).date()),
"submission_created": self.xform.instances.count(),
}
],
Expand Down Expand Up @@ -153,7 +154,7 @@ def test_expected_responses(self):
returned_data,
[
{
"group": str(date.today()),
"group": str(datetime.now().astimezone(timezone.utc).date()),
"submission_created": self.xform.instances.count(),
}
],
Expand Down
14 changes: 9 additions & 5 deletions onadata/apps/api/tests/viewsets/test_widget_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,17 @@ def test_list_widgets(self):
}
)

# empty - no xform filter
request = self.factory.get("/", **self.extra)
response = view(request)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 0)

# not empty - xform filter
request = self.factory.get("/", data={"xform": self.xform.pk}, **self.extra)
response = view(request)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 2)
self.assertEqual(len(response.data), 1)

def test_widget_permission_create(self):

Expand Down Expand Up @@ -313,7 +319,7 @@ def test_widget_permission_list(self):
)

request = self.factory.get("/", **self.extra)
response = view(request)
response = view(request, formid=self.xform.pk)

self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 0)
Expand All @@ -322,8 +328,7 @@ def test_widget_permission_list(self):
ReadOnlyRole.add(self.user, self.xform)

request = self.factory.get("/", **self.extra)
response = view(request)

response = view(request, formid=self.xform.pk)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 1)

Expand Down Expand Up @@ -498,7 +503,6 @@ def test_widget_data_public_form(self):

request = self.factory.get("/", **self.extra)
response = view(request, formid=self.xform.pk)

self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 1)

Expand Down
Loading

0 comments on commit 05785b0

Please sign in to comment.