Files
vidconf/backend/tests/test_health.py

39 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Тесты для GET /api/health."""
from collections.abc import AsyncGenerator
from unittest.mock import AsyncMock, patch
import httpx
from httpx import ASGITransport
from core.db import get_session
from main import create_app
class _FakeSession:
async def execute(self, *args: object, **kwargs: object) -> None:
return None
async def _fake_get_session() -> AsyncGenerator[_FakeSession, None]:
yield _FakeSession()
async def test_health_ok() -> None:
app = create_app()
app.dependency_overrides[get_session] = _fake_get_session
with patch("api.health.redis_client.ping", new=AsyncMock(return_value=True)):
transport = ASGITransport(app=app)
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
response = await client.get("/api/health")
assert response.status_code == 200
body = response.json()
assert body["status"] == "ok"
assert body["db"] is True
assert body["redis"] is True
# Версия инстанса — значение из Settings, не фиксируем точную
# строку здесь (совпадает с дефолтом Settings.vidconf_version в dev).
assert "version" in body