35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
import pytest
|
|
from httpx import AsyncClient, ASGITransport
|
|
from app.main import app
|
|
from app.__version__ import __version__, __app_name__
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_health_check_returns_200_and_metadata():
|
|
transport = ASGITransport(app=app)
|
|
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
|
response = await client.get("/health")
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["status"] == "ok"
|
|
assert data["version"] == __version__
|
|
assert data["app"] == __app_name__
|
|
assert "timestamp" in data
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_root_redirects_or_returns_info():
|
|
transport = ASGITransport(app=app)
|
|
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
|
response = await client.get("/")
|
|
|
|
assert response.status_code == 200
|
|
content_type = response.headers.get("content-type", "")
|
|
if "application/json" in content_type:
|
|
data = response.json()
|
|
assert data["app"] == __app_name__
|
|
else:
|
|
assert "text/html" in content_type
|
|
assert len(response.text) > 0
|