From abf11565d1955e72f0dbfdbde44260736429d091 Mon Sep 17 00:00:00 2001 From: senkovskiy Date: Sun, 30 Mar 2025 23:30:17 +0200 Subject: [PATCH 1/2] change redis test --- tests/conftest.py | 9 +++++++++ tests/test_redis.py | 12 ++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index cd2ef68..4a24f17 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,6 +5,7 @@ from sqlalchemy.ext.asyncio import AsyncSession from src.database.connection import session_maker from dotenv import load_dotenv +from src.dependencies.redis import startup, shutdown load_dotenv() @@ -14,6 +15,14 @@ async def app(): return get_application() +@pytest_asyncio.fixture +async def app_with_redis(): + app = get_application() + await startup() # manually start Redis + yield app + await shutdown() # manually shutdown Redis + + @pytest_asyncio.fixture async def client(app): transport = ASGITransport(app=app) diff --git a/tests/test_redis.py b/tests/test_redis.py index 1b9cfc0..08f012c 100644 --- a/tests/test_redis.py +++ b/tests/test_redis.py @@ -1,22 +1,14 @@ import pytest from httpx import AsyncClient, ASGITransport -from api.app import get_application @pytest.mark.asyncio -async def test_redis_ping(): - app = get_application() - - transport = ASGITransport(app=app) +async def test_redis_ping(app_with_redis): + transport = ASGITransport(app=app_with_redis) async with AsyncClient(transport=transport, base_url="http://test") as client: - # manually trigger Redis startup - await app.router.startup() - res = await client.get("/api/v1/redis/ping") assert res.status_code == 200 data = res.json() assert data["status"] == "OK" assert data["ping"] == "pong" - # manually trigger Redis shutdown - await app.router.shutdown() From 992ff692405c0aa0200e7729c838f7e8f2e6ce19 Mon Sep 17 00:00:00 2001 From: senkovskiy Date: Sun, 30 Mar 2025 23:34:36 +0200 Subject: [PATCH 2/2] change redis test --- tests/test_redis.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_redis.py b/tests/test_redis.py index 08f012c..68fda3b 100644 --- a/tests/test_redis.py +++ b/tests/test_redis.py @@ -1,7 +1,6 @@ import pytest from httpx import AsyncClient, ASGITransport - @pytest.mark.asyncio async def test_redis_ping(app_with_redis): transport = ASGITransport(app=app_with_redis)