pssecret-server/tests/integration/test_utils.py

36 lines
1,011 B
Python
Raw Normal View History

from unittest.mock import patch
from redis.asyncio import Redis
2025-01-01 19:01:10 +00:00
from pssecret_server.utils import get_new_key, save_secret
from ..factories import SecretFactory
async def test_get_new_key_returns_key(redis_server: Redis) -> None:
assert isinstance(await get_new_key(redis_server), str)
async def test_get_new_key_returns_free_key(redis_server: Redis) -> None:
new_key = await get_new_key(redis_server)
res = not await redis_server.exists(new_key)
assert res
2025-01-01 19:01:10 +00:00
@patch("pssecret_server.utils.uuid4", side_effect=("used", "free"))
async def test_get_new_key_skips_used_keys(_, redis_server: Redis) -> None:
await redis_server.set("used", "")
assert await get_new_key(redis_server) == "free"
async def test_save_secret_data(redis_server: Redis) -> None:
secret = SecretFactory.build()
key = await save_secret(secret, redis_server)
redis_data: bytes | None = await redis_server.get(key)
assert redis_data is not None
assert redis_data.decode() == secret.data