Coverage for tests/test_allow_inf_nan_in_enforcing.py: 100%
25 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
1import pytest 1abcdefg
2from fastapi import Body, FastAPI, Query 1abcdefg
3from fastapi.testclient import TestClient 1abcdefg
4from typing_extensions import Annotated 1abcdefg
6app = FastAPI() 1abcdefg
9@app.post("/") 1abcdefg
10async def get( 1abcdefg
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" 1hijklmnopqrstuvwxyzABCDEFGHI
19client = TestClient(app) 1abcdefg
22@pytest.mark.parametrize( 1abcdefg
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): 1abcdefg
34 response = client.post(f"/?x={value}") 1koswAEI
35 assert response.status_code == code, response.text 1koswAEI
38@pytest.mark.parametrize( 1abcdefg
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): 1abcdefg
50 response = client.post(f"/?y={value}") 1jnrvzDH
51 assert response.status_code == code, response.text 1jnrvzDH
54@pytest.mark.parametrize( 1abcdefg
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): 1abcdefg
66 response = client.post(f"/?z={value}") 1imquyCG
67 assert response.status_code == code, response.text 1imquyCG
70@pytest.mark.parametrize( 1abcdefg
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): 1abcdefg
82 response = client.post("/", json=value) 1hlptxBF
83 assert response.status_code == code, response.text 1hlptxBF