Coverage for tests / test_form_default.py: 100%
19 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1from typing import Annotated, Optional 1abcd
3from fastapi import FastAPI, File, Form 1abcd
4from starlette.testclient import TestClient 1abcd
6app = FastAPI() 1abcd
9@app.post("/urlencoded") 1abcd
10async def post_url_encoded(age: Annotated[Optional[int], Form()] = None): 1abcd
11 return age 1efg
14@app.post("/multipart") 1abcd
15async def post_multi_part( 1abcd
16 age: Annotated[Optional[int], Form()] = None,
17 file: Annotated[Optional[bytes], File()] = None,
18):
19 return {"file": file, "age": age} 1hij
22client = TestClient(app) 1abcd
25def test_form_default_url_encoded(): 1abcd
26 response = client.post("/urlencoded", data={"age": ""}) 1efg
27 assert response.status_code == 200 1efg
28 assert response.text == "null" 1efg
31def test_form_default_multi_part(): 1abcd
32 response = client.post("/multipart", data={"age": ""}) 1hij
33 assert response.status_code == 200 1hij
34 assert response.json() == {"file": None, "age": None} 1hij