add async with all functions

This commit is contained in:
2026-10-23 00:20:58 +03:00
parent a85702a30e
commit 7b7ca1b888
42 changed files with 901 additions and 763 deletions
+17 -16
View File
@@ -1,52 +1,52 @@
from fastapi.testclient import TestClient
from httpx import AsyncClient
from app.main import create_app
from tests.conftest import make_client
from tests.helpers import assert_request_id
def test_liveness(client: TestClient):
response = client.get("/health/live")
async def test_liveness(client: AsyncClient):
response = await client.get("/health/live")
assert response.status_code == 200
assert response.json() == {"status": "ok"}
assert_request_id(response)
def test_readiness(client: TestClient):
response = client.get("/health/ready")
async def test_readiness(client: AsyncClient):
response = await client.get("/health/ready")
assert response.status_code == 200
assert response.json() == {"status": "ok"}
assert_request_id(response)
def test_readiness_is_503_when_database_is_down(make_settings):
"""БД недоступна: live по-прежнему 200, ready — ограниченный 503."""
async def test_readiness_is_503_when_database_is_down(make_settings):
app = create_app(
make_settings(
database_url="postgresql+psycopg://nobody:nopass@127.0.0.1:1/none",
database_url="postgresql+asyncpg://nobody:nopass@127.0.0.1:1/none",
db_connect_timeout_seconds=1,
)
)
with TestClient(app) as client:
assert client.get("/health/live").status_code == 200
async with make_client(app) as client:
assert (await client.get("/health/live")).status_code == 200
ready = client.get("/health/ready")
ready = await client.get("/health/ready")
assert ready.status_code == 503
assert ready.json()["error"]["code"] == "unavailable"
assert_request_id(ready)
await app.state.engine.dispose()
def test_business_request_is_503_when_database_is_down(make_settings):
"""Недоступность БД не превращается в 500 и не раскрывает детали подключения."""
async def test_business_request_is_503_when_database_is_down(make_settings):
app = create_app(
make_settings(
database_url="postgresql+psycopg://nobody:secretpass@127.0.0.1:1/none",
database_url="postgresql+asyncpg://nobody:secretpass@127.0.0.1:1/none",
db_connect_timeout_seconds=1,
)
)
with TestClient(app, raise_server_exceptions=False) as client:
response = client.post(
async with make_client(app, raise_app_exceptions=False) as client:
response = await client.post(
"/api/v1/users",
json={
"username": "alice",
@@ -54,6 +54,7 @@ def test_business_request_is_503_when_database_is_down(make_settings):
"password": "Correct-horse-battery-1",
},
)
await app.state.engine.dispose()
assert response.status_code == 503
assert response.json()["error"]["code"] == "unavailable"