Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve user profile using case insensitive username filter #1988

Merged
merged 2 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions onadata/apps/api/tests/viewsets/test_xform_list_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,30 @@ def test_manifest_url_tag_is_not_present_when_no_media(self):
'/%s</manifestUrl>') % (self.user.username, self.xform.id)
self.assertTrue(manifest_url in content)

def test_form_list_case_insensitivity(self):
"""
Test that the <username>/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
Expand Down
2 changes: 1 addition & 1 deletion onadata/apps/api/viewsets/xform_list_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down