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
+15 -15
View File
@@ -1,21 +1,21 @@
import logging
import json
from fastapi.testclient import TestClient
from httpx import AsyncClient
from tests.helpers import assert_request_id
def test_missing_token_returns_401(client: TestClient):
response = client.get("/api/v1/users/me")
async def test_missing_token_returns_401(client: AsyncClient):
response = await client.get("/api/v1/users/me")
assert response.status_code == 401
assert response.json()["error"]["code"] == "unauthorized"
assert_request_id(response)
def test_garbage_token_returns_401(client: TestClient):
response = client.get(
async def test_garbage_token_returns_401(client: AsyncClient):
response = await client.get(
"/api/v1/users/me", headers={"Authorization": "Bearer garbage"}
)
@@ -24,8 +24,8 @@ def test_garbage_token_returns_401(client: TestClient):
assert_request_id(response)
def test_malformed_json_returns_400(client: TestClient):
response = client.post(
async def test_malformed_json_returns_400(client: AsyncClient):
response = await client.post(
"/api/v1/users",
content='{"username":"alice",',
headers={"Content-Type": "application/json"},
@@ -36,25 +36,25 @@ def test_malformed_json_returns_400(client: TestClient):
assert_request_id(response)
def test_not_found_returns_404(client: TestClient):
response = client.get("/no-such-path")
async def test_not_found_returns_404(client: AsyncClient):
response = await client.get("/no-such-path")
assert response.status_code == 404
assert response.json()["error"]["code"] == "not_found"
assert_request_id(response)
def test_method_not_allowed_preserves_405(client: TestClient):
response = client.delete("/api/v1/users")
async def test_method_not_allowed_preserves_405(client: AsyncClient):
response = await client.delete("/api/v1/users")
assert response.status_code == 405
assert response.json()["error"]["code"] == "invalid_request"
assert_request_id(response)
def test_unhandled_exception_is_hidden_from_client(client_no_raise: TestClient, caplog):
async def test_unhandled_exception_is_hidden_from_client(client_no_raise: AsyncClient, caplog):
with caplog.at_level(logging.ERROR, logger="app.errors.handlers"):
response = client_no_raise.get("/__test__/explode")
response = await client_no_raise.get("/__test__/explode")
assert response.status_code == 500
payload = response.json()
@@ -67,8 +67,8 @@ def test_unhandled_exception_is_hidden_from_client(client_no_raise: TestClient,
assert_request_id(response)
def test_success_response_contains_request_id(client: TestClient):
response = client.get("/health/live")
async def test_success_response_contains_request_id(client: AsyncClient):
response = await client.get("/health/live")
assert response.status_code == 200
assert response.headers.get("X-Request-Id")