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

1from typing import Optional 1abcde

2 

3from fastapi import FastAPI 1abcde

4from fastapi.params import Param 1abcde

5from fastapi.testclient import TestClient 1abcde

6 

7app = FastAPI() 1abcde

8 

9 

10@app.get("/items/") 1abcde

11def read_items(q: Optional[str] = Param(default=None)): # type: ignore 1abcde

12 return {"q": q} 1abcde

13 

14 

15client = TestClient(app) 1abcde

16 

17 

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

22 

23 

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