Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,35 @@ def test_dynamodb_cache_rejects_negative_ttl_jitter():

with pytest.raises(ValueError, match="ttl_jitter_seconds must be non-negative"):
DynamoDBCache(cfg, ttl_jitter_seconds=-1)
def test_redis_cache_uses_url_to_create_client():
import redis

fake_client = object()

with patch.object(redis.Redis, "from_url", return_value=fake_client) as from_url:
cache = RedisCache(
url="redis://example:6379/1",
ttl_seconds=120,
)

assert cache._r is fake_client
assert cache.ttl_seconds == 120
from_url.assert_called_once_with("redis://example:6379/1")


def test_redis_cache_prefers_injected_client():
import redis

fake_client = object()

with patch.object(redis.Redis, "from_url") as from_url:
cache = RedisCache(
url="redis://example:6379/1",
client=fake_client,
)

assert cache._r is fake_client
from_url.assert_not_called()

def test_redis_cache_stats():
class FakeRedis:
Expand Down