Skip to content

Commit

Permalink
Introduce token.token_backend and use it in test
Browse files Browse the repository at this point in the history
  • Loading branch information
totycro committed Feb 10, 2022
1 parent b909ffe commit a1826e7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion rest_framework_simplejwt/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,18 @@ def for_user(cls, user):

_token_backend = None

def get_token_backend(self):
@property
def token_backend(self):
if self._token_backend is None:
self._token_backend = import_string(
"rest_framework_simplejwt.state.token_backend"
)
return self._token_backend

def get_token_backend(self):
# Backward compatibility.
return self.token_backend


class BlacklistMixin:
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ def test_check_token_not_expired_if_in_leeway(self):
token.check_exp("refresh_exp", current_time=datetime_in_leeway)

# a token 1 day expired is valid if leeway is 2 days
token.get_token_backend().leeway = timedelta(days=2).total_seconds()
token.token_backend.leeway = timedelta(days=2).total_seconds()
token.check_exp("refresh_exp", current_time=datetime_in_leeway)
token.get_token_backend().leeway = 0
token.token_backend.leeway = 0

def test_for_user(self):
username = "test_user"
Expand Down

0 comments on commit a1826e7

Please sign in to comment.