fix(tokens-repo): fix is_name_exists() being fallible

redis/token-repo
Houkime 2022-12-21 17:04:18 +00:00
parent 2a239e35ad
commit 22a309466e
2 changed files with 8 additions and 4 deletions

View File

@ -70,10 +70,7 @@ class AbstractTokensRepository(ABC):
def is_token_name_exists(self, token_name: str) -> bool:
"""Check if the token name exists"""
token = self.get_token_by_name(token_name)
if token is None:
return False
return True
return token_name in [token.device_name for token in self.get_tokens()]
def is_token_name_pair_valid(self, token_name: str, token_string: str) -> bool:
"""Check if the token name and token are valid"""

View File

@ -215,6 +215,13 @@ def test_is_token_name_pair_valid(some_tokens_repo):
assert not repo.is_token_name_pair_valid("gibberish", token.token)
def test_is_token_name_exists(some_tokens_repo):
repo = some_tokens_repo
token = repo.get_tokens()[0]
assert repo.is_token_name_exists(token.device_name)
assert not repo.is_token_name_exists("gibberish")
def test_get_tokens(some_tokens_repo):
repo = some_tokens_repo
tokenstrings = []