♻️(backend) isolate authentication tests when dealing only with email

Refactor a test to narrow down its scope to email-related updates.
This commit is contained in:
lebaudantoine
2024-11-13 12:13:17 +01:00
parent bd4dec6f27
commit 0fd06ef6c0

View File

@@ -62,15 +62,14 @@ def test_authentication_getter_new_user_no_email(monkeypatch):
def test_authentication_getter_new_user_with_email(monkeypatch): def test_authentication_getter_new_user_with_email(monkeypatch):
""" """
If no user matches, a user should be created. If no user matches, a user should be created.
User's email and name should be set on the identity. User's info contains an email, created user's email should be filled.
The "email" field on the User model should not be set as it is reserved for staff users.
""" """
klass = OIDCAuthenticationBackend() klass = OIDCAuthenticationBackend()
email = "meet@example.com" email = "meet@example.com"
def get_userinfo_mocked(*args): def get_userinfo_mocked(*args):
return {"sub": "123", "email": email, "first_name": "John", "last_name": "Doe"} return {"sub": "123", "email": email}
monkeypatch.setattr(OIDCAuthenticationBackend, "get_userinfo", get_userinfo_mocked) monkeypatch.setattr(OIDCAuthenticationBackend, "get_userinfo", get_userinfo_mocked)
@@ -80,6 +79,8 @@ def test_authentication_getter_new_user_with_email(monkeypatch):
assert user.sub == "123" assert user.sub == "123"
assert user.email == email assert user.email == email
assert user.full_name is None
assert user.short_name is None
assert user.password == "!" assert user.password == "!"
assert models.User.objects.count() == 1 assert models.User.objects.count() == 1