forked from mtusi2026/mtusi2026lab5
Forward the lab 4 foundation and migrate the lab 5 pipeline to SQLAlchemy
This commit is contained in:
@@ -1,10 +1,20 @@
|
||||
import json
|
||||
import time
|
||||
from collections.abc import AsyncIterator
|
||||
from uuid import uuid4
|
||||
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
|
||||
from conftest import PASSWORD, actor, keyed, make_chat, register, running_app, split_settings
|
||||
from conftest import (
|
||||
PASSWORD,
|
||||
actor,
|
||||
keyed,
|
||||
make_chat,
|
||||
new_user,
|
||||
register,
|
||||
running_app,
|
||||
split_settings,
|
||||
)
|
||||
from messenger.main import create_app
|
||||
|
||||
MARKER_TEXT = "маркер-который-не-должен-попасть-в-логи-9f3a"
|
||||
@@ -100,6 +110,23 @@ async def test_body_limit_returns_413() -> None:
|
||||
assert response.json()["error"]["code"] == "payload_too_large"
|
||||
|
||||
|
||||
async def test_chunked_body_is_limited_too() -> None:
|
||||
async def chunks(body: bytes) -> AsyncIterator[bytes]:
|
||||
for start in range(0, len(body), 1000):
|
||||
yield body[start : start + 1000]
|
||||
|
||||
user = json.dumps(new_user("chunked")).encode()
|
||||
async with running_app(max_body_bytes=4096) as http:
|
||||
large = await http.post("/api/v1/users", content=chunks(b"x" * 5000))
|
||||
small = await http.post(
|
||||
"/api/v1/users", content=chunks(user), headers={"Content-Type": "application/json"}
|
||||
)
|
||||
assert "content-length" not in large.request.headers
|
||||
assert large.status_code == 413
|
||||
assert large.json()["error"]["code"] == "payload_too_large"
|
||||
assert small.status_code == 201
|
||||
|
||||
|
||||
async def test_ready_turns_unavailable_without_database() -> None:
|
||||
async with running_app(database_url="postgresql://u:p@127.0.0.1:1/none") as http:
|
||||
started = time.perf_counter()
|
||||
|
||||
Reference in New Issue
Block a user