-
-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3869 from kobotoolbox/3864-permission-sorting-issue
Permission assignments bug fix
- Loading branch information
Showing
3 changed files
with
145 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# coding: utf-8 | ||
from django.test import TestCase | ||
from django.contrib.auth.models import User | ||
|
||
from kpi.utils.object_permission import get_anonymous_user | ||
|
||
|
||
class SortingTestCase(TestCase): | ||
|
||
def test_different_sort_between_python_and_db(self): | ||
|
||
# Ensure that `AnonymousUser` is created to include it in the list below | ||
get_anonymous_user() | ||
|
||
User.objects.bulk_create([ | ||
User(first_name='A', last_name='User', username='a_user'), | ||
User(first_name='Alexander', last_name='Mtembenuzeni', username='alex_Mtemb'), | ||
User(first_name='Another', last_name='User', username='anotheruser'), | ||
]) | ||
|
||
users = list( | ||
User.objects.filter(username__istartswith='a') | ||
.values_list('username', flat=True) | ||
.order_by('username') | ||
) | ||
|
||
# The database (PostgreSQL, as of Jun, 14, 2022) seems to be case | ||
# insensitive and treats `_` after any letters. | ||
# Python is case sensitive and treats `_` before any letters. | ||
expected_database = [ | ||
'alex_Mtemb', | ||
'AnonymousUser', | ||
'anotheruser', | ||
'a_user', | ||
] | ||
|
||
expected_python = [ | ||
'AnonymousUser', | ||
'a_user', | ||
'alex_Mtemb', | ||
'anotheruser', | ||
] | ||
|
||
self.assertEqual(users, expected_database) | ||
self.assertEqual(sorted(users), expected_python) | ||
# Obviously if the first two assertions are True, the one below should | ||
# be false. No matter what, let's be paranoid and test it anyway. | ||
self.assertNotEqual(users, sorted(users)) |