Added support for all Redis versions (>=1.0.0) #5

Merged
root merged 4 commits from support-earlier-redis-versions into main 2025-01-08 21:22:26 +00:00
2 changed files with 17 additions and 32 deletions
Showing only changes of commit fcefa41956 - Show all commits

View file

@ -1,5 +1,6 @@
from unittest.mock import AsyncMock, Mock, patch
from unittest.mock import AsyncMock, patch
import pytest
from redis.asyncio import Redis
from pssecret_server.utils import get_new_key, getdel, save_secret
@ -35,27 +36,14 @@ async def test_save_secret_data(redis_server: Redis) -> None:
assert redis_data.decode() == secret.data
@patch("pssecret_server.utils._is_getdel_available", side_effect=AsyncMock())
async def test_getdel_when_available(
is_getdel_available: Mock, redis_server: Redis
@pytest.mark.parametrize("getdel_available", [True, False])
@patch("pssecret_server.utils._is_getdel_available", new_callable=AsyncMock)
async def test_getdel(
mock_is_getdel_available: AsyncMock,
getdel_available: bool,
redis_server: Redis,
) -> None:
is_getdel_available.side_effect.return_value = True
test_value = "test_data"
test_key = "test_key"
await redis_server.set(test_key, test_value)
result = await getdel(redis_server, test_key)
assert result.decode() == test_value
assert not await redis_server.exists(test_key)
@patch("pssecret_server.utils._is_getdel_available", side_effect=AsyncMock())
async def test_getdel_when_not_available(
is_getdel_available: Mock, redis_server: Redis
) -> None:
is_getdel_available.side_effect.return_value = False
mock_is_getdel_available.return_value = getdel_available
test_value = "test_data"
test_key = "test_key"

View file

@ -34,18 +34,15 @@ def test_secret_is_not_decryptable_by_random_key(fernet: Fernet):
decrypt_secret(encrypted_secret.data.encode(), random_fernet)
async def test_is_getdel_available_when_supported():
@pytest.mark.parametrize(
("getdel_effect", "expected_result"), [(None, True), (ResponseError, False)]
)
async def test_is_getdel_available(
getdel_effect: ResponseError | None, expected_result: bool
):
redis = AsyncMock()
redis.getdel.side_effect = getdel_effect # pyright: ignore[reportAny]
result = await _is_getdel_available(redis)
assert result is True
async def test_is_getdel_available_when_not_supported():
redis = AsyncMock()
redis.getdel.side_effect = ResponseError
result = await _is_getdel_available(redis)
assert result is False
assert result is expected_result