Files
docs-fastapi/tests/test_allow_inf_nan_in_enforcing.py
T
The Scheduler a42b1ff04e
Issue Manager / issue-manager (push) Has been cancelled
Build Docs / changes (push) Has been cancelled
Build Docs / langs (push) Has been cancelled
Build Docs / build-docs (push) Has been cancelled
Build Docs / docs-all-green (push) Has been cancelled
Conflict detector / main (push) Has been cancelled
Test Redistribute / test-redistribute (fastapi) (push) Has been cancelled
Test Redistribute / test-redistribute (fastapi-slim) (push) Has been cancelled
Test Redistribute / test-redistribute-alls-green (push) Has been cancelled
Test / lint (push) Has been cancelled
Test / test (pydantic-v1, 3.10) (push) Has been cancelled
Test / test (pydantic-v1, 3.11) (push) Has been cancelled
Test / test (pydantic-v1, 3.13) (push) Has been cancelled
Test / test (pydantic-v1, 3.8) (push) Has been cancelled
Test / test (pydantic-v1, 3.9) (push) Has been cancelled
Test / test (pydantic-v2, 3.10) (push) Has been cancelled
Test / test (pydantic-v2, 3.11) (push) Has been cancelled
Test / test (pydantic-v2, 3.12) (push) Has been cancelled
Test / test (pydantic-v2, 3.13) (push) Has been cancelled
Test / test (pydantic-v2, 3.14) (push) Has been cancelled
Test / test (pydantic-v2, 3.8) (push) Has been cancelled
Test / test (pydantic-v2, 3.9) (push) Has been cancelled
Test / coverage-combine (push) Has been cancelled
Test / check (push) Has been cancelled
Label Approved / label-approved (push) Has been cancelled
FastAPI People Contributors / job (push) Has been cancelled
FastAPI People Sponsors / job (push) Has been cancelled
Update Topic Repos / topic-repos (push) Has been cancelled
FastAPI People / job (push) Has been cancelled
Test / test (pydantic-v1, 3.12) (push) Has been cancelled
Sync fastapi docs from b5ca1324 on 2025-12-07
2025-12-07 21:35:20 +00:00

84 lines
1.8 KiB
Python

import pytest
from fastapi import Body, FastAPI, Query
from fastapi.testclient import TestClient
from typing_extensions import Annotated
app = FastAPI()
@app.post("/")
async def get(
x: Annotated[float, Query(allow_inf_nan=True)] = 0,
y: Annotated[float, Query(allow_inf_nan=False)] = 0,
z: Annotated[float, Query()] = 0,
b: Annotated[float, Body(allow_inf_nan=False)] = 0,
) -> str:
return "OK"
client = TestClient(app)
@pytest.mark.parametrize(
"value,code",
[
("-1", 200),
("inf", 200),
("-inf", 200),
("nan", 200),
("0", 200),
("342", 200),
],
)
def test_allow_inf_nan_param_true(value: str, code: int):
response = client.post(f"/?x={value}")
assert response.status_code == code, response.text
@pytest.mark.parametrize(
"value,code",
[
("-1", 200),
("inf", 422),
("-inf", 422),
("nan", 422),
("0", 200),
("342", 200),
],
)
def test_allow_inf_nan_param_false(value: str, code: int):
response = client.post(f"/?y={value}")
assert response.status_code == code, response.text
@pytest.mark.parametrize(
"value,code",
[
("-1", 200),
("inf", 200),
("-inf", 200),
("nan", 200),
("0", 200),
("342", 200),
],
)
def test_allow_inf_nan_param_default(value: str, code: int):
response = client.post(f"/?z={value}")
assert response.status_code == code, response.text
@pytest.mark.parametrize(
"value,code",
[
("-1", 200),
("inf", 422),
("-inf", 422),
("nan", 422),
("0", 200),
("342", 200),
],
)
def test_allow_inf_nan_body(value: str, code: int):
response = client.post("/", json=value)
assert response.status_code == code, response.text