Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 21, 2025
1 parent 6bab138 commit 2a71d65
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
"filename": "main/settings.py",
"hashed_secret": "09edaaba587f94f60fbb5cee2234507bcb883cc2",
"is_verified": false,
"line_number": 954
"line_number": 955
}
],
"pants": [
Expand Down Expand Up @@ -240,5 +240,5 @@
}
]
},
"generated_at": "2025-01-22T20:35:24Z"
"generated_at": "2025-02-21T19:27:26Z"
}
6 changes: 4 additions & 2 deletions authentication/pipeline/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from social_core.pipeline.partial import partial
from social_django.models import UserSocialAuth


from authentication.exceptions import (
EmailBlockedException,
InvalidPasswordException,
Expand Down Expand Up @@ -82,7 +81,10 @@ def limit_one_auth_per_backend(strategy, backend, user, uid, **kwargs): # pylin
# if there's at least one social auth and any of them don't match the incoming uid
# we have or are trying to add multiple accounts
if social_auths and any(auth.uid != uid for auth in social_auths):
raise AuthException(backend.name, "Another account is already linked to your MITxOnline account.")
raise AuthException(
backend.name,
"Another account is already linked to your MITxOnline account.",
)

return {}

Expand Down
16 changes: 11 additions & 5 deletions authentication/pipeline/user_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
from django.db import IntegrityError
from rest_framework import status
from social_core.backends.email import EmailAuth
from social_django.utils import load_backend, load_strategy
from social_core.exceptions import AuthException
from social_django.models import UserSocialAuth


from social_django.utils import load_backend, load_strategy

from authentication.exceptions import (
EmailBlockedException,
Expand Down Expand Up @@ -550,7 +548,13 @@ def test_limit_one_auth_per_backend_no_user(mocker):
"""limit_one_auth_per_backend should not error if the user doesn't exist"""
mock_strategy = mocker.Mock()
mock_backend = mocker.Mock()
assert user_actions.limit_one_auth_per_backend(strategy=mock_strategy, backend=mock_backend, user=None, uid=None) == {}
assert (
user_actions.limit_one_auth_per_backend(
strategy=mock_strategy, backend=mock_backend, user=None, uid=None
)
== {}
)


@pytest.mark.django_db
def test_limit_one_auth_per_backend_conflicting_auth(mocker, user):
Expand All @@ -563,4 +567,6 @@ def test_limit_one_auth_per_backend_conflicting_auth(mocker, user):
assert UserSocialAuth.filter(user=user, provider=mock_backend.name).count() == 1

with pytest.raises(AuthException):
user_actions.limit_one_auth_per_backend(backend=mock_backend, user=user, strategy=mock_strategy, uid="non-matching")
user_actions.limit_one_auth_per_backend(
backend=mock_backend, user=user, strategy=mock_strategy, uid="non-matching"
)

0 comments on commit 2a71d65

Please sign in to comment.