Improve coverage

This commit is contained in:
2026-02-20 06:02:57 +00:00
committed by Anibal Angulo
parent 94226ba913
commit 6edbca98bd
28 changed files with 2719 additions and 387 deletions

View File

@@ -7,9 +7,11 @@ from collections.abc import AsyncGenerator
import pytest
import pytest_asyncio
from fakeredis import aioredis as fakeredis
from capa_de_integracion.config import Settings
from capa_de_integracion.services.firestore_service import FirestoreService
from capa_de_integracion.services.redis_service import RedisService
# Configure pytest-asyncio
pytest_plugins = ("pytest_asyncio",)
@@ -65,6 +67,51 @@ async def _cleanup_collections(service: FirestoreService) -> None:
await doc.reference.delete()
@pytest_asyncio.fixture
async def redis_service(
emulator_settings: Settings,
) -> AsyncGenerator[RedisService, None]:
"""Create RedisService instance with fakeredis for testing."""
service = RedisService(emulator_settings)
# Use fakeredis instead of connecting to a real Redis instance
service.redis = await fakeredis.FakeRedis(decode_responses=True)
yield service
# Cleanup: Close the service
await service.close()
@pytest_asyncio.fixture
async def clean_redis(redis_service: RedisService) -> AsyncGenerator[RedisService, None]:
"""Provide a clean Redis service and cleanup after test."""
# Cleanup before test
await _cleanup_redis(redis_service)
yield redis_service
# Cleanup after test
await _cleanup_redis(redis_service)
async def _cleanup_redis(service: RedisService) -> None:
"""Delete all keys from Redis."""
if service.redis:
# Delete all keys matching our patterns
patterns = [
"conversation:*",
"notification:*",
]
for pattern in patterns:
cursor = 0
while True:
cursor, keys = await service.redis.scan(cursor, match=pattern, count=100)
if keys:
await service.redis.delete(*keys)
if cursor == 0:
break
def pytest_recording_configure(config, vcr):
"""Configure pytest-recording for Firestore emulator."""
# Don't filter requests to the emulator