This commit is contained in:
@@ -9,7 +9,7 @@ import pytest
|
||||
import redis.asyncio as aioredis
|
||||
from redis.asyncio import Redis
|
||||
|
||||
from services.redis import (
|
||||
from storage.redis import (
|
||||
RedisService,
|
||||
close_redis,
|
||||
init_redis,
|
||||
@@ -28,7 +28,7 @@ class TestRedisServiceInitialization:
|
||||
|
||||
def test_redis_service_init_without_aioredis(self):
|
||||
"""Тест инициализации без aioredis"""
|
||||
with patch("services.redis.aioredis", None):
|
||||
with patch("storage.redis.aioredis", None):
|
||||
service = RedisService()
|
||||
assert service._is_available is False
|
||||
|
||||
@@ -58,7 +58,7 @@ class TestRedisConnectionManagement:
|
||||
"""Тест успешного подключения"""
|
||||
service = RedisService()
|
||||
|
||||
with patch("services.redis.aioredis.from_url") as mock_from_url:
|
||||
with patch("storage.redis.aioredis.from_url") as mock_from_url:
|
||||
mock_client = AsyncMock()
|
||||
mock_client.ping = AsyncMock(return_value=True)
|
||||
mock_from_url.return_value = mock_client
|
||||
@@ -73,7 +73,7 @@ class TestRedisConnectionManagement:
|
||||
"""Тест неудачного подключения"""
|
||||
service = RedisService()
|
||||
|
||||
with patch("services.redis.aioredis.from_url") as mock_from_url:
|
||||
with patch("storage.redis.aioredis.from_url") as mock_from_url:
|
||||
mock_from_url.side_effect = Exception("Connection failed")
|
||||
|
||||
await service.connect()
|
||||
@@ -84,7 +84,7 @@ class TestRedisConnectionManagement:
|
||||
@pytest.mark.asyncio
|
||||
async def test_connect_without_aioredis(self):
|
||||
"""Тест подключения без aioredis"""
|
||||
with patch("services.redis.aioredis", None):
|
||||
with patch("storage.redis.aioredis", None):
|
||||
service = RedisService()
|
||||
await service.connect()
|
||||
assert service._client is None
|
||||
@@ -96,7 +96,7 @@ class TestRedisConnectionManagement:
|
||||
mock_existing_client = AsyncMock()
|
||||
service._client = mock_existing_client
|
||||
|
||||
with patch("services.redis.aioredis.from_url") as mock_from_url:
|
||||
with patch("storage.redis.aioredis.from_url") as mock_from_url:
|
||||
mock_client = AsyncMock()
|
||||
mock_client.ping = AsyncMock(return_value=True)
|
||||
mock_from_url.return_value = mock_client
|
||||
@@ -149,7 +149,7 @@ class TestRedisCommandExecution:
|
||||
@pytest.mark.asyncio
|
||||
async def test_execute_without_aioredis(self):
|
||||
"""Тест выполнения команды без aioredis"""
|
||||
with patch("services.redis.aioredis", None):
|
||||
with patch("storage.redis.aioredis", None):
|
||||
service = RedisService()
|
||||
result = await service.execute("test_command")
|
||||
assert result is None
|
||||
@@ -874,7 +874,7 @@ class TestAdditionalRedisCoverage:
|
||||
service._client = mock_client
|
||||
mock_client.close.side_effect = Exception("Close error")
|
||||
|
||||
with patch('services.redis.aioredis.from_url') as mock_from_url:
|
||||
with patch('storage.redis.aioredis.from_url') as mock_from_url:
|
||||
mock_new_client = AsyncMock()
|
||||
mock_from_url.return_value = mock_new_client
|
||||
|
||||
|
||||
Reference in New Issue
Block a user