Skip to content

Commit

Permalink
fix exception thrown when deleting export
Browse files Browse the repository at this point in the history
fix argument of type 'NoneType' is not iterable
  • Loading branch information
kelvin-muchiri committed May 23, 2024
1 parent be4f34f commit 30650f9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 25 additions & 1 deletion onadata/apps/api/tests/viewsets/test_export_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""
test_export_viewset module
"""

import os
from tempfile import NamedTemporaryFile

Expand Down Expand Up @@ -293,6 +292,31 @@ def test_export_delete(self):
response = view(request, pk=export.pk)
self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code)

def test_export_delete_null_body(self):
"""Null request body is handled"""
markdown_xlsform = """
| survey |
| | type | name | label |
| | select one fruits | fruit | Fruit |
| choices |
| | list name | name | label |
| | fruits | orange | Orange |
| | fruits | mango | Mango |
"""
self._create_user_and_login()
xform = self._publish_markdown(markdown_xlsform, self.user)
bob = self.user
export = Export.objects.create(xform=xform)
export.save()
view = ExportViewSet.as_view({"delete": "destroy"})
request = self.factory.delete(
"/export", data=None, content_type="application/json"
)
force_authenticate(request, user=bob)
response = view(request, pk=export.pk)
self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code)

def test_export_list_with_meta_perms(self):
"""
Test export list for forms with meta permissions.
Expand Down
4 changes: 3 additions & 1 deletion onadata/libs/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,10 @@ def _add_instance_prefix_to_dataview_filter_kwargs(self, filter_kwargs):
def _xform_filter(self, request, view, keyword, queryset=None):
"""Use XForm permissions"""
xform = request.query_params.get("xform")
if xform is None and "xform" in request.data:

if xform is None and request.data is not None and "xform" in request.data:
xform = request.data.get("xform")

dataview = request.query_params.get("dataview")
merged_xform = request.query_params.get("merged_xform")
filename = request.query_params.get("filename")
Expand Down

0 comments on commit 30650f9

Please sign in to comment.