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 da670d7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
Binary file modified fixtures/tuto/article_v1.zip
Binary file not shown.
Binary file modified fixtures/tuto/balise_audio.zip
Binary file not shown.
Binary file modified fixtures/tuto/big_tuto_v1.zip
Binary file not shown.
17 changes: 16 additions & 1 deletion zds/member/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from zds.api.pagination import REST_PAGE_SIZE, REST_MAX_PAGE_SIZE, REST_PAGE_SIZE_QUERY_PARAM
from zds.api.utils import authenticate_oauth2_client
from zds.member.tests.factories import ProfileFactory, StaffProfileFactory, ProfileNotSyncFactory
from zds.member.models import TokenRegister, BannedEmailProvider
from zds.member.models import Profile, TokenRegister, BannedEmailProvider
from rest_framework_extensions.settings import extensions_api_settings
from django.core.cache import caches

Expand Down Expand Up @@ -140,6 +140,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: # in case this username has already been used by another test
Profile.objects.get(user__username=username)
except Profile.DoesNotExist:
ProfileFactory(user__username=username)

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 da670d7

Please sign in to comment.