From a1826e7f27f2ea8c2de8051136df99d8c57ed3cc Mon Sep 17 00:00:00 2001 From: Bernhard Mallinger Date: Thu, 10 Feb 2022 09:38:13 +0100 Subject: [PATCH] Introduce token.token_backend and use it in test --- rest_framework_simplejwt/tokens.py | 7 ++++++- tests/test_tokens.py | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/rest_framework_simplejwt/tokens.py b/rest_framework_simplejwt/tokens.py index d1049467d..f0cfb846c 100644 --- a/rest_framework_simplejwt/tokens.py +++ b/rest_framework_simplejwt/tokens.py @@ -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: """ diff --git a/tests/test_tokens.py b/tests/test_tokens.py index 45ffbec02..1472fdbb0 100644 --- a/tests/test_tokens.py +++ b/tests/test_tokens.py @@ -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"