API - searching user is case insensitive
This commit is contained in:
parent
0b1d99aa7a
commit
08d412bddf
@ -780,6 +780,42 @@ class TestGetUsers(ApiTestCaseMixin):
|
||||
'total': 1,
|
||||
}
|
||||
|
||||
def test_it_returns_username_matching_query(
|
||||
self, app: Flask, user_1_admin: User, user_2: User, user_3: User
|
||||
) -> None:
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
app, user_1_admin.email
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/api/users?q=oto',
|
||||
headers=dict(Authorization=f'Bearer {auth_token}'),
|
||||
)
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['users']) == 1
|
||||
assert 'toto' in data['data']['users'][0]['username']
|
||||
|
||||
def test_it_filtering_on_username_is_case_insensitive(
|
||||
self, app: Flask, user_1_admin: User, user_2: User, user_3: User
|
||||
) -> None:
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
app, user_1_admin.email
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/api/users?q=TOTO',
|
||||
headers=dict(Authorization=f'Bearer {auth_token}'),
|
||||
)
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['users']) == 1
|
||||
assert 'toto' in data['data']['users'][0]['username']
|
||||
|
||||
def test_it_returns_empty_users_list_filtering_on_username(
|
||||
self, app: Flask, user_1_admin: User, user_2: User, user_3: User
|
||||
) -> None:
|
||||
|
@ -194,7 +194,7 @@ def get_users(auth_user: User) -> Dict:
|
||||
query = params.get('q')
|
||||
users_pagination = (
|
||||
User.query.filter(
|
||||
User.username.like('%' + query + '%') if query else True,
|
||||
User.username.ilike('%' + query + '%') if query else True,
|
||||
)
|
||||
.order_by(
|
||||
User.workouts_count.asc() # type: ignore
|
||||
|
Loading…
Reference in New Issue
Block a user