mirror of https://github.com/tiangolo/fastapi.git
Remove `xfail`, `pragma: no cover` and comments on failing tests
This commit is contained in:
parent
756317f302
commit
a2b0be2937
|
|
@ -3,7 +3,6 @@ from typing import List, Union
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import IsDict, IsOneOf, IsPartialDict
|
from dirty_equals import IsDict, IsOneOf, IsPartialDict
|
||||||
from fastapi import Body, FastAPI
|
from fastapi import Body, FastAPI
|
||||||
from fastapi._compat import PYDANTIC_V2
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
@ -115,21 +114,13 @@ class BodyModelRequiredListAlias(BaseModel):
|
||||||
|
|
||||||
@app.post("/model-required-list-alias", operation_id="model_required_list_alias")
|
@app.post("/model-required-list-alias", operation_id="model_required_list_alias")
|
||||||
async def read_model_required_list_alias(p: BodyModelRequiredListAlias):
|
async def read_model_required_list_alias(p: BodyModelRequiredListAlias):
|
||||||
return {"p": p.p} # pragma: no cover
|
return {"p": p.p}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-list-alias",
|
||||||
"/required-list-alias",
|
|
||||||
marks=pytest.mark.xfail(
|
|
||||||
raises=AssertionError,
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2 models",
|
|
||||||
strict=False,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
"/model-required-list-alias",
|
"/model-required-list-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -253,7 +244,7 @@ class BodyModelRequiredListValidationAlias(BaseModel):
|
||||||
async def read_model_required_list_validation_alias(
|
async def read_model_required_list_validation_alias(
|
||||||
p: BodyModelRequiredListValidationAlias,
|
p: BodyModelRequiredListValidationAlias,
|
||||||
):
|
):
|
||||||
return {"p": p.p} # pragma: no cover
|
return {"p": p.p}
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
|
|
@ -284,10 +275,7 @@ def test_required_list_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-list-validation-alias",
|
||||||
"/required-list-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-list-validation-alias",
|
"/model-required-list-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -299,9 +287,7 @@ def test_required_list_validation_alias_missing(path: str, json: Union[dict, Non
|
||||||
"detail": [
|
"detail": [
|
||||||
{
|
{
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": IsOneOf( # /required-validation-alias fails here
|
"loc": IsOneOf(["body"], ["body", "p_val_alias"]),
|
||||||
["body"], ["body", "p_val_alias"]
|
|
||||||
),
|
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(None, {}),
|
"input": IsOneOf(None, {}),
|
||||||
}
|
}
|
||||||
|
|
@ -313,19 +299,14 @@ def test_required_list_validation_alias_missing(path: str, json: Union[dict, Non
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-list-validation-alias",
|
||||||
"/required-list-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-list-validation-alias",
|
"/model-required-list-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_list_validation_alias_by_name(path: str):
|
def test_required_list_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, json={"p": ["hello", "world"]})
|
response = client.post(path, json={"p": ["hello", "world"]})
|
||||||
assert response.status_code == 422, (
|
assert response.status_code == 422, response.text
|
||||||
response.text # /required-list-validation-alias fails here
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
|
|
@ -343,19 +324,14 @@ def test_required_list_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-list-validation-alias",
|
||||||
"/required-list-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-list-validation-alias",
|
"/model-required-list-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_list_validation_alias_by_validation_alias(path: str):
|
def test_required_list_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, json={"p_val_alias": ["hello", "world"]})
|
response = client.post(path, json={"p_val_alias": ["hello", "world"]})
|
||||||
assert response.status_code == 200, (
|
assert response.status_code == 200, response.text
|
||||||
response.text # /required-list-validation-alias fails here
|
|
||||||
)
|
|
||||||
assert response.json() == {"p": ["hello", "world"]}
|
assert response.json() == {"p": ["hello", "world"]}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -386,7 +362,7 @@ class BodyModelRequiredListAliasAndValidationAlias(BaseModel):
|
||||||
def read_model_required_list_alias_and_validation_alias(
|
def read_model_required_list_alias_and_validation_alias(
|
||||||
p: BodyModelRequiredListAliasAndValidationAlias,
|
p: BodyModelRequiredListAliasAndValidationAlias,
|
||||||
):
|
):
|
||||||
return {"p": p.p} # pragma: no cover
|
return {"p": p.p}
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
|
|
@ -420,10 +396,7 @@ def test_required_list_alias_and_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-list-alias-and-validation-alias",
|
||||||
"/required-list-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-list-alias-and-validation-alias",
|
"/model-required-list-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -435,9 +408,7 @@ def test_required_list_alias_and_validation_alias_missing(path: str, json):
|
||||||
"detail": [
|
"detail": [
|
||||||
{
|
{
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": IsOneOf( # /required-list-alias-and-validation-alias fails here
|
"loc": IsOneOf(["body"], ["body", "p_val_alias"]),
|
||||||
["body"], ["body", "p_val_alias"]
|
|
||||||
),
|
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(None, {}),
|
"input": IsOneOf(None, {}),
|
||||||
}
|
}
|
||||||
|
|
@ -449,10 +420,7 @@ def test_required_list_alias_and_validation_alias_missing(path: str, json):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-list-alias-and-validation-alias",
|
||||||
"/required-list-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-list-alias-and-validation-alias",
|
"/model-required-list-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -464,7 +432,7 @@ def test_required_list_alias_and_validation_alias_by_name(path: str):
|
||||||
"detail": [
|
"detail": [
|
||||||
{
|
{
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [ # /required-list-alias-and-validation-alias fails here
|
"loc": [
|
||||||
"body",
|
"body",
|
||||||
"p_val_alias",
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
|
|
@ -479,10 +447,7 @@ def test_required_list_alias_and_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-list-alias-and-validation-alias",
|
||||||
"/required-list-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-list-alias-and-validation-alias",
|
"/model-required-list-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -507,17 +472,12 @@ def test_required_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-list-alias-and-validation-alias",
|
||||||
"/required-list-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-list-alias-and-validation-alias",
|
"/model-required-list-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_list_alias_and_validation_alias_by_validation_alias(path: str):
|
def test_required_list_alias_and_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, json={"p_val_alias": ["hello", "world"]})
|
response = client.post(path, json={"p_val_alias": ["hello", "world"]})
|
||||||
assert response.status_code == 200, (
|
assert response.status_code == 200, response.text
|
||||||
response.text # /required-list-alias-and-validation-alias fails here
|
|
||||||
)
|
|
||||||
assert response.json() == {"p": ["hello", "world"]}
|
assert response.json() == {"p": ["hello", "world"]}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ from typing import List, Optional
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import IsDict
|
from dirty_equals import IsDict
|
||||||
from fastapi import Body, FastAPI
|
from fastapi import Body, FastAPI
|
||||||
from fastapi._compat import PYDANTIC_V2
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
@ -149,15 +148,7 @@ async def read_model_optional_list_alias(p: BodyModelOptionalListAlias):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-list-alias",
|
||||||
"/optional-list-alias",
|
|
||||||
marks=pytest.mark.xfail(
|
|
||||||
raises=AssertionError,
|
|
||||||
strict=False,
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
"/model-optional-list-alias",
|
"/model-optional-list-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -383,10 +374,7 @@ def test_optional_list_validation_alias_missing_empty_dict(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-list-validation-alias",
|
||||||
"/optional-list-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-list-validation-alias",
|
"/model-optional-list-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -394,17 +382,14 @@ def test_optional_list_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, json={"p": ["hello", "world"]})
|
response = client.post(path, json={"p": ["hello", "world"]})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"p": None} # /optional-list-validation-alias fails here
|
assert response.json() == {"p": None}
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-list-validation-alias",
|
||||||
"/optional-list-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-list-validation-alias",
|
"/model-optional-list-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -412,9 +397,7 @@ def test_optional_list_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, json={"p_val_alias": ["hello", "world"]})
|
response = client.post(path, json={"p_val_alias": ["hello", "world"]})
|
||||||
assert response.status_code == 200, response.text
|
assert response.status_code == 200, response.text
|
||||||
assert response.json() == { # /optional-list-validation-alias fails here
|
assert response.json() == {"p": ["hello", "world"]}
|
||||||
"p": ["hello", "world"]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -561,10 +544,7 @@ def test_optional_list_alias_and_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-list-alias-and-validation-alias",
|
||||||
"/optional-list-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-list-alias-and-validation-alias",
|
"/model-optional-list-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -572,19 +552,14 @@ def test_optional_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, json={"p_alias": ["hello", "world"]})
|
response = client.post(path, json={"p_alias": ["hello", "world"]})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {
|
assert response.json() == {"p": None}
|
||||||
"p": None # /optional-list-alias-and-validation-alias fails here
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-list-alias-and-validation-alias",
|
||||||
"/optional-list-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-list-alias-and-validation-alias",
|
"/model-optional-list-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -593,7 +568,7 @@ def test_optional_list_alias_and_validation_alias_by_validation_alias(path: str)
|
||||||
response = client.post(path, json={"p_val_alias": ["hello", "world"]})
|
response = client.post(path, json={"p_val_alias": ["hello", "world"]})
|
||||||
assert response.status_code == 200, response.text
|
assert response.status_code == 200, response.text
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"p": [ # /optional-list-alias-and-validation-alias fails here
|
"p": [
|
||||||
"hello",
|
"hello",
|
||||||
"world",
|
"world",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ from typing import Optional
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import IsDict
|
from dirty_equals import IsDict
|
||||||
from fastapi import Body, FastAPI
|
from fastapi import Body, FastAPI
|
||||||
from fastapi._compat import PYDANTIC_V2
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
@ -144,15 +143,7 @@ async def read_model_optional_alias(p: BodyModelOptionalAlias):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-alias",
|
||||||
"/optional-alias",
|
|
||||||
marks=pytest.mark.xfail(
|
|
||||||
raises=AssertionError,
|
|
||||||
strict=False,
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
"/model-optional-alias",
|
"/model-optional-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -364,10 +355,7 @@ def test_model_optional_validation_alias_missing_empty_dict(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-validation-alias",
|
||||||
"/optional-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-validation-alias",
|
"/model-optional-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -375,17 +363,14 @@ def test_optional_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, json={"p": "hello"})
|
response = client.post(path, json={"p": "hello"})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"p": None} # /optional-validation-alias fails here
|
assert response.json() == {"p": None}
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-validation-alias",
|
||||||
"/optional-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-validation-alias",
|
"/model-optional-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -393,7 +378,7 @@ def test_optional_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, json={"p_val_alias": "hello"})
|
response = client.post(path, json={"p_val_alias": "hello"})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"p": "hello"} # /optional-validation-alias fails here
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -533,10 +518,7 @@ def test_optional_alias_and_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-alias-and-validation-alias",
|
||||||
"/optional-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-alias-and-validation-alias",
|
"/model-optional-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -544,19 +526,14 @@ def test_optional_alias_and_validation_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, json={"p_alias": "hello"})
|
response = client.post(path, json={"p_alias": "hello"})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {
|
assert response.json() == {"p": None}
|
||||||
"p": None # /optional-alias-and-validation-alias fails here
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-alias-and-validation-alias",
|
||||||
"/optional-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-alias-and-validation-alias",
|
"/model-optional-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -564,6 +541,4 @@ def test_optional_alias_and_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, json={"p_val_alias": "hello"})
|
response = client.post(path, json={"p_val_alias": "hello"})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {
|
assert response.json() == {"p": "hello"}
|
||||||
"p": "hello" # /optional-alias-and-validation-alias fails here
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ from typing import Any, Dict, Union
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import IsDict, IsOneOf
|
from dirty_equals import IsDict, IsOneOf
|
||||||
from fastapi import Body, FastAPI
|
from fastapi import Body, FastAPI
|
||||||
from fastapi._compat import PYDANTIC_V2
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
@ -118,15 +117,7 @@ async def read_model_required_alias(p: BodyModelRequiredAlias):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-alias",
|
||||||
"/required-alias",
|
|
||||||
marks=pytest.mark.xfail(
|
|
||||||
raises=AssertionError,
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2",
|
|
||||||
strict=False,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
"/model-required-alias",
|
"/model-required-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -270,10 +261,7 @@ def test_required_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-validation-alias",
|
||||||
"/required-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-validation-alias",
|
"/model-required-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -287,9 +275,7 @@ def test_required_validation_alias_missing(
|
||||||
"detail": [
|
"detail": [
|
||||||
{
|
{
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": IsOneOf( # /required-validation-alias fails here
|
"loc": IsOneOf(["body", "p_val_alias"], ["body"]),
|
||||||
["body", "p_val_alias"], ["body"]
|
|
||||||
),
|
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(None, {}),
|
"input": IsOneOf(None, {}),
|
||||||
}
|
}
|
||||||
|
|
@ -301,19 +287,14 @@ def test_required_validation_alias_missing(
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-validation-alias",
|
||||||
"/required-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-validation-alias",
|
"/model-required-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_validation_alias_by_name(path: str):
|
def test_required_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, json={"p": "hello"})
|
response = client.post(path, json={"p": "hello"})
|
||||||
assert response.status_code == 422, ( # /required-validation-alias fails here
|
assert response.status_code == 422, response.text
|
||||||
response.text
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
|
|
@ -331,19 +312,14 @@ def test_required_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-validation-alias",
|
||||||
"/required-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-validation-alias",
|
"/model-required-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_validation_alias_by_validation_alias(path: str):
|
def test_required_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, json={"p_val_alias": "hello"})
|
response = client.post(path, json={"p_val_alias": "hello"})
|
||||||
assert response.status_code == 200, ( # /required-validation-alias fails here
|
assert response.status_code == 200, response.text
|
||||||
response.text
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {"p": "hello"}
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
||||||
|
|
@ -405,10 +381,7 @@ def test_required_alias_and_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-alias-and-validation-alias",
|
||||||
"/required-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-alias-and-validation-alias",
|
"/model-required-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -422,9 +395,7 @@ def test_required_alias_and_validation_alias_missing(
|
||||||
"detail": [
|
"detail": [
|
||||||
{
|
{
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": IsOneOf( # /required-alias-and-validation-alias fails here
|
"loc": IsOneOf(["body"], ["body", "p_val_alias"]),
|
||||||
["body"], ["body", "p_val_alias"]
|
|
||||||
),
|
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(None, {}),
|
"input": IsOneOf(None, {}),
|
||||||
}
|
}
|
||||||
|
|
@ -436,10 +407,7 @@ def test_required_alias_and_validation_alias_missing(
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-alias-and-validation-alias",
|
||||||
"/required-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-alias-and-validation-alias",
|
"/model-required-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -454,7 +422,7 @@ def test_required_alias_and_validation_alias_by_name(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"body",
|
"body",
|
||||||
"p_val_alias", # /required-alias-and-validation-alias fails here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(None, {"p": "hello"}),
|
"input": IsOneOf(None, {"p": "hello"}),
|
||||||
|
|
@ -467,19 +435,14 @@ def test_required_alias_and_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-alias-and-validation-alias",
|
||||||
"/required-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-alias-and-validation-alias",
|
"/model-required-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_alias_and_validation_alias_by_alias(path: str):
|
def test_required_alias_and_validation_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, json={"p_alias": "hello"})
|
response = client.post(path, json={"p_alias": "hello"})
|
||||||
assert response.status_code == 422, (
|
assert response.status_code == 422, response.text
|
||||||
response.text # /required-alias-and-validation-alias fails here
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
|
|
@ -497,18 +460,13 @@ def test_required_alias_and_validation_alias_by_alias(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-alias-and-validation-alias",
|
||||||
"/required-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-alias-and-validation-alias",
|
"/model-required-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_alias_and_validation_alias_by_validation_alias(path: str):
|
def test_required_alias_and_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, json={"p_val_alias": "hello"})
|
response = client.post(path, json={"p_val_alias": "hello"})
|
||||||
assert response.status_code == 200, (
|
assert response.status_code == 200, response.text
|
||||||
response.text # /required-alias-and-validation-alias fails here
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {"p": "hello"}
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
|
||||||
|
|
@ -157,10 +157,7 @@ def test_optional_alias_by_name(path: str):
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
"/optional-alias",
|
"/optional-alias",
|
||||||
pytest.param(
|
"/model-optional-alias",
|
||||||
"/model-optional-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_optional_alias_by_alias(path: str):
|
def test_optional_alias_by_alias(path: str):
|
||||||
|
|
@ -168,7 +165,7 @@ def test_optional_alias_by_alias(path: str):
|
||||||
client.cookies.set("p_alias", "hello")
|
client.cookies.set("p_alias", "hello")
|
||||||
response = client.get(path)
|
response = client.get(path)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"p": "hello"} # /model-optional-alias fails here
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -194,7 +191,6 @@ def read_model_optional_validation_alias(
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
["/optional-validation-alias", "/model-optional-validation-alias"],
|
["/optional-validation-alias", "/model-optional-validation-alias"],
|
||||||
|
|
@ -229,10 +225,7 @@ def test_optional_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-validation-alias",
|
||||||
"/optional-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-validation-alias",
|
"/model-optional-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -248,10 +241,7 @@ def test_optional_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-validation-alias",
|
||||||
"/optional-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-validation-alias",
|
"/model-optional-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -260,7 +250,7 @@ def test_optional_validation_alias_by_validation_alias(path: str):
|
||||||
client.cookies.set("p_val_alias", "hello")
|
client.cookies.set("p_val_alias", "hello")
|
||||||
response = client.get(path)
|
response = client.get(path)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"p": "hello"} # /optional-validation-alias fails here
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -288,7 +278,6 @@ def read_model_optional_alias_and_validation_alias(
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -345,10 +334,7 @@ def test_optional_alias_and_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-alias-and-validation-alias",
|
||||||
"/optional-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-alias-and-validation-alias",
|
"/model-optional-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -357,19 +343,14 @@ def test_optional_alias_and_validation_alias_by_alias(path: str):
|
||||||
client.cookies.set("p_alias", "hello")
|
client.cookies.set("p_alias", "hello")
|
||||||
response = client.get(path)
|
response = client.get(path)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {
|
assert response.json() == {"p": None}
|
||||||
"p": None # /optional-alias-and-validation-alias fails here
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-alias-and-validation-alias",
|
||||||
"/optional-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-alias-and-validation-alias",
|
"/model-optional-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -378,6 +359,4 @@ def test_optional_alias_and_validation_alias_by_validation_alias(path: str):
|
||||||
client.cookies.set("p_val_alias", "hello")
|
client.cookies.set("p_val_alias", "hello")
|
||||||
response = client.get(path)
|
response = client.get(path)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {
|
assert response.json() == {"p": "hello"}
|
||||||
"p": "hello" # /optional-alias-and-validation-alias fails here
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import IsDict, IsOneOf
|
from dirty_equals import IsDict, IsOneOf
|
||||||
from fastapi import Cookie, FastAPI
|
from fastapi import Cookie, FastAPI
|
||||||
from fastapi._compat import PYDANTIC_V2
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
@ -103,7 +102,7 @@ class CookieModelRequiredAlias(BaseModel):
|
||||||
|
|
||||||
@app.get("/model-required-alias")
|
@app.get("/model-required-alias")
|
||||||
async def read_model_required_alias(p: Annotated[CookieModelRequiredAlias, Cookie()]):
|
async def read_model_required_alias(p: Annotated[CookieModelRequiredAlias, Cookie()]):
|
||||||
return {"p": p.p} # pragma: no cover
|
return {"p": p.p}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
@ -158,15 +157,7 @@ def test_required_alias_missing(path: str):
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
"/required-alias",
|
"/required-alias",
|
||||||
pytest.param(
|
"/model-required-alias",
|
||||||
"/model-required-alias",
|
|
||||||
marks=pytest.mark.xfail(
|
|
||||||
raises=AssertionError,
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2 models",
|
|
||||||
strict=False,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_alias_by_name(path: str):
|
def test_required_alias_by_name(path: str):
|
||||||
|
|
@ -183,7 +174,7 @@ def test_required_alias_by_name(path: str):
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(
|
"input": IsOneOf(
|
||||||
None,
|
None,
|
||||||
{"p": "hello"}, # /model-required-alias PDv2 fails here
|
{"p": "hello"},
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -206,19 +197,14 @@ def test_required_alias_by_name(path: str):
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
"/required-alias",
|
"/required-alias",
|
||||||
pytest.param(
|
"/model-required-alias",
|
||||||
"/model-required-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_alias_by_alias(path: str):
|
def test_required_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
client.cookies.set("p_alias", "hello")
|
client.cookies.set("p_alias", "hello")
|
||||||
response = client.get(path)
|
response = client.get(path)
|
||||||
assert response.status_code == 200, ( # /model-required-alias fails here
|
assert response.status_code == 200, response.text
|
||||||
response.text
|
|
||||||
)
|
|
||||||
assert response.json() == {"p": "hello"}
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -245,7 +231,6 @@ def read_model_required_validation_alias(
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
["/required-validation-alias", "/model-required-validation-alias"],
|
["/required-validation-alias", "/model-required-validation-alias"],
|
||||||
|
|
@ -265,10 +250,7 @@ def test_required_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-validation-alias",
|
||||||
"/required-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-validation-alias",
|
"/model-required-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -282,7 +264,7 @@ def test_required_validation_alias_missing(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"cookie",
|
"cookie",
|
||||||
"p_val_alias", # /required-validation-alias fails here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(None, {}),
|
"input": IsOneOf(None, {}),
|
||||||
|
|
@ -295,10 +277,7 @@ def test_required_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-validation-alias",
|
||||||
"/required-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-validation-alias",
|
"/model-required-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -306,9 +285,7 @@ def test_required_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
client.cookies.set("p", "hello")
|
client.cookies.set("p", "hello")
|
||||||
response = client.get(path)
|
response = client.get(path)
|
||||||
assert response.status_code == 422, ( # /required-validation-alias fails here
|
assert response.status_code == 422, response.text
|
||||||
response.text
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
|
|
@ -326,10 +303,7 @@ def test_required_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-validation-alias",
|
||||||
"/required-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-validation-alias",
|
"/model-required-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -337,9 +311,7 @@ def test_required_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
client.cookies.set("p_val_alias", "hello")
|
client.cookies.set("p_val_alias", "hello")
|
||||||
response = client.get(path)
|
response = client.get(path)
|
||||||
assert response.status_code == 200, ( # /required-validation-alias fails here
|
assert response.status_code == 200, response.text
|
||||||
response.text
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {"p": "hello"}
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
||||||
|
|
@ -367,7 +339,6 @@ def read_model_required_alias_and_validation_alias(
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -390,10 +361,7 @@ def test_required_alias_and_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-alias-and-validation-alias",
|
||||||
"/required-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-alias-and-validation-alias",
|
"/model-required-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -407,7 +375,7 @@ def test_required_alias_and_validation_alias_missing(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"cookie",
|
"cookie",
|
||||||
"p_val_alias", # /required-alias-and-validation-alias fails here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(None, {}),
|
"input": IsOneOf(None, {}),
|
||||||
|
|
@ -417,7 +385,6 @@ def test_required_alias_and_validation_alias_missing(path: str):
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -437,10 +404,10 @@ def test_required_alias_and_validation_alias_by_name(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"cookie",
|
"cookie",
|
||||||
"p_val_alias", # /required-alias-and-validation-alias fails here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf( # /model-alias-and-validation-alias fails here
|
"input": IsOneOf(
|
||||||
None,
|
None,
|
||||||
{"p": "hello"},
|
{"p": "hello"},
|
||||||
),
|
),
|
||||||
|
|
@ -450,7 +417,6 @@ def test_required_alias_and_validation_alias_by_name(path: str):
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -462,9 +428,7 @@ def test_required_alias_and_validation_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
client.cookies.set("p_alias", "hello")
|
client.cookies.set("p_alias", "hello")
|
||||||
response = client.get(path)
|
response = client.get(path)
|
||||||
assert (
|
assert response.status_code == 422
|
||||||
response.status_code == 422 # /required-alias-and-validation-alias fails here
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
|
|
@ -472,7 +436,7 @@ def test_required_alias_and_validation_alias_by_alias(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": ["cookie", "p_val_alias"],
|
"loc": ["cookie", "p_val_alias"],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf( # /model-alias-and-validation-alias fails here
|
"input": IsOneOf(
|
||||||
None,
|
None,
|
||||||
{"p_alias": "hello"},
|
{"p_alias": "hello"},
|
||||||
),
|
),
|
||||||
|
|
@ -485,10 +449,7 @@ def test_required_alias_and_validation_alias_by_alias(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-alias-and-validation-alias",
|
||||||
"/required-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-alias-and-validation-alias",
|
"/model-required-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -496,8 +457,6 @@ def test_required_alias_and_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
client.cookies.set("p_val_alias", "hello")
|
client.cookies.set("p_val_alias", "hello")
|
||||||
response = client.get(path)
|
response = client.get(path)
|
||||||
assert response.status_code == 200, (
|
assert response.status_code == 200, response.text
|
||||||
response.text # /required-alias-and-validation-alias fails here
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {"p": "hello"}
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ from typing import List
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import IsDict
|
from dirty_equals import IsDict
|
||||||
from fastapi import FastAPI, File, UploadFile
|
from fastapi import FastAPI, File, UploadFile
|
||||||
from fastapi._compat import PYDANTIC_V2
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
||||||
|
|
@ -134,12 +133,6 @@ async def read_list_uploadfile_alias(
|
||||||
return {"file_size": [file.size for file in p]}
|
return {"file_size": [file.size for file in p]}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(
|
|
||||||
raises=AssertionError,
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2",
|
|
||||||
strict=False,
|
|
||||||
)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -334,14 +327,8 @@ def test_list_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/list-bytes-validation-alias",
|
||||||
"/list-bytes-validation-alias",
|
"/list-uploadfile-validation-alias",
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
pytest.param(
|
|
||||||
"/list-uploadfile-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_list_validation_alias_missing(path: str):
|
def test_list_validation_alias_missing(path: str):
|
||||||
|
|
@ -352,7 +339,7 @@ def test_list_validation_alias_missing(path: str):
|
||||||
"detail": [
|
"detail": [
|
||||||
{
|
{
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [ # /list-*-validation-alias fail here
|
"loc": [
|
||||||
"body",
|
"body",
|
||||||
"p_val_alias",
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
|
|
@ -367,24 +354,16 @@ def test_list_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/list-bytes-validation-alias",
|
||||||
"/list-bytes-validation-alias",
|
"/list-uploadfile-validation-alias",
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
pytest.param(
|
|
||||||
"/list-uploadfile-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_list_validation_alias_by_name(path: str):
|
def test_list_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, files=[("p", b"hello"), ("p", b"world")])
|
response = client.post(path, files=[("p", b"hello"), ("p", b"world")])
|
||||||
assert response.status_code == 422, ( # /list-*-validation-alias fail here
|
assert response.status_code == 422, response.text
|
||||||
response.text
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == { # pragma: no cover
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
{
|
{
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
|
|
@ -396,7 +375,6 @@ def test_list_validation_alias_by_name(path: str):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
|
|
@ -410,8 +388,8 @@ def test_list_validation_alias_by_validation_alias(path: str):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
path, files=[("p_val_alias", b"hello"), ("p_val_alias", b"world")]
|
path, files=[("p_val_alias", b"hello"), ("p_val_alias", b"world")]
|
||||||
)
|
)
|
||||||
assert response.status_code == 200, response.text # all 2 fail here
|
assert response.status_code == 200, response.text
|
||||||
assert response.json() == {"file_size": [5, 5]} # pragma: no cover
|
assert response.json() == {"file_size": [5, 5]}
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -486,14 +464,8 @@ def test_list_alias_and_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/list-bytes-alias-and-validation-alias",
|
||||||
"/list-bytes-alias-and-validation-alias",
|
"/list-uploadfile-alias-and-validation-alias",
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
pytest.param(
|
|
||||||
"/list-uploadfile-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_list_alias_and_validation_alias_missing(path: str):
|
def test_list_alias_and_validation_alias_missing(path: str):
|
||||||
|
|
@ -506,7 +478,7 @@ def test_list_alias_and_validation_alias_missing(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"body",
|
"body",
|
||||||
"p_val_alias", # /list-*-alias-and-validation-alias fail here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": None,
|
"input": None,
|
||||||
|
|
@ -515,7 +487,6 @@ def test_list_alias_and_validation_alias_missing(path: str):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
|
|
@ -535,7 +506,7 @@ def test_list_alias_and_validation_alias_by_name(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"body",
|
"body",
|
||||||
"p_val_alias", # /list-*-alias-and-validation-alias fail here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": None,
|
"input": None,
|
||||||
|
|
@ -548,24 +519,16 @@ def test_list_alias_and_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/list-bytes-alias-and-validation-alias",
|
||||||
"/list-bytes-alias-and-validation-alias",
|
"/list-uploadfile-alias-and-validation-alias",
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
pytest.param(
|
|
||||||
"/list-uploadfile-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_list_alias_and_validation_alias_by_alias(path: str):
|
def test_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, files=[("p_alias", b"hello"), ("p_alias", b"world")])
|
response = client.post(path, files=[("p_alias", b"hello"), ("p_alias", b"world")])
|
||||||
assert response.status_code == 422, (
|
assert response.status_code == 422, response.text
|
||||||
response.text # /list-*-alias-and-validation-alias fails here
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == { # pragma: no cover
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
{
|
{
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
|
|
@ -577,7 +540,6 @@ def test_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
|
|
@ -591,7 +553,5 @@ def test_list_alias_and_validation_alias_by_validation_alias(path: str):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
path, files=[("p_val_alias", b"hello"), ("p_val_alias", b"world")]
|
path, files=[("p_val_alias", b"hello"), ("p_val_alias", b"world")]
|
||||||
)
|
)
|
||||||
assert response.status_code == 200, ( # all 2 fail here
|
assert response.status_code == 200, response.text
|
||||||
response.text
|
assert response.json() == {"file_size": [5, 5]}
|
||||||
)
|
|
||||||
assert response.json() == {"file_size": [5, 5]} # pragma: no cover
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ from typing import Optional
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import IsDict
|
from dirty_equals import IsDict
|
||||||
from fastapi import FastAPI, File, UploadFile
|
from fastapi import FastAPI, File, UploadFile
|
||||||
from fastapi._compat import PYDANTIC_V2
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
||||||
|
|
@ -107,12 +106,6 @@ async def read_optional_uploadfile_alias(
|
||||||
return {"file_size": p.size if p else None}
|
return {"file_size": p.size if p else None}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(
|
|
||||||
raises=AssertionError,
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2",
|
|
||||||
strict=False,
|
|
||||||
)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -266,44 +259,30 @@ def test_optional_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-bytes-validation-alias",
|
||||||
"/optional-bytes-validation-alias",
|
"/optional-uploadfile-validation-alias",
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
pytest.param(
|
|
||||||
"/optional-uploadfile-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_optional_validation_alias_by_name(path: str):
|
def test_optional_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, files=[("p", b"hello")])
|
response = client.post(path, files=[("p", b"hello")])
|
||||||
assert response.status_code == 200, response.text
|
assert response.status_code == 200, response.text
|
||||||
assert response.json() == { # /optional-*-validation-alias fail here
|
assert response.json() == {"file_size": None}
|
||||||
"file_size": None
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-bytes-validation-alias",
|
||||||
"/optional-bytes-validation-alias",
|
"/optional-uploadfile-validation-alias",
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
pytest.param(
|
|
||||||
"/optional-uploadfile-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_optional_validation_alias_by_validation_alias(path: str):
|
def test_optional_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, files=[("p_val_alias", b"hello")])
|
response = client.post(path, files=[("p_val_alias", b"hello")])
|
||||||
assert response.status_code == 200, response.text
|
assert response.status_code == 200, response.text
|
||||||
assert response.json() == {"file_size": 5} # /optional-*-validation-alias fail here
|
assert response.json() == {"file_size": 5}
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -403,14 +382,8 @@ def test_optional_alias_and_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-bytes-alias-and-validation-alias",
|
||||||
"/optional-bytes-alias-and-validation-alias",
|
"/optional-uploadfile-alias-and-validation-alias",
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
pytest.param(
|
|
||||||
"/optional-uploadfile-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_optional_alias_and_validation_alias_by_alias(path: str):
|
def test_optional_alias_and_validation_alias_by_alias(path: str):
|
||||||
|
|
@ -424,20 +397,12 @@ def test_optional_alias_and_validation_alias_by_alias(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-bytes-alias-and-validation-alias",
|
||||||
"/optional-bytes-alias-and-validation-alias",
|
"/optional-uploadfile-alias-and-validation-alias",
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
pytest.param(
|
|
||||||
"/optional-uploadfile-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_optional_alias_and_validation_alias_by_validation_alias(path: str):
|
def test_optional_alias_and_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, files=[("p_val_alias", b"hello")])
|
response = client.post(path, files=[("p_val_alias", b"hello")])
|
||||||
assert response.status_code == 200, response.text
|
assert response.status_code == 200, response.text
|
||||||
assert response.json() == {
|
assert response.json() == {"file_size": 5}
|
||||||
"file_size": 5
|
|
||||||
} # /optional-*-alias-and-validation-alias fail here
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ from typing import List, Optional
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import IsDict
|
from dirty_equals import IsDict
|
||||||
from fastapi import FastAPI, File, UploadFile
|
from fastapi import FastAPI, File, UploadFile
|
||||||
from fastapi._compat import PYDANTIC_V2
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
||||||
|
|
@ -87,15 +86,7 @@ def test_optional_list_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-list-bytes",
|
||||||
"/optional-list-bytes",
|
|
||||||
marks=pytest.mark.xfail(
|
|
||||||
raises=(TypeError, AssertionError),
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2 due to #14297",
|
|
||||||
strict=False,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
"/optional-list-uploadfile",
|
"/optional-list-uploadfile",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -124,12 +115,6 @@ async def read_optional_list_uploadfile_alias(
|
||||||
return {"file_size": [file.size for file in p] if p else None}
|
return {"file_size": [file.size for file in p] if p else None}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(
|
|
||||||
raises=AssertionError,
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2",
|
|
||||||
strict=False,
|
|
||||||
)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -202,15 +187,7 @@ def test_optional_list_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-list-bytes-alias",
|
||||||
"/optional-list-bytes-alias",
|
|
||||||
marks=pytest.mark.xfail(
|
|
||||||
raises=(TypeError, AssertionError),
|
|
||||||
strict=False,
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2 model due to #14297",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
"/optional-list-uploadfile-alias",
|
"/optional-list-uploadfile-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -302,30 +279,17 @@ def test_optional_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-list-bytes-validation-alias",
|
||||||
"/optional-list-bytes-validation-alias",
|
"/optional-list-uploadfile-validation-alias",
|
||||||
marks=pytest.mark.xfail(
|
|
||||||
raises=(TypeError, AssertionError),
|
|
||||||
strict=False,
|
|
||||||
reason="Fails due to #14297",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
pytest.param(
|
|
||||||
"/optional-list-uploadfile-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_optional_validation_alias_by_name(path: str):
|
def test_optional_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, files=[("p", b"hello"), ("p", b"world")])
|
response = client.post(path, files=[("p", b"hello"), ("p", b"world")])
|
||||||
assert response.status_code == 200, response.text
|
assert response.status_code == 200, response.text
|
||||||
assert response.json() == { # /optional-list-uploadfile-validation-alias fails here
|
assert response.json() == {"file_size": None}
|
||||||
"file_size": None
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
|
|
@ -340,9 +304,7 @@ def test_optional_validation_alias_by_validation_alias(path: str):
|
||||||
path, files=[("p_val_alias", b"hello"), ("p_val_alias", b"world")]
|
path, files=[("p_val_alias", b"hello"), ("p_val_alias", b"world")]
|
||||||
)
|
)
|
||||||
assert response.status_code == 200, response.text
|
assert response.status_code == 200, response.text
|
||||||
assert response.json() == {
|
assert response.json() == {"file_size": [5, 5]}
|
||||||
"file_size": [5, 5] # /optional-list-*-validation-alias fail here
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -444,30 +406,17 @@ def test_optional_list_alias_and_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-list-bytes-alias-and-validation-alias",
|
||||||
"/optional-list-bytes-alias-and-validation-alias",
|
"/optional-list-uploadfile-alias-and-validation-alias",
|
||||||
marks=pytest.mark.xfail(
|
|
||||||
raises=(TypeError, AssertionError),
|
|
||||||
strict=False,
|
|
||||||
reason="Fails due to #14297",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
pytest.param(
|
|
||||||
"/optional-list-uploadfile-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_optional_list_alias_and_validation_alias_by_alias(path: str):
|
def test_optional_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, files=[("p_alias", b"hello"), ("p_alias", b"world")])
|
response = client.post(path, files=[("p_alias", b"hello"), ("p_alias", b"world")])
|
||||||
assert response.status_code == 200, response.text
|
assert response.status_code == 200, response.text
|
||||||
assert ( # /optional-list-uploadfile-alias-and-validation-alias fails here
|
assert response.json() == {"file_size": None}
|
||||||
response.json() == {"file_size": None}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
|
|
@ -482,6 +431,4 @@ def test_optional_list_alias_and_validation_alias_by_validation_alias(path: str)
|
||||||
path, files=[("p_val_alias", b"hello"), ("p_val_alias", b"world")]
|
path, files=[("p_val_alias", b"hello"), ("p_val_alias", b"world")]
|
||||||
)
|
)
|
||||||
assert response.status_code == 200, response.text
|
assert response.status_code == 200, response.text
|
||||||
assert response.json() == {
|
assert response.json() == {"file_size": [5, 5]}
|
||||||
"file_size": [5, 5] # /optional-list-*-alias-and-validation-alias fail here
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import IsDict
|
from dirty_equals import IsDict
|
||||||
from fastapi import FastAPI, File, UploadFile
|
from fastapi import FastAPI, File, UploadFile
|
||||||
from fastapi._compat import PYDANTIC_V2
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
||||||
|
|
@ -112,12 +111,6 @@ async def read_required_uploadfile_alias(
|
||||||
return {"file_size": p.size}
|
return {"file_size": p.size}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(
|
|
||||||
raises=AssertionError,
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2",
|
|
||||||
strict=False,
|
|
||||||
)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -278,14 +271,8 @@ def test_required_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-bytes-validation-alias",
|
||||||
"/required-bytes-validation-alias",
|
"/required-uploadfile-validation-alias",
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
pytest.param(
|
|
||||||
"/required-uploadfile-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_validation_alias_missing(path: str):
|
def test_required_validation_alias_missing(path: str):
|
||||||
|
|
@ -296,7 +283,7 @@ def test_required_validation_alias_missing(path: str):
|
||||||
"detail": [
|
"detail": [
|
||||||
{
|
{
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [ # /required-*-validation-alias fail here
|
"loc": [
|
||||||
"body",
|
"body",
|
||||||
"p_val_alias",
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
|
|
@ -311,24 +298,16 @@ def test_required_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-bytes-validation-alias",
|
||||||
"/required-bytes-validation-alias",
|
"/required-uploadfile-validation-alias",
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
pytest.param(
|
|
||||||
"/required-uploadfile-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_validation_alias_by_name(path: str):
|
def test_required_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, files=[("p", b"hello")])
|
response = client.post(path, files=[("p", b"hello")])
|
||||||
assert response.status_code == 422, ( # /required-*-validation-alias fail here
|
assert response.status_code == 422, response.text
|
||||||
response.text
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == { # pragma: no cover
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
{
|
{
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
|
|
@ -344,23 +323,15 @@ def test_required_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-bytes-validation-alias",
|
||||||
"/required-bytes-validation-alias",
|
"/required-uploadfile-validation-alias",
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
pytest.param(
|
|
||||||
"/required-uploadfile-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_validation_alias_by_validation_alias(path: str):
|
def test_required_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, files=[("p_val_alias", b"hello")])
|
response = client.post(path, files=[("p_val_alias", b"hello")])
|
||||||
assert response.status_code == 200, ( # all 2 fail here
|
assert response.status_code == 200, response.text
|
||||||
response.text
|
assert response.json() == {"file_size": 5}
|
||||||
)
|
|
||||||
assert response.json() == {"file_size": 5} # pragma: no cover
|
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -417,14 +388,8 @@ def test_required_alias_and_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-bytes-alias-and-validation-alias",
|
||||||
"/required-bytes-alias-and-validation-alias",
|
"/required-uploadfile-alias-and-validation-alias",
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
pytest.param(
|
|
||||||
"/required-uploadfile-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_alias_and_validation_alias_missing(path: str):
|
def test_required_alias_and_validation_alias_missing(path: str):
|
||||||
|
|
@ -437,7 +402,7 @@ def test_required_alias_and_validation_alias_missing(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"body",
|
"body",
|
||||||
"p_val_alias", # /required-*-alias-and-validation-alias fail here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": None,
|
"input": None,
|
||||||
|
|
@ -450,14 +415,8 @@ def test_required_alias_and_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-bytes-alias-and-validation-alias",
|
||||||
"/required-bytes-alias-and-validation-alias",
|
"/required-uploadfile-alias-and-validation-alias",
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
pytest.param(
|
|
||||||
"/required-uploadfile-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_alias_and_validation_alias_by_name(path: str):
|
def test_required_alias_and_validation_alias_by_name(path: str):
|
||||||
|
|
@ -471,7 +430,7 @@ def test_required_alias_and_validation_alias_by_name(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"body",
|
"body",
|
||||||
"p_val_alias", # /required-*-alias-and-validation-alias fail here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": None,
|
"input": None,
|
||||||
|
|
@ -484,24 +443,16 @@ def test_required_alias_and_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-bytes-alias-and-validation-alias",
|
||||||
"/required-bytes-alias-and-validation-alias",
|
"/required-uploadfile-alias-and-validation-alias",
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
pytest.param(
|
|
||||||
"/required-uploadfile-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_alias_and_validation_alias_by_alias(path: str):
|
def test_required_alias_and_validation_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, files=[("p_alias", b"hello")])
|
response = client.post(path, files=[("p_alias", b"hello")])
|
||||||
assert response.status_code == 422, (
|
assert response.status_code == 422, response.text
|
||||||
response.text # /required-*-alias-and-validation-alias fails here
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == { # pragma: no cover
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
{
|
{
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
|
|
@ -517,20 +468,12 @@ def test_required_alias_and_validation_alias_by_alias(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-bytes-alias-and-validation-alias",
|
||||||
"/required-bytes-alias-and-validation-alias",
|
"/required-uploadfile-alias-and-validation-alias",
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
pytest.param(
|
|
||||||
"/required-uploadfile-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_alias_and_validation_alias_by_validation_alias(path: str):
|
def test_required_alias_and_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, files=[("p_val_alias", b"hello")])
|
response = client.post(path, files=[("p_val_alias", b"hello")])
|
||||||
assert response.status_code == 200, ( # all 2 fail here
|
assert response.status_code == 200, response.text
|
||||||
response.text
|
assert response.json() == {"file_size": 5}
|
||||||
)
|
|
||||||
assert response.json() == {"file_size": 5} # pragma: no cover
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ from typing import List
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import IsDict, IsOneOf, IsPartialDict
|
from dirty_equals import IsDict, IsOneOf, IsPartialDict
|
||||||
from fastapi import FastAPI, Form
|
from fastapi import FastAPI, Form
|
||||||
from fastapi._compat import PYDANTIC_V2
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
@ -114,21 +113,13 @@ class FormModelRequiredListAlias(BaseModel):
|
||||||
async def read_model_required_list_alias(
|
async def read_model_required_list_alias(
|
||||||
p: Annotated[FormModelRequiredListAlias, Form()],
|
p: Annotated[FormModelRequiredListAlias, Form()],
|
||||||
):
|
):
|
||||||
return {"p": p.p} # pragma: no cover
|
return {"p": p.p}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-list-alias",
|
||||||
"/required-list-alias",
|
|
||||||
marks=pytest.mark.xfail(
|
|
||||||
raises=AssertionError,
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2 models",
|
|
||||||
strict=False,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
"/model-required-list-alias",
|
"/model-required-list-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -187,15 +178,7 @@ def test_required_list_alias_missing(path: str):
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
"/required-list-alias",
|
"/required-list-alias",
|
||||||
pytest.param(
|
"/model-required-list-alias",
|
||||||
"/model-required-list-alias",
|
|
||||||
marks=pytest.mark.xfail(
|
|
||||||
raises=AssertionError,
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2 models",
|
|
||||||
strict=False,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_list_alias_by_name(path: str):
|
def test_required_list_alias_by_name(path: str):
|
||||||
|
|
@ -209,9 +192,7 @@ def test_required_list_alias_by_name(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": ["body", "p_alias"],
|
"loc": ["body", "p_alias"],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf( # /model-required-list-alias with PDv2 fails here
|
"input": IsOneOf(None, {"p": ["hello", "world"]}),
|
||||||
None, {"p": ["hello", "world"]}
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -264,7 +245,7 @@ class FormModelRequiredListValidationAlias(BaseModel):
|
||||||
async def read_model_required_list_validation_alias(
|
async def read_model_required_list_validation_alias(
|
||||||
p: Annotated[FormModelRequiredListValidationAlias, Form()],
|
p: Annotated[FormModelRequiredListValidationAlias, Form()],
|
||||||
):
|
):
|
||||||
return {"p": p.p} # pragma: no cover
|
return {"p": p.p}
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
|
|
@ -294,10 +275,7 @@ def test_required_list_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-list-validation-alias",
|
||||||
"/required-list-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-list-validation-alias",
|
"/model-required-list-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -311,7 +289,7 @@ def test_required_list_validation_alias_missing(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"body",
|
"body",
|
||||||
"p_val_alias", # /required-list-validation-alias fails here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(None, {}),
|
"input": IsOneOf(None, {}),
|
||||||
|
|
@ -324,19 +302,14 @@ def test_required_list_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-list-validation-alias",
|
||||||
"/required-list-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-list-validation-alias",
|
"/model-required-list-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_list_validation_alias_by_name(path: str):
|
def test_required_list_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, data={"p": ["hello", "world"]})
|
response = client.post(path, data={"p": ["hello", "world"]})
|
||||||
assert response.status_code == 422, (
|
assert response.status_code == 422, response.text
|
||||||
response.text # /required-list-validation-alias fails here
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
|
|
@ -351,7 +324,6 @@ def test_required_list_validation_alias_by_name(path: str):
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
["/required-list-validation-alias", "/model-required-list-validation-alias"],
|
["/required-list-validation-alias", "/model-required-list-validation-alias"],
|
||||||
|
|
@ -359,9 +331,9 @@ def test_required_list_validation_alias_by_name(path: str):
|
||||||
def test_required_list_validation_alias_by_validation_alias(path: str):
|
def test_required_list_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, data={"p_val_alias": ["hello", "world"]})
|
response = client.post(path, data={"p_val_alias": ["hello", "world"]})
|
||||||
assert response.status_code == 200, response.text # both fail here
|
assert response.status_code == 200, response.text
|
||||||
|
|
||||||
assert response.json() == {"p": ["hello", "world"]} # pragma: no cover
|
assert response.json() == {"p": ["hello", "world"]}
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -389,7 +361,7 @@ class FormModelRequiredListAliasAndValidationAlias(BaseModel):
|
||||||
def read_model_required_list_alias_and_validation_alias(
|
def read_model_required_list_alias_and_validation_alias(
|
||||||
p: Annotated[FormModelRequiredListAliasAndValidationAlias, Form()],
|
p: Annotated[FormModelRequiredListAliasAndValidationAlias, Form()],
|
||||||
):
|
):
|
||||||
return {"p": p.p} # pragma: no cover
|
return {"p": p.p}
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
|
|
@ -422,10 +394,7 @@ def test_required_list_alias_and_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-list-alias-and-validation-alias",
|
||||||
"/required-list-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-list-alias-and-validation-alias",
|
"/model-required-list-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -439,7 +408,6 @@ def test_required_list_alias_and_validation_alias_missing(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"body",
|
"body",
|
||||||
# /required-list-alias-and-validation-alias fails here
|
|
||||||
"p_val_alias",
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
|
|
@ -450,7 +418,6 @@ def test_required_list_alias_and_validation_alias_missing(path: str):
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -468,13 +435,11 @@ def test_required_list_alias_and_validation_alias_by_name(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"body",
|
"body",
|
||||||
# /required-list-alias-and-validation-alias fails here
|
|
||||||
"p_val_alias",
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(
|
"input": IsOneOf(
|
||||||
None,
|
None,
|
||||||
# /model-required-list-alias-and-validation-alias fails here
|
|
||||||
{"p": ["hello", "world"]},
|
{"p": ["hello", "world"]},
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
@ -486,19 +451,14 @@ def test_required_list_alias_and_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-list-alias-and-validation-alias",
|
||||||
"/required-list-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-list-alias-and-validation-alias",
|
"/model-required-list-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_list_alias_and_validation_alias_by_alias(path: str):
|
def test_required_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, data={"p_alias": ["hello", "world"]})
|
response = client.post(path, data={"p_alias": ["hello", "world"]})
|
||||||
assert ( # /required-list-alias-and-validation-alias fails here
|
assert response.status_code == 422
|
||||||
response.status_code == 422
|
|
||||||
)
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
{
|
{
|
||||||
|
|
@ -512,7 +472,6 @@ def test_required_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -523,5 +482,5 @@ def test_required_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
def test_required_list_alias_and_validation_alias_by_validation_alias(path: str):
|
def test_required_list_alias_and_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, data={"p_val_alias": ["hello", "world"]})
|
response = client.post(path, data={"p_val_alias": ["hello", "world"]})
|
||||||
assert response.status_code == 200, response.text # both fail here
|
assert response.status_code == 200, response.text
|
||||||
assert response.json() == {"p": ["hello", "world"]} # pragma: no cover
|
assert response.json() == {"p": ["hello", "world"]}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ from typing import List, Optional
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import IsDict
|
from dirty_equals import IsDict
|
||||||
from fastapi import FastAPI, Form
|
from fastapi import FastAPI, Form
|
||||||
from fastapi._compat import PYDANTIC_V2
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
@ -115,15 +114,7 @@ async def read_model_optional_list_alias(
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-list-alias",
|
||||||
"/optional-list-alias",
|
|
||||||
marks=pytest.mark.xfail(
|
|
||||||
raises=AssertionError,
|
|
||||||
strict=False,
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
"/model-optional-list-alias",
|
"/model-optional-list-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -276,10 +267,7 @@ def test_optional_list_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-list-validation-alias",
|
||||||
"/optional-list-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-list-validation-alias",
|
"/model-optional-list-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -287,11 +275,10 @@ def test_optional_list_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, data={"p": ["hello", "world"]})
|
response = client.post(path, data={"p": ["hello", "world"]})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"p": None} # /optional-list-validation-alias fails here
|
assert response.json() == {"p": None}
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
["/optional-list-validation-alias", "/model-optional-list-validation-alias"],
|
["/optional-list-validation-alias", "/model-optional-list-validation-alias"],
|
||||||
|
|
@ -299,12 +286,8 @@ def test_optional_list_validation_alias_by_name(path: str):
|
||||||
def test_optional_list_validation_alias_by_validation_alias(path: str):
|
def test_optional_list_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, data={"p_val_alias": ["hello", "world"]})
|
response = client.post(path, data={"p_val_alias": ["hello", "world"]})
|
||||||
assert response.status_code == 200, (
|
assert response.status_code == 200, response.text
|
||||||
response.text # /model-optional-list-validation-alias fails here
|
assert response.json() == {"p": ["hello", "world"]}
|
||||||
)
|
|
||||||
assert response.json() == { # /optional-list-validation-alias fails here
|
|
||||||
"p": ["hello", "world"]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -415,10 +398,7 @@ def test_optional_list_alias_and_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-list-alias-and-validation-alias",
|
||||||
"/optional-list-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-list-alias-and-validation-alias",
|
"/model-optional-list-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -426,13 +406,10 @@ def test_optional_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, data={"p_alias": ["hello", "world"]})
|
response = client.post(path, data={"p_alias": ["hello", "world"]})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {
|
assert response.json() == {"p": None}
|
||||||
"p": None # /optional-list-alias-and-validation-alias fails here
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -443,11 +420,9 @@ def test_optional_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
def test_optional_list_alias_and_validation_alias_by_validation_alias(path: str):
|
def test_optional_list_alias_and_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, data={"p_val_alias": ["hello", "world"]})
|
response = client.post(path, data={"p_val_alias": ["hello", "world"]})
|
||||||
assert response.status_code == 200, (
|
assert response.status_code == 200, response.text
|
||||||
response.text # /model-optional-list-alias-and-validation-alias fails here
|
|
||||||
)
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"p": [ # /optional-list-alias-and-validation-alias fails here
|
"p": [
|
||||||
"hello",
|
"hello",
|
||||||
"world",
|
"world",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ from typing import Optional
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import IsDict
|
from dirty_equals import IsDict
|
||||||
from fastapi import FastAPI, Form
|
from fastapi import FastAPI, Form
|
||||||
from fastapi._compat import PYDANTIC_V2
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
@ -108,15 +107,7 @@ async def read_model_optional_alias(p: Annotated[FormModelOptionalAlias, Form()]
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-alias",
|
||||||
"/optional-alias",
|
|
||||||
marks=pytest.mark.xfail(
|
|
||||||
raises=AssertionError,
|
|
||||||
strict=False,
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
"/model-optional-alias",
|
"/model-optional-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -252,10 +243,7 @@ def test_optional_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-validation-alias",
|
||||||
"/optional-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-validation-alias",
|
"/model-optional-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -263,17 +251,14 @@ def test_optional_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, data={"p": "hello"})
|
response = client.post(path, data={"p": "hello"})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"p": None} # /optional-validation-alias fails here
|
assert response.json() == {"p": None}
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-validation-alias",
|
||||||
"/optional-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-validation-alias",
|
"/model-optional-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -281,7 +266,7 @@ def test_optional_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, data={"p_val_alias": "hello"})
|
response = client.post(path, data={"p_val_alias": "hello"})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"p": "hello"} # /optional-validation-alias fails here
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -383,10 +368,7 @@ def test_optional_alias_and_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-alias-and-validation-alias",
|
||||||
"/optional-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-alias-and-validation-alias",
|
"/model-optional-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -394,19 +376,14 @@ def test_optional_alias_and_validation_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, data={"p_alias": "hello"})
|
response = client.post(path, data={"p_alias": "hello"})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {
|
assert response.json() == {"p": None}
|
||||||
"p": None # /optional-alias-and-validation-alias fails here
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-alias-and-validation-alias",
|
||||||
"/optional-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-alias-and-validation-alias",
|
"/model-optional-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -414,6 +391,4 @@ def test_optional_alias_and_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, data={"p_val_alias": "hello"})
|
response = client.post(path, data={"p_val_alias": "hello"})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {
|
assert response.json() == {"p": "hello"}
|
||||||
"p": "hello" # /optional-alias-and-validation-alias fails here
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import IsDict, IsOneOf
|
from dirty_equals import IsDict, IsOneOf
|
||||||
from fastapi import FastAPI, Form
|
from fastapi import FastAPI, Form
|
||||||
from fastapi._compat import PYDANTIC_V2
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
@ -113,15 +112,7 @@ async def read_model_required_alias(p: Annotated[FormModelRequiredAlias, Form()]
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-alias",
|
||||||
"/required-alias",
|
|
||||||
marks=pytest.mark.xfail(
|
|
||||||
raises=AssertionError,
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2",
|
|
||||||
strict=False,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
"/model-required-alias",
|
"/model-required-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -263,10 +254,7 @@ def test_required_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-validation-alias",
|
||||||
"/required-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-validation-alias",
|
"/model-required-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -280,7 +268,7 @@ def test_required_validation_alias_missing(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"body",
|
"body",
|
||||||
"p_val_alias", # /required-validation-alias fails here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(None, {}),
|
"input": IsOneOf(None, {}),
|
||||||
|
|
@ -293,19 +281,14 @@ def test_required_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-validation-alias",
|
||||||
"/required-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-validation-alias",
|
"/model-required-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_validation_alias_by_name(path: str):
|
def test_required_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, data={"p": "hello"})
|
response = client.post(path, data={"p": "hello"})
|
||||||
assert response.status_code == 422, ( # /required-validation-alias fails here
|
assert response.status_code == 422, response.text
|
||||||
response.text
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
|
|
@ -323,19 +306,14 @@ def test_required_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-validation-alias",
|
||||||
"/required-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-validation-alias",
|
"/model-required-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_validation_alias_by_validation_alias(path: str):
|
def test_required_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, data={"p_val_alias": "hello"})
|
response = client.post(path, data={"p_val_alias": "hello"})
|
||||||
assert response.status_code == 200, ( # /required-validation-alias fails here
|
assert response.status_code == 200, response.text
|
||||||
response.text
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {"p": "hello"}
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
||||||
|
|
@ -394,10 +372,7 @@ def test_required_alias_and_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-alias-and-validation-alias",
|
||||||
"/required-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-alias-and-validation-alias",
|
"/model-required-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -411,7 +386,7 @@ def test_required_alias_and_validation_alias_missing(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"body",
|
"body",
|
||||||
"p_val_alias", # /required-alias-and-validation-alias fails here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(None, {}),
|
"input": IsOneOf(None, {}),
|
||||||
|
|
@ -424,10 +399,7 @@ def test_required_alias_and_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-alias-and-validation-alias",
|
||||||
"/required-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-alias-and-validation-alias",
|
"/model-required-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -442,7 +414,7 @@ def test_required_alias_and_validation_alias_by_name(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"body",
|
"body",
|
||||||
"p_val_alias", # /required-alias-and-validation-alias fails here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(None, {"p": "hello"}),
|
"input": IsOneOf(None, {"p": "hello"}),
|
||||||
|
|
@ -455,19 +427,14 @@ def test_required_alias_and_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-alias-and-validation-alias",
|
||||||
"/required-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-alias-and-validation-alias",
|
"/model-required-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_alias_and_validation_alias_by_alias(path: str):
|
def test_required_alias_and_validation_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, data={"p_alias": "hello"})
|
response = client.post(path, data={"p_alias": "hello"})
|
||||||
assert response.status_code == 422, (
|
assert response.status_code == 422, response.text
|
||||||
response.text # /required-alias-and-validation-alias fails here
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
|
|
@ -485,18 +452,13 @@ def test_required_alias_and_validation_alias_by_alias(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-alias-and-validation-alias",
|
||||||
"/required-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-alias-and-validation-alias",
|
"/model-required-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_alias_and_validation_alias_by_validation_alias(path: str):
|
def test_required_alias_and_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.post(path, data={"p_val_alias": "hello"})
|
response = client.post(path, data={"p_val_alias": "hello"})
|
||||||
assert response.status_code == 200, (
|
assert response.status_code == 200, response.text
|
||||||
response.text # /required-alias-and-validation-alias fails here
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {"p": "hello"}
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ from typing import List
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import AnyThing, IsDict, IsOneOf, IsPartialDict
|
from dirty_equals import AnyThing, IsDict, IsOneOf, IsPartialDict
|
||||||
from fastapi import FastAPI, Header
|
from fastapi import FastAPI, Header
|
||||||
from fastapi._compat import PYDANTIC_V2
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
@ -109,7 +108,7 @@ class HeaderModelRequiredListAlias(BaseModel):
|
||||||
async def read_model_required_list_alias(
|
async def read_model_required_list_alias(
|
||||||
p: Annotated[HeaderModelRequiredListAlias, Header()],
|
p: Annotated[HeaderModelRequiredListAlias, Header()],
|
||||||
):
|
):
|
||||||
return {"p": p.p} # pragma: no cover
|
return {"p": p.p}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
@ -168,15 +167,7 @@ def test_required_list_alias_missing(path: str):
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
"/required-list-alias",
|
"/required-list-alias",
|
||||||
pytest.param(
|
"/model-required-list-alias",
|
||||||
"/model-required-list-alias",
|
|
||||||
marks=pytest.mark.xfail(
|
|
||||||
raises=AssertionError,
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2 models",
|
|
||||||
strict=False,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_list_alias_by_name(path: str):
|
def test_required_list_alias_by_name(path: str):
|
||||||
|
|
@ -190,9 +181,7 @@ def test_required_list_alias_by_name(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": ["header", "p_alias"],
|
"loc": ["header", "p_alias"],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf( # /model-required-list-alias with PDv2 fails here
|
"input": IsOneOf(None, IsPartialDict({"p": ["hello", "world"]})),
|
||||||
None, IsPartialDict({"p": ["hello", "world"]})
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -214,18 +203,13 @@ def test_required_list_alias_by_name(path: str):
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
"/required-list-alias",
|
"/required-list-alias",
|
||||||
pytest.param(
|
"/model-required-list-alias",
|
||||||
"/model-required-list-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_list_alias_by_alias(path: str):
|
def test_required_list_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(path, headers=[("p_alias", "hello"), ("p_alias", "world")])
|
response = client.get(path, headers=[("p_alias", "hello"), ("p_alias", "world")])
|
||||||
assert response.status_code == 200, ( # /model-required-list-alias fails here
|
assert response.status_code == 200, response.text
|
||||||
response.text
|
|
||||||
)
|
|
||||||
assert response.json() == {"p": ["hello", "world"]}
|
assert response.json() == {"p": ["hello", "world"]}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -248,11 +232,10 @@ class HeaderModelRequiredListValidationAlias(BaseModel):
|
||||||
async def read_model_required_list_validation_alias(
|
async def read_model_required_list_validation_alias(
|
||||||
p: Annotated[HeaderModelRequiredListValidationAlias, Header()],
|
p: Annotated[HeaderModelRequiredListValidationAlias, Header()],
|
||||||
):
|
):
|
||||||
return {"p": p.p} # pragma: no cover
|
return {"p": p.p}
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
["/required-list-validation-alias", "/model-required-list-validation-alias"],
|
["/required-list-validation-alias", "/model-required-list-validation-alias"],
|
||||||
|
|
@ -276,10 +259,7 @@ def test_required_list_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-list-validation-alias",
|
||||||
"/required-list-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-list-validation-alias",
|
"/model-required-list-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -293,7 +273,7 @@ def test_required_list_validation_alias_missing(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"header",
|
"header",
|
||||||
"p_val_alias", # /required-list-validation-alias fails here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": AnyThing,
|
"input": AnyThing,
|
||||||
|
|
@ -306,17 +286,14 @@ def test_required_list_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-list-validation-alias",
|
||||||
"/required-list-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-list-validation-alias",
|
"/model-required-list-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_list_validation_alias_by_name(path: str):
|
def test_required_list_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(path, headers=[("p", "hello"), ("p", "world")])
|
response = client.get(path, headers=[("p", "hello"), ("p", "world")])
|
||||||
assert response.status_code == 422 # /required-list-validation-alias fails here
|
assert response.status_code == 422
|
||||||
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
|
|
@ -331,7 +308,6 @@ def test_required_list_validation_alias_by_name(path: str):
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
["/required-list-validation-alias", "/model-required-list-validation-alias"],
|
["/required-list-validation-alias", "/model-required-list-validation-alias"],
|
||||||
|
|
@ -341,9 +317,9 @@ def test_required_list_validation_alias_by_validation_alias(path: str):
|
||||||
response = client.get(
|
response = client.get(
|
||||||
path, headers=[("p_val_alias", "hello"), ("p_val_alias", "world")]
|
path, headers=[("p_val_alias", "hello"), ("p_val_alias", "world")]
|
||||||
)
|
)
|
||||||
assert response.status_code == 200, response.text # both fail here
|
assert response.status_code == 200, response.text
|
||||||
|
|
||||||
assert response.json() == {"p": ["hello", "world"]} # pragma: no cover
|
assert response.json() == {"p": ["hello", "world"]}
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -365,11 +341,10 @@ class HeaderModelRequiredListAliasAndValidationAlias(BaseModel):
|
||||||
def read_model_required_list_alias_and_validation_alias(
|
def read_model_required_list_alias_and_validation_alias(
|
||||||
p: Annotated[HeaderModelRequiredListAliasAndValidationAlias, Header()],
|
p: Annotated[HeaderModelRequiredListAliasAndValidationAlias, Header()],
|
||||||
):
|
):
|
||||||
return {"p": p.p} # pragma: no cover
|
return {"p": p.p}
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -396,10 +371,7 @@ def test_required_list_alias_and_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-list-alias-and-validation-alias",
|
||||||
"/required-list-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-list-alias-and-validation-alias",
|
"/model-required-list-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -413,7 +385,6 @@ def test_required_list_alias_and_validation_alias_missing(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"header",
|
"header",
|
||||||
# /required-list-alias-and-validation-alias fails here
|
|
||||||
"p_val_alias",
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
|
|
@ -424,7 +395,6 @@ def test_required_list_alias_and_validation_alias_missing(path: str):
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -442,13 +412,11 @@ def test_required_list_alias_and_validation_alias_by_name(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"header",
|
"header",
|
||||||
# /required-list-alias-and-validation-alias fails here
|
|
||||||
"p_val_alias",
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(
|
"input": IsOneOf(
|
||||||
None,
|
None,
|
||||||
# /model-required-list-alias-and-validation-alias fails here
|
|
||||||
IsPartialDict({"p": ["hello", "world"]}),
|
IsPartialDict({"p": ["hello", "world"]}),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
@ -457,7 +425,6 @@ def test_required_list_alias_and_validation_alias_by_name(path: str):
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -468,9 +435,7 @@ def test_required_list_alias_and_validation_alias_by_name(path: str):
|
||||||
def test_required_list_alias_and_validation_alias_by_alias(path: str):
|
def test_required_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(path, headers=[("p_alias", "hello"), ("p_alias", "world")])
|
response = client.get(path, headers=[("p_alias", "hello"), ("p_alias", "world")])
|
||||||
assert ( # /required-list-alias-and-validation-alias fails here
|
assert response.status_code == 422
|
||||||
response.status_code == 422
|
|
||||||
)
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
{
|
{
|
||||||
|
|
@ -479,7 +444,6 @@ def test_required_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(
|
"input": IsOneOf(
|
||||||
None,
|
None,
|
||||||
# /model-required-list-alias-and-validation-alias fails here
|
|
||||||
IsPartialDict({"p_alias": ["hello", "world"]}),
|
IsPartialDict({"p_alias": ["hello", "world"]}),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
@ -488,7 +452,6 @@ def test_required_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -501,5 +464,5 @@ def test_required_list_alias_and_validation_alias_by_validation_alias(path: str)
|
||||||
response = client.get(
|
response = client.get(
|
||||||
path, headers=[("p_val_alias", "hello"), ("p_val_alias", "world")]
|
path, headers=[("p_val_alias", "hello"), ("p_val_alias", "world")]
|
||||||
)
|
)
|
||||||
assert response.status_code == 200, response.text # both fail here
|
assert response.status_code == 200, response.text
|
||||||
assert response.json() == {"p": ["hello", "world"]} # pragma: no cover
|
assert response.json() == {"p": ["hello", "world"]}
|
||||||
|
|
|
||||||
|
|
@ -171,19 +171,14 @@ def test_optional_list_alias_by_name(path: str):
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
"/optional-list-alias",
|
"/optional-list-alias",
|
||||||
pytest.param(
|
"/model-optional-list-alias",
|
||||||
"/model-optional-list-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_optional_list_alias_by_alias(path: str):
|
def test_optional_list_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(path, headers=[("p_alias", "hello"), ("p_alias", "world")])
|
response = client.get(path, headers=[("p_alias", "hello"), ("p_alias", "world")])
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {
|
assert response.json() == {"p": ["hello", "world"]}
|
||||||
"p": ["hello", "world"] # /model-optional-list-alias fails here
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -209,7 +204,6 @@ def read_model_optional_list_validation_alias(
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
["/optional-list-validation-alias", "/model-optional-list-validation-alias"],
|
["/optional-list-validation-alias", "/model-optional-list-validation-alias"],
|
||||||
|
|
@ -247,10 +241,7 @@ def test_optional_list_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-list-validation-alias",
|
||||||
"/optional-list-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-list-validation-alias",
|
"/model-optional-list-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -258,11 +249,10 @@ def test_optional_list_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(path, headers=[("p", "hello"), ("p", "world")])
|
response = client.get(path, headers=[("p", "hello"), ("p", "world")])
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"p": None} # /optional-list-validation-alias fails here
|
assert response.json() == {"p": None}
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
["/optional-list-validation-alias", "/model-optional-list-validation-alias"],
|
["/optional-list-validation-alias", "/model-optional-list-validation-alias"],
|
||||||
|
|
@ -272,12 +262,8 @@ def test_optional_list_validation_alias_by_validation_alias(path: str):
|
||||||
response = client.get(
|
response = client.get(
|
||||||
path, headers=[("p_val_alias", "hello"), ("p_val_alias", "world")]
|
path, headers=[("p_val_alias", "hello"), ("p_val_alias", "world")]
|
||||||
)
|
)
|
||||||
assert response.status_code == 200, (
|
assert response.status_code == 200, response.text
|
||||||
response.text # /model-optional-list-validation-alias fails here
|
assert response.json() == {"p": ["hello", "world"]}
|
||||||
)
|
|
||||||
assert response.json() == { # /optional-list-validation-alias fails here
|
|
||||||
"p": ["hello", "world"]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -307,7 +293,6 @@ def read_model_optional_list_alias_and_validation_alias(
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -366,10 +351,7 @@ def test_optional_list_alias_and_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-list-alias-and-validation-alias",
|
||||||
"/optional-list-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-list-alias-and-validation-alias",
|
"/model-optional-list-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -377,13 +359,10 @@ def test_optional_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(path, headers=[("p_alias", "hello"), ("p_alias", "world")])
|
response = client.get(path, headers=[("p_alias", "hello"), ("p_alias", "world")])
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {
|
assert response.json() == {"p": None}
|
||||||
"p": None # /optional-list-alias-and-validation-alias fails here
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -396,11 +375,9 @@ def test_optional_list_alias_and_validation_alias_by_validation_alias(path: str)
|
||||||
response = client.get(
|
response = client.get(
|
||||||
path, headers=[("p_val_alias", "hello"), ("p_val_alias", "world")]
|
path, headers=[("p_val_alias", "hello"), ("p_val_alias", "world")]
|
||||||
)
|
)
|
||||||
assert response.status_code == 200, (
|
assert response.status_code == 200, response.text
|
||||||
response.text # /model-optional-list-alias-and-validation-alias fails here
|
|
||||||
)
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"p": [ # /optional-list-alias-and-validation-alias fails here
|
"p": [
|
||||||
"hello",
|
"hello",
|
||||||
"world",
|
"world",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -155,17 +155,14 @@ def test_optional_alias_by_name(path: str):
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
"/optional-alias",
|
"/optional-alias",
|
||||||
pytest.param(
|
"/model-optional-alias",
|
||||||
"/model-optional-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_optional_alias_by_alias(path: str):
|
def test_optional_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(path, headers={"p_alias": "hello"})
|
response = client.get(path, headers={"p_alias": "hello"})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"p": "hello"} # /model-optional-alias fails here
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -191,7 +188,6 @@ def read_model_optional_validation_alias(
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
["/optional-validation-alias", "/model-optional-validation-alias"],
|
["/optional-validation-alias", "/model-optional-validation-alias"],
|
||||||
|
|
@ -226,10 +222,7 @@ def test_optional_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-validation-alias",
|
||||||
"/optional-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-validation-alias",
|
"/model-optional-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -237,17 +230,14 @@ def test_optional_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(path, headers={"p": "hello"})
|
response = client.get(path, headers={"p": "hello"})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"p": None} # /optional-validation-alias fails here
|
assert response.json() == {"p": None}
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-validation-alias",
|
||||||
"/optional-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-validation-alias",
|
"/model-optional-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -255,7 +245,7 @@ def test_optional_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(path, headers={"p_val_alias": "hello"})
|
response = client.get(path, headers={"p_val_alias": "hello"})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"p": "hello"} # /optional-validation-alias fails here
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -283,7 +273,6 @@ def read_model_optional_alias_and_validation_alias(
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -339,10 +328,7 @@ def test_optional_alias_and_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-alias-and-validation-alias",
|
||||||
"/optional-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-alias-and-validation-alias",
|
"/model-optional-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -350,19 +336,14 @@ def test_optional_alias_and_validation_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(path, headers={"p_alias": "hello"})
|
response = client.get(path, headers={"p_alias": "hello"})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {
|
assert response.json() == {"p": None}
|
||||||
"p": None # /optional-alias-and-validation-alias fails here
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-alias-and-validation-alias",
|
||||||
"/optional-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-alias-and-validation-alias",
|
"/model-optional-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -370,6 +351,4 @@ def test_optional_alias_and_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(path, headers={"p_val_alias": "hello"})
|
response = client.get(path, headers={"p_val_alias": "hello"})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {
|
assert response.json() == {"p": "hello"}
|
||||||
"p": "hello" # /optional-alias-and-validation-alias fails here
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import AnyThing, IsDict, IsOneOf, IsPartialDict
|
from dirty_equals import AnyThing, IsDict, IsOneOf, IsPartialDict
|
||||||
from fastapi import FastAPI, Header
|
from fastapi import FastAPI, Header
|
||||||
from fastapi._compat import PYDANTIC_V2
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
@ -102,7 +101,7 @@ class HeaderModelRequiredAlias(BaseModel):
|
||||||
|
|
||||||
@app.get("/model-required-alias")
|
@app.get("/model-required-alias")
|
||||||
async def read_model_required_alias(p: Annotated[HeaderModelRequiredAlias, Header()]):
|
async def read_model_required_alias(p: Annotated[HeaderModelRequiredAlias, Header()]):
|
||||||
return {"p": p.p} # pragma: no cover
|
return {"p": p.p}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
@ -157,15 +156,7 @@ def test_required_alias_missing(path: str):
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
"/required-alias",
|
"/required-alias",
|
||||||
pytest.param(
|
"/model-required-alias",
|
||||||
"/model-required-alias",
|
|
||||||
marks=pytest.mark.xfail(
|
|
||||||
raises=AssertionError,
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2 models",
|
|
||||||
strict=False,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_alias_by_name(path: str):
|
def test_required_alias_by_name(path: str):
|
||||||
|
|
@ -201,18 +192,13 @@ def test_required_alias_by_name(path: str):
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
"/required-alias",
|
"/required-alias",
|
||||||
pytest.param(
|
"/model-required-alias",
|
||||||
"/model-required-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_alias_by_alias(path: str):
|
def test_required_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(path, headers={"p_alias": "hello"})
|
response = client.get(path, headers={"p_alias": "hello"})
|
||||||
assert response.status_code == 200, ( # /model-required-alias fails here
|
assert response.status_code == 200, response.text
|
||||||
response.text
|
|
||||||
)
|
|
||||||
assert response.json() == {"p": "hello"}
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -239,7 +225,6 @@ def read_model_required_validation_alias(
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
["/required-validation-alias", "/model-required-validation-alias"],
|
["/required-validation-alias", "/model-required-validation-alias"],
|
||||||
|
|
@ -259,10 +244,7 @@ def test_required_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-validation-alias",
|
||||||
"/required-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-validation-alias",
|
"/model-required-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -276,7 +258,7 @@ def test_required_validation_alias_missing(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"header",
|
"header",
|
||||||
"p_val_alias", # /required-validation-alias fails here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": AnyThing,
|
"input": AnyThing,
|
||||||
|
|
@ -289,19 +271,14 @@ def test_required_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-validation-alias",
|
||||||
"/required-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-validation-alias",
|
"/model-required-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_validation_alias_by_name(path: str):
|
def test_required_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(path, headers={"p": "hello"})
|
response = client.get(path, headers={"p": "hello"})
|
||||||
assert response.status_code == 422, ( # /required-validation-alias fails here
|
assert response.status_code == 422, response.text
|
||||||
response.text
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
|
|
@ -319,19 +296,14 @@ def test_required_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-validation-alias",
|
||||||
"/required-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-validation-alias",
|
"/model-required-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_validation_alias_by_validation_alias(path: str):
|
def test_required_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(path, headers={"p_val_alias": "hello"})
|
response = client.get(path, headers={"p_val_alias": "hello"})
|
||||||
assert response.status_code == 200, ( # /required-validation-alias fails here
|
assert response.status_code == 200, response.text
|
||||||
response.text
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {"p": "hello"}
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
||||||
|
|
@ -359,7 +331,6 @@ def read_model_required_alias_and_validation_alias(
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -382,10 +353,7 @@ def test_required_alias_and_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-alias-and-validation-alias",
|
||||||
"/required-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-alias-and-validation-alias",
|
"/model-required-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -399,7 +367,7 @@ def test_required_alias_and_validation_alias_missing(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"header",
|
"header",
|
||||||
"p_val_alias", # /required-alias-and-validation-alias fails here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": AnyThing,
|
"input": AnyThing,
|
||||||
|
|
@ -409,7 +377,6 @@ def test_required_alias_and_validation_alias_missing(path: str):
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -428,10 +395,10 @@ def test_required_alias_and_validation_alias_by_name(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"header",
|
"header",
|
||||||
"p_val_alias", # /required-alias-and-validation-alias fails here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf( # /model-alias-and-validation-alias fails here
|
"input": IsOneOf(
|
||||||
None,
|
None,
|
||||||
IsPartialDict({"p": "hello"}),
|
IsPartialDict({"p": "hello"}),
|
||||||
),
|
),
|
||||||
|
|
@ -441,7 +408,6 @@ def test_required_alias_and_validation_alias_by_name(path: str):
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -452,9 +418,7 @@ def test_required_alias_and_validation_alias_by_name(path: str):
|
||||||
def test_required_alias_and_validation_alias_by_alias(path: str):
|
def test_required_alias_and_validation_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(path, headers={"p_alias": "hello"})
|
response = client.get(path, headers={"p_alias": "hello"})
|
||||||
assert (
|
assert response.status_code == 422
|
||||||
response.status_code == 422 # /required-alias-and-validation-alias fails here
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
|
|
@ -462,7 +426,7 @@ def test_required_alias_and_validation_alias_by_alias(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": ["header", "p_val_alias"],
|
"loc": ["header", "p_val_alias"],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf( # /model-alias-and-validation-alias fails here
|
"input": IsOneOf(
|
||||||
None,
|
None,
|
||||||
IsPartialDict({"p_alias": "hello"}),
|
IsPartialDict({"p_alias": "hello"}),
|
||||||
),
|
),
|
||||||
|
|
@ -475,18 +439,13 @@ def test_required_alias_and_validation_alias_by_alias(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-alias-and-validation-alias",
|
||||||
"/required-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-alias-and-validation-alias",
|
"/model-required-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_alias_and_validation_alias_by_validation_alias(path: str):
|
def test_required_alias_and_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(path, headers={"p_val_alias": "hello"})
|
response = client.get(path, headers={"p_val_alias": "hello"})
|
||||||
assert response.status_code == 200, (
|
assert response.status_code == 200, response.text
|
||||||
response.text # /required-alias-and-validation-alias fails here
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {"p": "hello"}
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
|
||||||
|
|
@ -22,14 +22,14 @@ async def read_required_alias(p: Annotated[str, Path(alias="p_alias")]):
|
||||||
def read_required_validation_alias(
|
def read_required_validation_alias(
|
||||||
p: Annotated[str, Path(validation_alias="p_val_alias")],
|
p: Annotated[str, Path(validation_alias="p_val_alias")],
|
||||||
):
|
):
|
||||||
return {"p": p} # pragma: no cover
|
return {"p": p}
|
||||||
|
|
||||||
|
|
||||||
@app.get("/required-alias-and-validation-alias/{p_val_alias}")
|
@app.get("/required-alias-and-validation-alias/{p_val_alias}")
|
||||||
def read_required_alias_and_validation_alias(
|
def read_required_alias_and_validation_alias(
|
||||||
p: Annotated[str, Path(alias="p_alias", validation_alias="p_val_alias")],
|
p: Annotated[str, Path(alias="p_alias", validation_alias="p_val_alias")],
|
||||||
):
|
):
|
||||||
return {"p": p} # pragma: no cover
|
return {"p": p}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
@ -44,20 +44,14 @@ def read_required_alias_and_validation_alias(
|
||||||
"p_val_alias",
|
"p_val_alias",
|
||||||
"P Val Alias",
|
"P Val Alias",
|
||||||
id="required-validation-alias",
|
id="required-validation-alias",
|
||||||
marks=(
|
marks=needs_pydanticv2,
|
||||||
needs_pydanticv2,
|
|
||||||
pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
pytest.param(
|
pytest.param(
|
||||||
"/required-alias-and-validation-alias/{p_val_alias}",
|
"/required-alias-and-validation-alias/{p_val_alias}",
|
||||||
"p_val_alias",
|
"p_val_alias",
|
||||||
"P Val Alias",
|
"P Val Alias",
|
||||||
id="required-alias-and-validation-alias",
|
id="required-alias-and-validation-alias",
|
||||||
marks=(
|
marks=needs_pydanticv2,
|
||||||
needs_pydanticv2,
|
|
||||||
pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -80,18 +74,12 @@ def test_schema(path: str, expected_name: str, expected_title: str):
|
||||||
pytest.param(
|
pytest.param(
|
||||||
"/required-validation-alias",
|
"/required-validation-alias",
|
||||||
id="required-validation-alias",
|
id="required-validation-alias",
|
||||||
marks=(
|
marks=needs_pydanticv2,
|
||||||
needs_pydanticv2,
|
|
||||||
pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
pytest.param(
|
pytest.param(
|
||||||
"/required-alias-and-validation-alias",
|
"/required-alias-and-validation-alias",
|
||||||
id="required-alias-and-validation-alias",
|
id="required-alias-and-validation-alias",
|
||||||
marks=(
|
marks=needs_pydanticv2,
|
||||||
needs_pydanticv2,
|
|
||||||
pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ from typing import List
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import IsDict, IsOneOf
|
from dirty_equals import IsDict, IsOneOf
|
||||||
from fastapi import FastAPI, Query
|
from fastapi import FastAPI, Query
|
||||||
from fastapi._compat import PYDANTIC_V2
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
@ -109,7 +108,7 @@ class QueryModelRequiredListAlias(BaseModel):
|
||||||
async def read_model_required_list_alias(
|
async def read_model_required_list_alias(
|
||||||
p: Annotated[QueryModelRequiredListAlias, Query()],
|
p: Annotated[QueryModelRequiredListAlias, Query()],
|
||||||
):
|
):
|
||||||
return {"p": p.p} # pragma: no cover
|
return {"p": p.p}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
@ -168,15 +167,7 @@ def test_required_list_alias_missing(path: str):
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
"/required-list-alias",
|
"/required-list-alias",
|
||||||
pytest.param(
|
"/model-required-list-alias",
|
||||||
"/model-required-list-alias",
|
|
||||||
marks=pytest.mark.xfail(
|
|
||||||
raises=AssertionError,
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2 models",
|
|
||||||
strict=False,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_list_alias_by_name(path: str):
|
def test_required_list_alias_by_name(path: str):
|
||||||
|
|
@ -190,9 +181,7 @@ def test_required_list_alias_by_name(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": ["query", "p_alias"],
|
"loc": ["query", "p_alias"],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf( # /model-required-list-alias with PDv2 fails here
|
"input": IsOneOf(None, {"p": ["hello", "world"]}),
|
||||||
None, {"p": ["hello", "world"]}
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -214,18 +203,13 @@ def test_required_list_alias_by_name(path: str):
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
"/required-list-alias",
|
"/required-list-alias",
|
||||||
pytest.param(
|
"/model-required-list-alias",
|
||||||
"/model-required-list-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_list_alias_by_alias(path: str):
|
def test_required_list_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(f"{path}?p_alias=hello&p_alias=world")
|
response = client.get(f"{path}?p_alias=hello&p_alias=world")
|
||||||
assert response.status_code == 200, ( # /model-required-list-alias fails here
|
assert response.status_code == 200, response.text
|
||||||
response.text
|
|
||||||
)
|
|
||||||
assert response.json() == {"p": ["hello", "world"]}
|
assert response.json() == {"p": ["hello", "world"]}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -248,11 +232,10 @@ class QueryModelRequiredListValidationAlias(BaseModel):
|
||||||
async def read_model_required_list_validation_alias(
|
async def read_model_required_list_validation_alias(
|
||||||
p: Annotated[QueryModelRequiredListValidationAlias, Query()],
|
p: Annotated[QueryModelRequiredListValidationAlias, Query()],
|
||||||
):
|
):
|
||||||
return {"p": p.p} # pragma: no cover
|
return {"p": p.p}
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
["/required-list-validation-alias", "/model-required-list-validation-alias"],
|
["/required-list-validation-alias", "/model-required-list-validation-alias"],
|
||||||
|
|
@ -276,10 +259,7 @@ def test_required_list_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-list-validation-alias",
|
||||||
"/required-list-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-list-validation-alias",
|
"/model-required-list-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -293,7 +273,7 @@ def test_required_list_validation_alias_missing(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"query",
|
"query",
|
||||||
"p_val_alias", # /required-list-validation-alias fails here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(None, {}),
|
"input": IsOneOf(None, {}),
|
||||||
|
|
@ -306,17 +286,14 @@ def test_required_list_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-list-validation-alias",
|
||||||
"/required-list-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-list-validation-alias",
|
"/model-required-list-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_list_validation_alias_by_name(path: str):
|
def test_required_list_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(f"{path}?p=hello&p=world")
|
response = client.get(f"{path}?p=hello&p=world")
|
||||||
assert response.status_code == 422 # /required-list-validation-alias fails here
|
assert response.status_code == 422
|
||||||
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
|
|
@ -331,7 +308,6 @@ def test_required_list_validation_alias_by_name(path: str):
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
["/required-list-validation-alias", "/model-required-list-validation-alias"],
|
["/required-list-validation-alias", "/model-required-list-validation-alias"],
|
||||||
|
|
@ -339,9 +315,9 @@ def test_required_list_validation_alias_by_name(path: str):
|
||||||
def test_required_list_validation_alias_by_validation_alias(path: str):
|
def test_required_list_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(f"{path}?p_val_alias=hello&p_val_alias=world")
|
response = client.get(f"{path}?p_val_alias=hello&p_val_alias=world")
|
||||||
assert response.status_code == 200, response.text # both fail here
|
assert response.status_code == 200, response.text
|
||||||
|
|
||||||
assert response.json() == {"p": ["hello", "world"]} # pragma: no cover
|
assert response.json() == {"p": ["hello", "world"]}
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -363,11 +339,10 @@ class QueryModelRequiredListAliasAndValidationAlias(BaseModel):
|
||||||
def read_model_required_list_alias_and_validation_alias(
|
def read_model_required_list_alias_and_validation_alias(
|
||||||
p: Annotated[QueryModelRequiredListAliasAndValidationAlias, Query()],
|
p: Annotated[QueryModelRequiredListAliasAndValidationAlias, Query()],
|
||||||
):
|
):
|
||||||
return {"p": p.p} # pragma: no cover
|
return {"p": p.p}
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -394,10 +369,7 @@ def test_required_list_alias_and_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-list-alias-and-validation-alias",
|
||||||
"/required-list-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-list-alias-and-validation-alias",
|
"/model-required-list-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -411,7 +383,6 @@ def test_required_list_alias_and_validation_alias_missing(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"query",
|
"query",
|
||||||
# /required-list-alias-and-validation-alias fails here
|
|
||||||
"p_val_alias",
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
|
|
@ -422,7 +393,6 @@ def test_required_list_alias_and_validation_alias_missing(path: str):
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -440,13 +410,11 @@ def test_required_list_alias_and_validation_alias_by_name(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"query",
|
"query",
|
||||||
# /required-list-alias-and-validation-alias fails here
|
|
||||||
"p_val_alias",
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(
|
"input": IsOneOf(
|
||||||
None,
|
None,
|
||||||
# /model-required-list-alias-and-validation-alias fails here
|
|
||||||
{
|
{
|
||||||
"p": [
|
"p": [
|
||||||
"hello",
|
"hello",
|
||||||
|
|
@ -460,7 +428,6 @@ def test_required_list_alias_and_validation_alias_by_name(path: str):
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -471,9 +438,7 @@ def test_required_list_alias_and_validation_alias_by_name(path: str):
|
||||||
def test_required_list_alias_and_validation_alias_by_alias(path: str):
|
def test_required_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(f"{path}?p_alias=hello&p_alias=world")
|
response = client.get(f"{path}?p_alias=hello&p_alias=world")
|
||||||
assert ( # /required-list-alias-and-validation-alias fails here
|
assert response.status_code == 422
|
||||||
response.status_code == 422
|
|
||||||
)
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
{
|
{
|
||||||
|
|
@ -482,7 +447,6 @@ def test_required_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(
|
"input": IsOneOf(
|
||||||
None,
|
None,
|
||||||
# /model-required-list-alias-and-validation-alias fails here
|
|
||||||
{"p_alias": ["hello", "world"]},
|
{"p_alias": ["hello", "world"]},
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
@ -491,7 +455,6 @@ def test_required_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -502,5 +465,5 @@ def test_required_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
def test_required_list_alias_and_validation_alias_by_validation_alias(path: str):
|
def test_required_list_alias_and_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(f"{path}?p_val_alias=hello&p_val_alias=world")
|
response = client.get(f"{path}?p_val_alias=hello&p_val_alias=world")
|
||||||
assert response.status_code == 200, response.text # both fail here
|
assert response.status_code == 200, response.text
|
||||||
assert response.json() == {"p": ["hello", "world"]} # pragma: no cover
|
assert response.json() == {"p": ["hello", "world"]}
|
||||||
|
|
|
||||||
|
|
@ -171,19 +171,14 @@ def test_optional_list_alias_by_name(path: str):
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
"/optional-list-alias",
|
"/optional-list-alias",
|
||||||
pytest.param(
|
"/model-optional-list-alias",
|
||||||
"/model-optional-list-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_optional_list_alias_by_alias(path: str):
|
def test_optional_list_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(f"{path}?p_alias=hello&p_alias=world")
|
response = client.get(f"{path}?p_alias=hello&p_alias=world")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {
|
assert response.json() == {"p": ["hello", "world"]}
|
||||||
"p": ["hello", "world"] # /model-optional-list-alias fails here
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -209,7 +204,6 @@ def read_model_optional_list_validation_alias(
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
["/optional-list-validation-alias", "/model-optional-list-validation-alias"],
|
["/optional-list-validation-alias", "/model-optional-list-validation-alias"],
|
||||||
|
|
@ -247,10 +241,7 @@ def test_optional_list_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-list-validation-alias",
|
||||||
"/optional-list-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-list-validation-alias",
|
"/model-optional-list-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -258,11 +249,10 @@ def test_optional_list_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(f"{path}?p=hello&p=world")
|
response = client.get(f"{path}?p=hello&p=world")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"p": None} # /optional-list-validation-alias fails here
|
assert response.json() == {"p": None}
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
["/optional-list-validation-alias", "/model-optional-list-validation-alias"],
|
["/optional-list-validation-alias", "/model-optional-list-validation-alias"],
|
||||||
|
|
@ -270,12 +260,8 @@ def test_optional_list_validation_alias_by_name(path: str):
|
||||||
def test_optional_list_validation_alias_by_validation_alias(path: str):
|
def test_optional_list_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(f"{path}?p_val_alias=hello&p_val_alias=world")
|
response = client.get(f"{path}?p_val_alias=hello&p_val_alias=world")
|
||||||
assert response.status_code == 200, (
|
assert response.status_code == 200, response.text
|
||||||
response.text # /model-optional-list-validation-alias fails here
|
assert response.json() == {"p": ["hello", "world"]}
|
||||||
)
|
|
||||||
assert response.json() == { # /optional-list-validation-alias fails here
|
|
||||||
"p": ["hello", "world"]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -305,7 +291,6 @@ def read_model_optional_list_alias_and_validation_alias(
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -364,10 +349,7 @@ def test_optional_list_alias_and_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-list-alias-and-validation-alias",
|
||||||
"/optional-list-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-list-alias-and-validation-alias",
|
"/model-optional-list-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -375,13 +357,10 @@ def test_optional_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(f"{path}?p_alias=hello&p_alias=world")
|
response = client.get(f"{path}?p_alias=hello&p_alias=world")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {
|
assert response.json() == {"p": None}
|
||||||
"p": None # /optional-list-alias-and-validation-alias fails here
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -392,11 +371,9 @@ def test_optional_list_alias_and_validation_alias_by_alias(path: str):
|
||||||
def test_optional_list_alias_and_validation_alias_by_validation_alias(path: str):
|
def test_optional_list_alias_and_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(f"{path}?p_val_alias=hello&p_val_alias=world")
|
response = client.get(f"{path}?p_val_alias=hello&p_val_alias=world")
|
||||||
assert response.status_code == 200, (
|
assert response.status_code == 200, response.text
|
||||||
response.text # /model-optional-list-alias-and-validation-alias fails here
|
|
||||||
)
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"p": [ # /optional-list-alias-and-validation-alias fails here
|
"p": [
|
||||||
"hello",
|
"hello",
|
||||||
"world",
|
"world",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -155,17 +155,14 @@ def test_optional_alias_by_name(path: str):
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
"/optional-alias",
|
"/optional-alias",
|
||||||
pytest.param(
|
"/model-optional-alias",
|
||||||
"/model-optional-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_optional_alias_by_alias(path: str):
|
def test_optional_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(f"{path}?p_alias=hello")
|
response = client.get(f"{path}?p_alias=hello")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"p": "hello"} # /model-optional-alias fails here
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -191,7 +188,6 @@ def read_model_optional_validation_alias(
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
["/optional-validation-alias", "/model-optional-validation-alias"],
|
["/optional-validation-alias", "/model-optional-validation-alias"],
|
||||||
|
|
@ -226,10 +222,7 @@ def test_optional_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-validation-alias",
|
||||||
"/optional-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-validation-alias",
|
"/model-optional-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -244,10 +237,7 @@ def test_optional_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-validation-alias",
|
||||||
"/optional-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-validation-alias",
|
"/model-optional-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -255,7 +245,7 @@ def test_optional_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(f"{path}?p_val_alias=hello")
|
response = client.get(f"{path}?p_val_alias=hello")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"p": "hello"} # /optional-validation-alias fails here
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
||||||
|
|
||||||
# =====================================================================================
|
# =====================================================================================
|
||||||
|
|
@ -283,7 +273,6 @@ def read_model_optional_alias_and_validation_alias(
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -339,10 +328,7 @@ def test_optional_alias_and_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-alias-and-validation-alias",
|
||||||
"/optional-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-alias-and-validation-alias",
|
"/model-optional-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -350,19 +336,14 @@ def test_optional_alias_and_validation_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(f"{path}?p_alias=hello")
|
response = client.get(f"{path}?p_alias=hello")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {
|
assert response.json() == {"p": None}
|
||||||
"p": None # /optional-alias-and-validation-alias fails here
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/optional-alias-and-validation-alias",
|
||||||
"/optional-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-optional-alias-and-validation-alias",
|
"/model-optional-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -370,6 +351,4 @@ def test_optional_alias_and_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(f"{path}?p_val_alias=hello")
|
response = client.get(f"{path}?p_val_alias=hello")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {
|
assert response.json() == {"p": "hello"}
|
||||||
"p": "hello" # /optional-alias-and-validation-alias fails here
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import IsDict, IsOneOf
|
from dirty_equals import IsDict, IsOneOf
|
||||||
from fastapi import FastAPI, Query
|
from fastapi import FastAPI, Query
|
||||||
from fastapi._compat import PYDANTIC_V2
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
@ -102,7 +101,7 @@ class QueryModelRequiredAlias(BaseModel):
|
||||||
|
|
||||||
@app.get("/model-required-alias")
|
@app.get("/model-required-alias")
|
||||||
async def read_model_required_alias(p: Annotated[QueryModelRequiredAlias, Query()]):
|
async def read_model_required_alias(p: Annotated[QueryModelRequiredAlias, Query()]):
|
||||||
return {"p": p.p} # pragma: no cover
|
return {"p": p.p}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
@ -157,15 +156,7 @@ def test_required_alias_missing(path: str):
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
"/required-alias",
|
"/required-alias",
|
||||||
pytest.param(
|
"/model-required-alias",
|
||||||
"/model-required-alias",
|
|
||||||
marks=pytest.mark.xfail(
|
|
||||||
raises=AssertionError,
|
|
||||||
condition=PYDANTIC_V2,
|
|
||||||
reason="Fails only with PDv2 models",
|
|
||||||
strict=False,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_alias_by_name(path: str):
|
def test_required_alias_by_name(path: str):
|
||||||
|
|
@ -181,7 +172,7 @@ def test_required_alias_by_name(path: str):
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(
|
"input": IsOneOf(
|
||||||
None,
|
None,
|
||||||
{"p": "hello"}, # /model-required-alias PDv2 fails here
|
{"p": "hello"},
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -204,18 +195,13 @@ def test_required_alias_by_name(path: str):
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
"/required-alias",
|
"/required-alias",
|
||||||
pytest.param(
|
"/model-required-alias",
|
||||||
"/model-required-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_alias_by_alias(path: str):
|
def test_required_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(f"{path}?p_alias=hello")
|
response = client.get(f"{path}?p_alias=hello")
|
||||||
assert response.status_code == 200, ( # /model-required-alias fails here
|
assert response.status_code == 200, response.text
|
||||||
response.text
|
|
||||||
)
|
|
||||||
assert response.json() == {"p": "hello"}
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -242,7 +228,6 @@ def read_model_required_validation_alias(
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
["/required-validation-alias", "/model-required-validation-alias"],
|
["/required-validation-alias", "/model-required-validation-alias"],
|
||||||
|
|
@ -262,10 +247,7 @@ def test_required_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-validation-alias",
|
||||||
"/required-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-validation-alias",
|
"/model-required-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -279,7 +261,7 @@ def test_required_validation_alias_missing(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"query",
|
"query",
|
||||||
"p_val_alias", # /required-validation-alias fails here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(None, {}),
|
"input": IsOneOf(None, {}),
|
||||||
|
|
@ -292,19 +274,14 @@ def test_required_validation_alias_missing(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-validation-alias",
|
||||||
"/required-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-validation-alias",
|
"/model-required-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_validation_alias_by_name(path: str):
|
def test_required_validation_alias_by_name(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(f"{path}?p=hello")
|
response = client.get(f"{path}?p=hello")
|
||||||
assert response.status_code == 422, ( # /required-validation-alias fails here
|
assert response.status_code == 422, response.text
|
||||||
response.text
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
|
|
@ -322,19 +299,14 @@ def test_required_validation_alias_by_name(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-validation-alias",
|
||||||
"/required-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-validation-alias",
|
"/model-required-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_validation_alias_by_validation_alias(path: str):
|
def test_required_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(f"{path}?p_val_alias=hello")
|
response = client.get(f"{path}?p_val_alias=hello")
|
||||||
assert response.status_code == 200, ( # /required-validation-alias fails here
|
assert response.status_code == 200, response.text
|
||||||
response.text
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {"p": "hello"}
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
||||||
|
|
@ -362,7 +334,6 @@ def read_model_required_alias_and_validation_alias(
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -385,10 +356,7 @@ def test_required_alias_and_validation_alias_schema(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-alias-and-validation-alias",
|
||||||
"/required-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-alias-and-validation-alias",
|
"/model-required-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -402,7 +370,7 @@ def test_required_alias_and_validation_alias_missing(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"query",
|
"query",
|
||||||
"p_val_alias", # /required-alias-and-validation-alias fails here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf(None, {}),
|
"input": IsOneOf(None, {}),
|
||||||
|
|
@ -412,7 +380,6 @@ def test_required_alias_and_validation_alias_missing(path: str):
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -431,10 +398,10 @@ def test_required_alias_and_validation_alias_by_name(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": [
|
"loc": [
|
||||||
"query",
|
"query",
|
||||||
"p_val_alias", # /required-alias-and-validation-alias fails here
|
"p_val_alias",
|
||||||
],
|
],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf( # /model-alias-and-validation-alias fails here
|
"input": IsOneOf(
|
||||||
None,
|
None,
|
||||||
{"p": "hello"},
|
{"p": "hello"},
|
||||||
),
|
),
|
||||||
|
|
@ -444,7 +411,6 @@ def test_required_alias_and_validation_alias_by_name(path: str):
|
||||||
|
|
||||||
|
|
||||||
@needs_pydanticv2
|
@needs_pydanticv2
|
||||||
@pytest.mark.xfail(raises=AssertionError, strict=False)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
|
@ -455,9 +421,7 @@ def test_required_alias_and_validation_alias_by_name(path: str):
|
||||||
def test_required_alias_and_validation_alias_by_alias(path: str):
|
def test_required_alias_and_validation_alias_by_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(f"{path}?p_alias=hello")
|
response = client.get(f"{path}?p_alias=hello")
|
||||||
assert (
|
assert response.status_code == 422
|
||||||
response.status_code == 422 # /required-alias-and-validation-alias fails here
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"detail": [
|
"detail": [
|
||||||
|
|
@ -465,7 +429,7 @@ def test_required_alias_and_validation_alias_by_alias(path: str):
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": ["query", "p_val_alias"],
|
"loc": ["query", "p_val_alias"],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": IsOneOf( # /model-alias-and-validation-alias fails here
|
"input": IsOneOf(
|
||||||
None,
|
None,
|
||||||
{"p_alias": "hello"},
|
{"p_alias": "hello"},
|
||||||
),
|
),
|
||||||
|
|
@ -478,18 +442,13 @@ def test_required_alias_and_validation_alias_by_alias(path: str):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
pytest.param(
|
"/required-alias-and-validation-alias",
|
||||||
"/required-alias-and-validation-alias",
|
|
||||||
marks=pytest.mark.xfail(raises=AssertionError, strict=False),
|
|
||||||
),
|
|
||||||
"/model-required-alias-and-validation-alias",
|
"/model-required-alias-and-validation-alias",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_required_alias_and_validation_alias_by_validation_alias(path: str):
|
def test_required_alias_and_validation_alias_by_validation_alias(path: str):
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
response = client.get(f"{path}?p_val_alias=hello")
|
response = client.get(f"{path}?p_val_alias=hello")
|
||||||
assert response.status_code == 200, (
|
assert response.status_code == 200, response.text
|
||||||
response.text # /required-alias-and-validation-alias fails here
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.json() == {"p": "hello"}
|
assert response.json() == {"p": "hello"}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue