mirror of
https://github.com/d3vyce/taskiq-deduplication.git
synced 2026-08-04 19:14:07 +00:00
feat: allow pydantic RedisDsn in addition to str for redis_url (#62)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from pydantic import RedisDsn, TypeAdapter
|
||||
|
||||
from taskiq_deduplication import DuplicateTaskError, RedisDeduplicationMiddleware
|
||||
from taskiq_deduplication.middleware import (
|
||||
@@ -341,6 +342,17 @@ class TestLifecycle:
|
||||
mock_from_url.assert_called_once_with("redis://localhost")
|
||||
assert mw._redis is mock_client
|
||||
|
||||
async def test_startup_accepts_redis_dsn(self):
|
||||
dsn = TypeAdapter(RedisDsn).validate_python("redis://localhost:6379/0")
|
||||
mw = RedisDeduplicationMiddleware(redis_url=dsn)
|
||||
with patch("redis.asyncio.Redis.from_url") as mock_from_url:
|
||||
mock_client = AsyncMock()
|
||||
mock_client.register_script = MagicMock()
|
||||
mock_from_url.return_value = mock_client
|
||||
await mw.startup()
|
||||
mock_from_url.assert_called_once_with("redis://localhost:6379/0")
|
||||
assert mw._redis is mock_client
|
||||
|
||||
async def test_shutdown_closes_redis_client(self):
|
||||
mw = RedisDeduplicationMiddleware(redis_url="redis://localhost")
|
||||
mock_client = AsyncMock()
|
||||
|
||||
Reference in New Issue
Block a user