diff --git a/onadata/apps/api/tests/viewsets/test_xform_list_viewset.py b/onadata/apps/api/tests/viewsets/test_xform_list_viewset.py index 3a45e41682..3daee48cd0 100644 --- a/onadata/apps/api/tests/viewsets/test_xform_list_viewset.py +++ b/onadata/apps/api/tests/viewsets/test_xform_list_viewset.py @@ -980,6 +980,30 @@ def test_manifest_url_tag_is_not_present_when_no_media(self): '/%s') % (self.user.username, self.xform.id) self.assertTrue(manifest_url in content) + def test_form_list_case_insensitivity(self): + """ + Test that the /formList endpoint utilizes the username in a + case insensitive manner + """ + request = self.factory.get( + f'/{self.user.username}/formList', **self.extra) + response = self.view(request, username=self.user.username) + self.assertEqual(response.status_code, 200) + + request = self.factory.get( + f'/{self.user.username.capitalize()}', **self.extra) + response_2 = self.view( + request, username=self.user.username.capitalize()) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.data, response_2.data) + + request = self.factory.get( + f'/{self.user.username.swapcase()}', **self.extra) + response_3 = self.view( + request, username=self.user.username.capitalize()) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.data, response_3.data) + def test_retrieve_form_using_pk(self): """ Test formList endpoint utilizing primary key is able to retrieve diff --git a/onadata/apps/api/viewsets/xform_list_viewset.py b/onadata/apps/api/viewsets/xform_list_viewset.py index 8ede9b6500..6a1eeec6b6 100644 --- a/onadata/apps/api/viewsets/xform_list_viewset.py +++ b/onadata/apps/api/viewsets/xform_list_viewset.py @@ -82,7 +82,7 @@ def filter_queryset(self, queryset): profile = None if username: profile = get_object_or_404( - UserProfile, user__username=username) + UserProfile, user__username__iexact=username) elif form_pk: queryset = queryset.filter(pk=form_pk) if queryset.first():