forked from numerique-gouv/impress
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚸(backend) improve users similarity search and sort results
In some edge cases, the domain part the email addresse is longer than the name part. Users searches by email similarity then return a lot of unsorted results. We can improve this by being more demanding on similarity when the query looks like an email. Sorting results by the similarity score is also an obvious improvement. At the moment, we still think it is good to propose results with a weak similarity on the name part because we want to avoid as much as possible creating duplicate users by inviting one of is many emails, a user who is already in our database. Fixes 399
- Loading branch information
1 parent
50891af
commit 4f4951c
Showing
3 changed files
with
60 additions
and
0 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 |
---|---|---|
|
@@ -69,6 +69,48 @@ def test_api_users_list_query_email(): | |
assert user_ids == [str(nicole.id), str(frank.id)] | ||
|
||
|
||
def test_api_users_list_query_email_matching(): | ||
"""While filtering by email, results should be filtered and sorted by similarity""" | ||
user = factories.UserFactory() | ||
|
||
client = APIClient() | ||
client.force_login(user) | ||
|
||
alice = factories.UserFactory(email="[email protected]") | ||
factories.UserFactory(email="[email protected]") | ||
michael_wilson = factories.UserFactory(email="[email protected]") | ||
factories.UserFactory(email="[email protected]") | ||
michael_brown = factories.UserFactory(email="[email protected]") | ||
factories.UserFactory(email="[email protected]") | ||
|
||
response = client.get( | ||
"/api/v1.0/users/[email protected]", | ||
) | ||
assert response.status_code == 200 | ||
user_ids = [user["id"] for user in response.json()["results"]] | ||
assert user_ids == [str(michael_wilson.id)] | ||
|
||
response = client.get("/api/v1.0/users/[email protected]") | ||
|
||
assert response.status_code == 200 | ||
user_ids = [user["id"] for user in response.json()["results"]] | ||
assert user_ids == [str(michael_wilson.id), str(alice.id), str(michael_brown.id)] | ||
|
||
response = client.get( | ||
"/api/v1.0/users/[email protected]", | ||
) | ||
assert response.status_code == 200 | ||
user_ids = [user["id"] for user in response.json()["results"]] | ||
assert user_ids == [str(alice.id)] | ||
|
||
response = client.get( | ||
"/api/v1.0/users/[email protected]", | ||
) | ||
assert response.status_code == 200 | ||
user_ids = [user["id"] for user in response.json()["results"]] | ||
assert user_ids == [str(michael_wilson.id)] | ||
|
||
|
||
def test_api_users_list_query_email_exclude_doc_user(): | ||
""" | ||
Authenticated users should be able to list users | ||
|