Skip to content

Commit

Permalink
Fix charts groupby multiple fields and check content type (#2151)
Browse files Browse the repository at this point in the history
* test on charts by grouping multiple fields

* test on charts with content type

* update the format to json when content type has been provided

* styling fix

* styling fix

* Update onadata/apps/api/tests/viewsets/test_charts_viewset.py

Co-authored-by: Davis Raymond <[email protected]>

* Clean out Merged Datasets upon xform deletion. Clean out Form Media Files upon form deletion. Add documentation on clean up of filtered datasets (#2136)

* Query data endpoint by submission review. Filter `NULL` review status (#2144)

* Add failing tests

* Include ability to generate sql statement for NULL query strings.

* Update data endpoint documentation

* Remove unnecessary test

* test on charts by grouping multiple fields

* test on charts with content type

* update the format to json when content type has been provided

* styling fix

* styling fix

* Update onadata/apps/api/tests/viewsets/test_charts_viewset.py

Co-authored-by: Davis Raymond <[email protected]>

* Remove unnecessary test

Co-authored-by: Davis Raymond <[email protected]>
Co-authored-by: Winnie Kiragu <[email protected]>
  • Loading branch information
3 people authored Nov 11, 2021
1 parent 74ffb93 commit f11c688
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions onadata/apps/api/tests/viewsets/test_charts_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,19 @@ def test_nan_not_json_response(self):
"xform": self.xform.pk
}
self.assertEqual(expected, res)

def test_on_charts_with_content_type(self):
request = self.factory.get('/charts', content_type="application/json")
force_authenticate(request, user=self.user)
response = self.view(
request,
pk=self.xform.pk,
id_string=self.xform.id_string
)
expected = {
'id': self.xform.pk,
'id_string': self.xform.id_string,
'url': 'http://testserver/api/v1/charts/{}'.format(self.xform.pk)
}
self.assertEqual(200, response.status_code)
self.assertDictContainsSubset(expected, response.data)
5 changes: 5 additions & 0 deletions onadata/apps/api/viewsets/charts_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,16 @@ def retrieve(self, request, *args, **kwargs):
field_name = request.query_params.get('field_name')
field_xpath = request.query_params.get('field_xpath')
fields = request.query_params.get('fields')
content_type = request.content_type
group_by = request.query_params.get('group_by')
fmt = kwargs.get('format')

xform = self.get_object()
serializer = self.get_serializer(xform)
# This is to update the format to be json
# when the content_type has been provided.
if fmt is None and content_type == 'application/json':
fmt = 'json'

if fields:
if fmt is not None and fmt != 'json':
Expand Down

0 comments on commit f11c688

Please sign in to comment.