mirror of
https://github.com/fastapi/fastapi.git
synced 2026-02-19 15:34:20 -05:00
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: tiangolo <1326112+tiangolo@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
26 lines
604 B
Python
26 lines
604 B
Python
from fastapi import FastAPI
|
|
from fastapi.params import Param
|
|
from fastapi.testclient import TestClient
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.get("/items/")
|
|
def read_items(q: str | None = Param(default=None)): # type: ignore
|
|
return {"q": q}
|
|
|
|
|
|
client = TestClient(app)
|
|
|
|
|
|
def test_default_param_query_none():
|
|
response = client.get("/items/")
|
|
assert response.status_code == 200, response.text
|
|
assert response.json() == {"q": None}
|
|
|
|
|
|
def test_default_param_query():
|
|
response = client.get("/items/?q=foo")
|
|
assert response.status_code == 200, response.text
|
|
assert response.json() == {"q": "foo"}
|