Coverage for tests/test_allow_inf_nan_in_enforcing.py: 100%
25 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-05 00:03 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-05 00:03 +0000
1import pytest 1abcdef
2from fastapi import Body, FastAPI, Query 1abcdef
3from fastapi.testclient import TestClient 1abcdef
4from typing_extensions import Annotated 1abcdef
6app = FastAPI() 1abcdef
9@app.post("/") 1abcdef
10async def get( 1abcdef
11 x: Annotated[float, Query(allow_inf_nan=True)] = 0,
12 y: Annotated[float, Query(allow_inf_nan=False)] = 0,
13 z: Annotated[float, Query()] = 0,
14 b: Annotated[float, Body(allow_inf_nan=False)] = 0,
15) -> str:
16 return "OK" 1ghijklmnopqrstuvwxyzABCD
19client = TestClient(app) 1abcdef
22@pytest.mark.parametrize( 1abcdef
23 "value,code",
24 [
25 ("-1", 200),
26 ("inf", 200),
27 ("-inf", 200),
28 ("nan", 200),
29 ("0", 200),
30 ("342", 200),
31 ],
32)
33def test_allow_inf_nan_param_true(value: str, code: int): 1abcdef
34 response = client.post(f"/?x={value}") 1jnrvzD
35 assert response.status_code == code, response.text 1jnrvzD
38@pytest.mark.parametrize( 1abcdef
39 "value,code",
40 [
41 ("-1", 200),
42 ("inf", 422),
43 ("-inf", 422),
44 ("nan", 422),
45 ("0", 200),
46 ("342", 200),
47 ],
48)
49def test_allow_inf_nan_param_false(value: str, code: int): 1abcdef
50 response = client.post(f"/?y={value}") 1imquyC
51 assert response.status_code == code, response.text 1imquyC
54@pytest.mark.parametrize( 1abcdef
55 "value,code",
56 [
57 ("-1", 200),
58 ("inf", 200),
59 ("-inf", 200),
60 ("nan", 200),
61 ("0", 200),
62 ("342", 200),
63 ],
64)
65def test_allow_inf_nan_param_default(value: str, code: int): 1abcdef
66 response = client.post(f"/?z={value}") 1hlptxB
67 assert response.status_code == code, response.text 1hlptxB
70@pytest.mark.parametrize( 1abcdef
71 "value,code",
72 [
73 ("-1", 200),
74 ("inf", 422),
75 ("-inf", 422),
76 ("nan", 422),
77 ("0", 200),
78 ("342", 200),
79 ],
80)
81def test_allow_inf_nan_body(value: str, code: int): 1abcdef
82 response = client.post("/", json=value) 1gkoswA
83 assert response.status_code == code, response.text 1gkoswA