From 7d9bccf4ec67b83a017caa19495092b1ad33c176 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Mon, 26 Dec 2022 15:18:02 +0000 Subject: [PATCH] fix(tokens-repo): make is_token_valid infallible --- .../repositories/tokens/abstract_tokens_repository.py | 5 +---- .../test_graphql/test_repository/test_tokens_repository.py | 7 +++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/selfprivacy_api/repositories/tokens/abstract_tokens_repository.py b/selfprivacy_api/repositories/tokens/abstract_tokens_repository.py index 7601ef4..dcd2b0d 100644 --- a/selfprivacy_api/repositories/tokens/abstract_tokens_repository.py +++ b/selfprivacy_api/repositories/tokens/abstract_tokens_repository.py @@ -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""" diff --git a/tests/test_graphql/test_repository/test_tokens_repository.py b/tests/test_graphql/test_repository/test_tokens_repository.py index a95878d..dd4f0ef 100644 --- a/tests/test_graphql/test_repository/test_tokens_repository.py +++ b/tests/test_graphql/test_repository/test_tokens_repository.py @@ -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]