fix(tokens-repo): fix name pair validation being able to raise a notfound error

This commit is contained in:
Houkime 2022-12-21 16:10:41 +00:00
parent 3021584adc
commit 20410ec790
2 changed files with 13 additions and 2 deletions

View file

@ -77,8 +77,11 @@ class AbstractTokensRepository(ABC):
def is_token_name_pair_valid(self, token_name: str, token_string: str) -> bool:
"""Check if the token name and token are valid"""
token = self.get_token_by_name(token_name)
if token is None:
try:
token = self.get_token_by_name(token_name)
if token is None:
return False
except TokenNotFound:
return False
return token.token == token_string

View file

@ -207,6 +207,14 @@ 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_name_pair_valid(some_tokens_repo):
repo = some_tokens_repo
token = repo.get_tokens()[0]
assert repo.is_token_name_pair_valid(token.device_name, token.token)
assert not repo.is_token_name_pair_valid(token.device_name, "gibberish")
assert not repo.is_token_name_pair_valid("gibberish", token.token)
def test_get_tokens(some_tokens_repo):
repo = some_tokens_repo
tokenstrings = []