feat(tokens-repo): reset function

This commit is contained in:
Houkime 2022-12-14 17:31:32 +00:00
parent 9ffd67fa19
commit 95e200bfc5
2 changed files with 6 additions and 2 deletions

View file

@ -11,6 +11,7 @@ from selfprivacy_api.utils.redis_pool import RedisPool
from selfprivacy_api.models.tokens.token import Token
from selfprivacy_api.models.tokens.recovery_key import RecoveryKey
from selfprivacy_api.models.tokens.new_device_key import NewDeviceKey
from selfprivacy_api.repositories.tokens.exceptions import TokenNotFound
TOKENS_PREFIX = "token_repo:tokens:"
NEW_DEVICE_KEY_REDIS_KEY = "token_repo:new_device_key"
@ -40,6 +41,10 @@ class RedisTokensRepository(AbstractTokensRepository):
key = RedisTokensRepository._token_redis_key(input_token)
r.delete(key)
def reset(self):
for token in self.get_tokens():
self.delete_token(token)
def get_recovery_key(self) -> Optional[RecoveryKey]:
"""Get the recovery key"""
raise NotImplementedError

View file

@ -159,8 +159,7 @@ def empty_json_repo(empty_keys):
@pytest.fixture
def empty_redis_repo():
repo = RedisTokensRepository()
for token in repo.get_tokens():
repo.delete_token(token)
repo.reset()
assert repo.get_tokens() == []
return repo