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 Jun 12, 2024
1 parent d9818d6 commit d04ce48
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions rest_framework_simplejwt/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.contrib.auth.models import AbstractBaseUser, update_last_login
from django.utils.translation import gettext_lazy as _
from rest_framework import exceptions, serializers
from rest_framework.exceptions import ValidationError, AuthenticationFailed
from rest_framework.exceptions import AuthenticationFailed, ValidationError

from .models import TokenUser
from .settings import api_settings
Expand Down Expand Up @@ -112,7 +112,11 @@ def validate(self, attrs: Dict[str, Any]) -> Dict[str, str]:
refresh = self.token_class(attrs["refresh"])

user_id = refresh.payload.get(api_settings.USER_ID_CLAIM, None)
if user_id and (user := get_user_model().objects.get(**{api_settings.USER_ID_FIELD: user_id})):
if user_id and (
user := get_user_model().objects.get(
**{api_settings.USER_ID_FIELD: user_id}
)
):
if not api_settings.USER_AUTHENTICATION_RULE(user):
raise AuthenticationFailed(
self.error_messages["no_active_account"],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def test_it_should_raise_error_for_inactive_users(self):
self.user.save()

s = TokenRefreshSerializer(data={"refresh": str(refresh)})

with self.assertRaises(drf_exceptions.AuthenticationFailed) as e:
s.is_valid()

Expand Down

0 comments on commit d04ce48

Please sign in to comment.