Browse Source

add tests

pull/13537/head
adhoc 2 weeks ago
parent
commit
5e501bb4c0
  1. 46
      tests/test_form_default.py

46
tests/test_form_default.py

@ -0,0 +1,46 @@
from typing import Annotated, Optional
from fastapi import FastAPI, File, Form
from starlette.testclient import TestClient
app = FastAPI()
client = TestClient(app)
@app.post("/urlencoded")
async def post_url_encoded(age: Annotated[Optional[int], Form()] = None):
return age
def test_form_default_url_encoded():
response = client.post("/urlencoded", data={"age": ""})
assert response.status_code == 200
assert response.text == "null"
@app.post("/multipart")
async def post_multi_part(
age: Annotated[Optional[int], Form()] = None,
file: Annotated[Optional[bytes], File()] = None,
):
assert file is None
assert age is None
def test_form_default_multi_part():
response = client.post("/multipart", data={"age": ""})
assert response.status_code == 200
@app.post("/multipart-file-first")
async def post_multi_part_file_first(
file: Annotated[Optional[bytes], File()] = None,
age: Annotated[Optional[int], Form()] = None,
):
assert file is None
assert age is None
def test_form_default_multi_part_file_first():
response = client.post("/multipart-file-first", data={"age": ""})
assert response.status_code == 200
Loading…
Cancel
Save