mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-18 16:39:13 +00:00
fix(tokens-repo): make is_token_valid infallible
This commit is contained in:
parent
87ea88c50a
commit
7d9bccf4ec
|
@ -63,10 +63,7 @@ class AbstractTokensRepository(ABC):
|
|||
|
||||
def is_token_valid(self, token_string: str) -> bool:
|
||||
"""Check if the token is valid"""
|
||||
token = self.get_token_by_token_string(token_string)
|
||||
if token is None:
|
||||
return False
|
||||
return True
|
||||
return token_string in [token.token for token in self.get_tokens()]
|
||||
|
||||
def is_token_name_exists(self, token_name: str) -> bool:
|
||||
"""Check if the token name exists"""
|
||||
|
|
|
@ -207,6 +207,13 @@ def test_get_token_by_non_existent_name(some_tokens_repo):
|
|||
assert repo.get_token_by_name(token_name="badname") is None
|
||||
|
||||
|
||||
def test_is_token_valid(some_tokens_repo):
|
||||
repo = some_tokens_repo
|
||||
token = repo.get_tokens()[0]
|
||||
assert repo.is_token_valid(token.token)
|
||||
assert not repo.is_token_valid("gibberish")
|
||||
|
||||
|
||||
def test_is_token_name_pair_valid(some_tokens_repo):
|
||||
repo = some_tokens_repo
|
||||
token = repo.get_tokens()[0]
|
||||
|
|
Loading…
Reference in a new issue