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 -17
View File
@@ -1,11 +1,11 @@
import pytest
from fastapi.testclient import TestClient
from httpx import AsyncClient
from tests.helpers import PASSWORD, assert_request_id, bearer, create_user, register
def test_register_does_not_leak_password(client: TestClient):
response = client.post(
async def test_register_does_not_leak_password(client: AsyncClient):
response = await client.post(
"/api/v1/users",
json={"username": "alice", "display_name": "Алиса 👋", "password": PASSWORD},
)
@@ -17,10 +17,10 @@ def test_register_does_not_leak_password(client: TestClient):
assert_request_id(response)
def test_get_current_user(client: TestClient):
user = create_user(client, display_name="Алиса 👋")
async def test_get_current_user(client: AsyncClient):
user = await create_user(client, display_name="Алиса 👋")
response = client.get("/api/v1/users/me", headers=bearer(user))
response = await client.get("/api/v1/users/me", headers=bearer(user))
assert response.status_code == 200
assert response.json()["id"] == user["id"]
@@ -43,17 +43,17 @@ def test_get_current_user(client: TestClient):
{"username": "alice", "display_name": "Alice", "password": "x" * 129},
],
)
def test_invalid_user_payloads(client: TestClient, body: dict):
response = client.post("/api/v1/users", json=body)
async def test_invalid_user_payloads(client: AsyncClient, body: dict):
response = await client.post("/api/v1/users", json=body)
assert response.status_code == 400
assert response.json()["error"]["code"] == "invalid_request"
assert_request_id(response)
def test_password_length_boundaries_are_accepted(client: TestClient):
async def test_password_length_boundaries_are_accepted(client: AsyncClient):
for index, password in enumerate(["x" * 12, "y" * 128, " " * 12, "п" * 12]):
response = client.post(
response = await client.post(
"/api/v1/users",
json={
"username": f"pw_user_{index}",
@@ -64,8 +64,8 @@ def test_password_length_boundaries_are_accepted(client: TestClient):
assert response.status_code == 201, (index, response.text)
def test_extra_user_field_is_rejected(client: TestClient):
response = client.post(
async def test_extra_user_field_is_rejected(client: AsyncClient):
response = await client.post(
"/api/v1/users",
json={
"username": "alice",
@@ -79,10 +79,10 @@ def test_extra_user_field_is_rejected(client: TestClient):
assert response.json()["error"]["code"] == "invalid_request"
def test_duplicate_username_returns_conflict(client: TestClient):
user = register(client, username="duplicate_user")
async def test_duplicate_username_returns_conflict(client: AsyncClient):
user = await register(client, username="duplicate_user")
response = client.post(
response = await client.post(
"/api/v1/users",
json={
"username": user["username"],
@@ -96,8 +96,8 @@ def test_duplicate_username_returns_conflict(client: TestClient):
assert_request_id(response)
def test_user_exact_length_boundaries_are_accepted(client: TestClient):
async def test_user_exact_length_boundaries_are_accepted(client: AsyncClient):
for length in (3, 32):
user = register(client, username=("a" * length), display_name="d" * 100)
user = await register(client, username=("a" * length), display_name="d" * 100)
assert len(user["username"]) == length
assert len(user["display_name"]) == 100