Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand Down
13 changes: 2 additions & 11 deletions tests/test_redis.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
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()