diff --git a/src/backend/core/api/viewsets.py b/src/backend/core/api/viewsets.py index a9cc5a7c..9c317f1b 100644 --- a/src/backend/core/api/viewsets.py +++ b/src/backend/core/api/viewsets.py @@ -225,10 +225,11 @@ class UserViewSet( # For performance reasons we filter first by similarity, which relies on an # index, then only calculate precise similarity scores for sorting purposes. # - # Additionally we reorder results to prefer users "closer" to the current + # Additionally results are reordered to prefer users "closer" to the current # user: users they recently shared documents with, same full domain, same # partial domain (e.g. both end with "gouv.fr"). To achieve that without - # complex SQL we build a proximity score in Python and returnthe top N results. + # complex SQL, we build a proximity score in Python and return the + # top N results. current_user = self.request.user shared_map = users_sharing_documents_with(current_user) @@ -287,9 +288,6 @@ class UserViewSet( sim, ) - # Sort candidates by the key descending and return top N as a queryset-like - # list. Keep return type consistent with previous behavior (QuerySet slice - # was returned) by returning a list of model instances. candidates.sort(key=_sort_key, reverse=True) return candidates[: settings.API_USERS_LIST_LIMIT] @@ -2295,7 +2293,8 @@ class InvitationViewset( ) # Abilities are computed based on logged-in user's role and # the user role on each document access - .annotate(user_roles=db.Subquery(user_roles_query)).distinct() + .annotate(user_roles=db.Subquery(user_roles_query)) + .distinct() ) return queryset diff --git a/src/backend/core/tests/test_utils.py b/src/backend/core/tests/test_utils.py index 820ac3d1..ec8dc60a 100644 --- a/src/backend/core/tests/test_utils.py +++ b/src/backend/core/tests/test_utils.py @@ -111,6 +111,7 @@ def test_utils_extract_email_domain_parts_when_email_is_valid(): def test_utils_extract_email_domain_parts_when_email_is_empty(): + """Test extraction of email domain parts in case of an empty email.""" empty_email = "" full_domain, partial_domain = utils.extract_email_domain_parts(empty_email) assert full_domain == "" diff --git a/src/backend/core/tests/test_utils_users_sharing_documents_with.py b/src/backend/core/tests/test_utils_users_sharing_documents_with.py index 38635aa2..bf3efeb1 100644 --- a/src/backend/core/tests/test_utils_users_sharing_documents_with.py +++ b/src/backend/core/tests/test_utils_users_sharing_documents_with.py @@ -1,3 +1,7 @@ +""" +Unit tests for the users_sharing_documents_with utility function. +""" + from django.utils import timezone import pytest