Coverage for tests/test_param_class.py: 100%
17 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1from typing import Optional 1abcde
3from fastapi import FastAPI 1abcde
4from fastapi.params import Param 1abcde
5from fastapi.testclient import TestClient 1abcde
7app = FastAPI() 1abcde
10@app.get("/items/") 1abcde
11def read_items(q: Optional[str] = Param(default=None)): # type: ignore 1abcde
12 return {"q": q} 1abcde
15client = TestClient(app) 1abcde
18def test_default_param_query_none(): 1abcde
19 response = client.get("/items/") 1abcde
20 assert response.status_code == 200, response.text 1abcde
21 assert response.json() == {"q": None} 1abcde
24def test_default_param_query(): 1abcde
25 response = client.get("/items/?q=foo") 1abcde
26 assert response.status_code == 200, response.text 1abcde
27 assert response.json() == {"q": "foo"} 1abcde