Skip to content

Commit

Permalink
tests(account): python 3.8 vs multi 'with'
Browse files Browse the repository at this point in the history
  • Loading branch information
pennersr committed Nov 30, 2024
1 parent 5d295d4 commit a1ed6bc
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions allauth/account/tests/test_auth_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,23 @@ def test_auth_by_username_or_email(self):
)
def test_account_enumeration_timing_attack(user, db, rf, settings, auth_method):
settings.ACCOUNT_AUTHENTICATION_METHOD = auth_method
with (
patch("django.contrib.auth.models.User.set_password") as set_password_mock,
patch("django.contrib.auth.models.User.check_password", new=set_password_mock),
):
backend = AuthenticationBackend()
backend.authenticate(
rf.get("/"), email="[email protected]", username="not-known", password="secret"
)
set_password_mock.assert_called_once()
set_password_mock.reset_mock()
backend.authenticate(rf.get("/"), username=user.username, password="secret")
set_password_mock.assert_called_once()
set_password_mock.reset_mock()
backend.authenticate(
rf.get("/"), email=user.email, username="not-known", password="secret"
)
set_password_mock.assert_called_once()
with patch("django.contrib.auth.models.User.set_password") as set_password_mock:
with patch(
"django.contrib.auth.models.User.check_password", new=set_password_mock
):
backend = AuthenticationBackend()
backend.authenticate(
rf.get("/"),
email="[email protected]",
username="not-known",
password="secret",
)
set_password_mock.assert_called_once()
set_password_mock.reset_mock()
backend.authenticate(rf.get("/"), username=user.username, password="secret")
set_password_mock.assert_called_once()
set_password_mock.reset_mock()
backend.authenticate(
rf.get("/"), email=user.email, username="not-known", password="secret"
)
set_password_mock.assert_called_once()

0 comments on commit a1ed6bc

Please sign in to comment.