mirror of https://github.com/tiangolo/fastapi.git
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
This commit is contained in:
parent
c434bea96a
commit
f1f4c77fea
|
|
@ -6,53 +6,56 @@ from fastapi.testclient import TestClient
|
|||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/")
|
||||
def get(
|
||||
x: Optional[float] = Query(default=0, allow_inf_nan=False),
|
||||
y: Optional[float] = Query(default=0, allow_inf_nan=True),
|
||||
z: Optional[float] = Query(default=0)) -> str: # type: ignore
|
||||
return 'OK'
|
||||
x: Optional[float] = Query(default=0, allow_inf_nan=False),
|
||||
y: Optional[float] = Query(default=0, allow_inf_nan=True),
|
||||
z: Optional[float] = Query(default=0),
|
||||
) -> str: # type: ignore
|
||||
return "OK"
|
||||
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test_allow_inf_nan_false():
|
||||
response = client.get('/?x=inf')
|
||||
assert response.status_code == 422, response.text
|
||||
|
||||
response = client.get('/?x=-inf')
|
||||
assert response.status_code == 422, response.text
|
||||
|
||||
response = client.get('/?x=nan')
|
||||
response = client.get("/?x=inf")
|
||||
assert response.status_code == 422, response.text
|
||||
|
||||
response = client.get('/?x=0')
|
||||
response = client.get("/?x=-inf")
|
||||
assert response.status_code == 422, response.text
|
||||
|
||||
response = client.get("/?x=nan")
|
||||
assert response.status_code == 422, response.text
|
||||
|
||||
response = client.get("/?x=0")
|
||||
assert response.status_code == 200, response.text
|
||||
|
||||
|
||||
def test_allow_inf_nan_true():
|
||||
response = client.get('/?y=inf')
|
||||
assert response.status_code == 200, response.text
|
||||
|
||||
response = client.get('/?y=-inf')
|
||||
assert response.status_code == 200, response.text
|
||||
|
||||
response = client.get('/?y=nan')
|
||||
response = client.get("/?y=inf")
|
||||
assert response.status_code == 200, response.text
|
||||
|
||||
response = client.get('/?y=0')
|
||||
response = client.get("/?y=-inf")
|
||||
assert response.status_code == 200, response.text
|
||||
|
||||
response = client.get("/?y=nan")
|
||||
assert response.status_code == 200, response.text
|
||||
|
||||
response = client.get("/?y=0")
|
||||
assert response.status_code == 200, response.text
|
||||
|
||||
|
||||
def test_allow_inf_nan_not_specified():
|
||||
response = client.get('/?z=inf')
|
||||
assert response.status_code == 200, response.text
|
||||
|
||||
response = client.get('/?z=-inf')
|
||||
assert response.status_code == 200, response.text
|
||||
|
||||
response = client.get('/?z=nan')
|
||||
response = client.get("/?z=inf")
|
||||
assert response.status_code == 200, response.text
|
||||
|
||||
response = client.get('/?z=0')
|
||||
response = client.get("/?z=-inf")
|
||||
assert response.status_code == 200, response.text
|
||||
|
||||
response = client.get("/?z=nan")
|
||||
assert response.status_code == 200, response.text
|
||||
|
||||
response = client.get("/?z=0")
|
||||
assert response.status_code == 200, response.text
|
||||
|
|
|
|||
Loading…
Reference in New Issue