Skip to content

Commit

Permalink
(Autocomplétion) Ajout d'un test
Browse files Browse the repository at this point in the history
  • Loading branch information
Situphen committed Sep 21, 2024
1 parent df1c558 commit 9ec29f2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions zds/member/api/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.db.utils import IntegrityError
from django.conf import settings
from django.contrib.auth.models import User, Group
from django.core import mail
Expand Down Expand Up @@ -140,6 +141,21 @@ def test_search_without_results_in_list_of_users(self):
self.assertIsNone(response.data.get("next"))
self.assertIsNone(response.data.get("previous"))

def test_search_with_results_in_right_order(self):
"""
Gets list of users corresponding to part of a username and
verifies that the list of usernames returned is in the right order.
"""
for username in ("andr", "Radon", "alexandre", "MisterAndrew", "andré", "Andr", "dragon", "Andromède"):
try:
ProfileFactory(user__username=username)
except IntegrityError: # in case user already exists (maybe from another test)
continue

response = self.client.get(reverse("api:member:list") + "?search=Andr")
list_of_usernames = [item.get("username") for item in response.data.get("results")]
self.assertEqual(list_of_usernames, ["Andr", "andr", "Andromède", "andré", "MisterAndrew", "alexandre"])

def test_register_new_user(self):
"""
Registers a new user in the database.
Expand Down

0 comments on commit 9ec29f2

Please sign in to comment.