🔥 Remove Pydantic v1 specific test variants (#14611)

This commit is contained in:
Sebastián Ramírez
2025-12-27 10:19:10 -08:00
committed by GitHub
parent 8322a4445a
commit 44c849c4fc
104 changed files with 4139 additions and 8074 deletions

View File

@@ -148,29 +148,16 @@ def test_required_list_alias_missing(path: str, json: Union[dict, None]):
client = TestClient(app)
response = client.post(path, json=json)
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": IsOneOf(["body", "p_alias"], ["body"]),
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": IsOneOf(["body", "p_alias"], ["body"]),
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": IsOneOf(["body", "p_alias"], ["body"]),
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
@pytest.mark.parametrize(
@@ -181,29 +168,16 @@ def test_required_list_alias_by_name(path: str):
client = TestClient(app)
response = client.post(path, json={"p": ["hello", "world"]})
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {"p": ["hello", "world"]}),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {"p": ["hello", "world"]}),
}
]
}
@pytest.mark.parametrize(

View File

@@ -1,7 +1,6 @@
from typing import Annotated, Optional
import pytest
from dirty_equals import IsDict
from fastapi import Body, FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field
@@ -38,30 +37,19 @@ def test_optional_list_str_schema(path: str):
openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict(
{
"properties": {
"p": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P",
},
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P",
},
"title": body_model_name,
"type": "object",
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"properties": {
"p": {"items": {"type": "string"}, "type": "array", "title": "P"},
},
"title": body_model_name,
"type": "object",
}
)
},
"title": body_model_name,
"type": "object",
}
def test_optional_list_str_missing():
@@ -75,29 +63,16 @@ def test_model_optional_list_str_missing():
client = TestClient(app)
response = client.post("/model-optional-list-str")
assert response.status_code == 422, response.text
assert response.json() == IsDict(
{
"detail": [
{
"input": None,
"loc": ["body"],
"msg": "Field required",
"type": "missing",
},
],
}
) | IsDict(
{
# TODO: remove when deprecating Pydantic v1
"detail": [
{
"loc": ["body"],
"msg": "field required",
"type": "value_error.missing",
},
],
}
)
assert response.json() == {
"detail": [
{
"input": None,
"loc": ["body"],
"msg": "Field required",
"type": "missing",
},
],
}
@pytest.mark.parametrize(
@@ -153,34 +128,19 @@ def test_optional_list_str_alias_schema(path: str):
openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict(
{
"properties": {
"p_alias": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P Alias",
},
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p_alias": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P Alias",
},
"title": body_model_name,
"type": "object",
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"properties": {
"p_alias": {
"items": {"type": "string"},
"type": "array",
"title": "P Alias",
},
},
"title": body_model_name,
"type": "object",
}
)
},
"title": body_model_name,
"type": "object",
}
def test_optional_list_alias_missing():
@@ -194,29 +154,16 @@ def test_model_optional_list_alias_missing():
client = TestClient(app)
response = client.post("/model-optional-list-alias")
assert response.status_code == 422, response.text
assert response.json() == IsDict(
{
"detail": [
{
"input": None,
"loc": ["body"],
"msg": "Field required",
"type": "missing",
},
],
}
) | IsDict(
{
# TODO: remove when deprecating Pydantic v1
"detail": [
{
"loc": ["body"],
"msg": "field required",
"type": "value_error.missing",
},
],
}
)
assert response.json() == {
"detail": [
{
"input": None,
"loc": ["body"],
"msg": "Field required",
"type": "missing",
},
],
}
@pytest.mark.parametrize(
@@ -289,34 +236,19 @@ def test_optional_list_validation_alias_schema(path: str):
openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict(
{
"properties": {
"p_val_alias": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P Val Alias",
},
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p_val_alias": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P Val Alias",
},
"title": body_model_name,
"type": "object",
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"properties": {
"p_val_alias": {
"items": {"type": "string"},
"type": "array",
"title": "P Val Alias",
},
},
"title": body_model_name,
"type": "object",
}
)
},
"title": body_model_name,
"type": "object",
}
def test_optional_list_validation_alias_missing():
@@ -330,29 +262,16 @@ def test_model_optional_list_validation_alias_missing():
client = TestClient(app)
response = client.post("/model-optional-list-validation-alias")
assert response.status_code == 422, response.text
assert response.json() == IsDict(
{
"detail": [
{
"input": None,
"loc": ["body"],
"msg": "Field required",
"type": "missing",
},
],
}
) | IsDict(
{
# TODO: remove when deprecating Pydantic v1
"detail": [
{
"loc": ["body"],
"msg": "field required",
"type": "value_error.missing",
},
],
}
)
assert response.json() == {
"detail": [
{
"input": None,
"loc": ["body"],
"msg": "Field required",
"type": "missing",
},
],
}
@pytest.mark.parametrize(
@@ -438,34 +357,19 @@ def test_optional_list_alias_and_validation_alias_schema(path: str):
openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict(
{
"properties": {
"p_val_alias": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P Val Alias",
},
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p_val_alias": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P Val Alias",
},
"title": body_model_name,
"type": "object",
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"properties": {
"p_val_alias": {
"items": {"type": "string"},
"type": "array",
"title": "P Val Alias",
},
},
"title": body_model_name,
"type": "object",
}
)
},
"title": body_model_name,
"type": "object",
}
def test_optional_list_alias_and_validation_alias_missing():
@@ -479,29 +383,16 @@ def test_model_optional_list_alias_and_validation_alias_missing():
client = TestClient(app)
response = client.post("/model-optional-list-alias-and-validation-alias")
assert response.status_code == 422, response.text
assert response.json() == IsDict(
{
"detail": [
{
"input": None,
"loc": ["body"],
"msg": "Field required",
"type": "missing",
},
],
}
) | IsDict(
{
# TODO: remove when deprecating Pydantic v1
"detail": [
{
"loc": ["body"],
"msg": "field required",
"type": "value_error.missing",
},
],
}
)
assert response.json() == {
"detail": [
{
"input": None,
"loc": ["body"],
"msg": "Field required",
"type": "missing",
},
],
}
@pytest.mark.parametrize(

View File

@@ -1,7 +1,6 @@
from typing import Annotated, Optional
import pytest
from dirty_equals import IsDict
from fastapi import Body, FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field
@@ -36,27 +35,16 @@ def test_optional_str_schema(path: str):
openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict(
{
"properties": {
"p": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P",
},
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P",
},
"title": body_model_name,
"type": "object",
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"properties": {
"p": {"type": "string", "title": "P"},
},
"title": body_model_name,
"type": "object",
}
)
},
"title": body_model_name,
"type": "object",
}
def test_optional_str_missing():
@@ -70,29 +58,16 @@ def test_model_optional_str_missing():
client = TestClient(app)
response = client.post("/model-optional-str")
assert response.status_code == 422, response.text
assert response.json() == IsDict(
{
"detail": [
{
"input": None,
"loc": ["body"],
"msg": "Field required",
"type": "missing",
},
],
}
) | IsDict(
{
# TODO: remove when deprecating Pydantic v1
"detail": [
{
"loc": ["body"],
"msg": "field required",
"type": "value_error.missing",
},
],
}
)
assert response.json() == {
"detail": [
{
"input": None,
"loc": ["body"],
"msg": "Field required",
"type": "missing",
},
],
}
@pytest.mark.parametrize(
@@ -148,27 +123,16 @@ def test_optional_str_alias_schema(path: str):
openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict(
{
"properties": {
"p_alias": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P Alias",
},
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p_alias": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P Alias",
},
"title": body_model_name,
"type": "object",
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"properties": {
"p_alias": {"type": "string", "title": "P Alias"},
},
"title": body_model_name,
"type": "object",
}
)
},
"title": body_model_name,
"type": "object",
}
def test_optional_alias_missing():
@@ -182,29 +146,16 @@ def test_model_optional_alias_missing():
client = TestClient(app)
response = client.post("/model-optional-alias")
assert response.status_code == 422, response.text
assert response.json() == IsDict(
{
"detail": [
{
"input": None,
"loc": ["body"],
"msg": "Field required",
"type": "missing",
},
],
}
) | IsDict(
{
# TODO: remove when deprecating Pydantic v1
"detail": [
{
"loc": ["body"],
"msg": "field required",
"type": "value_error.missing",
},
],
}
)
assert response.json() == {
"detail": [
{
"input": None,
"loc": ["body"],
"msg": "Field required",
"type": "missing",
},
],
}
@pytest.mark.parametrize(
@@ -274,27 +225,16 @@ def test_optional_validation_alias_schema(path: str):
openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict(
{
"properties": {
"p_val_alias": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P Val Alias",
},
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p_val_alias": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P Val Alias",
},
"title": body_model_name,
"type": "object",
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"properties": {
"p_val_alias": {"type": "string", "title": "P Val Alias"},
},
"title": body_model_name,
"type": "object",
}
)
},
"title": body_model_name,
"type": "object",
}
def test_optional_validation_alias_missing():
@@ -308,29 +248,16 @@ def test_model_optional_validation_alias_missing():
client = TestClient(app)
response = client.post("/model-optional-validation-alias")
assert response.status_code == 422, response.text
assert response.json() == IsDict(
{
"detail": [
{
"input": None,
"loc": ["body"],
"msg": "Field required",
"type": "missing",
},
],
}
) | IsDict(
{
# TODO: remove when deprecating Pydantic v1
"detail": [
{
"loc": ["body"],
"msg": "field required",
"type": "value_error.missing",
},
],
}
)
assert response.json() == {
"detail": [
{
"input": None,
"loc": ["body"],
"msg": "Field required",
"type": "missing",
},
],
}
@pytest.mark.parametrize(
@@ -413,27 +340,16 @@ def test_optional_alias_and_validation_alias_schema(path: str):
openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict(
{
"properties": {
"p_val_alias": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P Val Alias",
},
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p_val_alias": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P Val Alias",
},
"title": body_model_name,
"type": "object",
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"properties": {
"p_val_alias": {"type": "string", "title": "P Val Alias"},
},
"title": body_model_name,
"type": "object",
}
)
},
"title": body_model_name,
"type": "object",
}
def test_optional_alias_and_validation_alias_missing():
@@ -447,29 +363,16 @@ def test_model_optional_alias_and_validation_alias_missing():
client = TestClient(app)
response = client.post("/model-optional-alias-and-validation-alias")
assert response.status_code == 422, response.text
assert response.json() == IsDict(
{
"detail": [
{
"input": None,
"loc": ["body"],
"msg": "Field required",
"type": "missing",
},
],
}
) | IsDict(
{
# TODO: remove when deprecating Pydantic v1
"detail": [
{
"loc": ["body"],
"msg": "field required",
"type": "value_error.missing",
},
],
}
)
assert response.json() == {
"detail": [
{
"input": None,
"loc": ["body"],
"msg": "Field required",
"type": "missing",
},
],
}
@pytest.mark.parametrize(

View File

@@ -1,7 +1,7 @@
from typing import Annotated, Any, Union
import pytest
from dirty_equals import IsDict, IsOneOf
from dirty_equals import IsOneOf
from fastapi import Body, FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field
@@ -55,29 +55,16 @@ def test_required_str_missing(path: str, json: Union[dict[str, Any], None]):
client = TestClient(app)
response = client.post(path, json=json)
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": IsOneOf(["body"], ["body", "p"]),
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": IsOneOf(["body"], ["body", "p"]),
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": IsOneOf(["body"], ["body", "p"]),
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
@pytest.mark.parametrize(
@@ -141,29 +128,16 @@ def test_required_alias_missing(path: str, json: Union[dict[str, Any], None]):
client = TestClient(app)
response = client.post(path, json=json)
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": IsOneOf(["body", "p_alias"], ["body"]),
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": IsOneOf(["body", "p_alias"], ["body"]),
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": IsOneOf(["body", "p_alias"], ["body"]),
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
@pytest.mark.parametrize(
@@ -174,29 +148,16 @@ def test_required_alias_by_name(path: str):
client = TestClient(app)
response = client.post(path, json={"p": "hello"})
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {"p": "hello"}),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": IsOneOf(["body", "p_alias"], ["body"]),
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {"p": "hello"}),
}
]
}
@pytest.mark.parametrize(

View File

@@ -1,7 +1,6 @@
from typing import Annotated, Optional
import pytest
from dirty_equals import IsDict
from fastapi import Cookie, FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field
@@ -32,26 +31,15 @@ async def read_model_optional_str(p: Annotated[CookieModelOptionalStr, Cookie()]
)
def test_optional_str_schema(path: str):
assert app.openapi()["paths"][path]["get"]["parameters"] == [
IsDict(
{
"required": False,
"schema": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P",
},
"name": "p",
"in": "cookie",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"required": False,
"schema": {"title": "P", "type": "string"},
"name": "p",
"in": "cookie",
}
)
{
"required": False,
"schema": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P",
},
"name": "p",
"in": "cookie",
}
]
@@ -104,26 +92,15 @@ async def read_model_optional_alias(p: Annotated[CookieModelOptionalAlias, Cooki
)
def test_optional_str_alias_schema(path: str):
assert app.openapi()["paths"][path]["get"]["parameters"] == [
IsDict(
{
"required": False,
"schema": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P Alias",
},
"name": "p_alias",
"in": "cookie",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"required": False,
"schema": {"title": "P Alias", "type": "string"},
"name": "p_alias",
"in": "cookie",
}
)
{
"required": False,
"schema": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P Alias",
},
"name": "p_alias",
"in": "cookie",
}
]

View File

@@ -1,7 +1,7 @@
from typing import Annotated
import pytest
from dirty_equals import IsDict, IsOneOf
from dirty_equals import IsOneOf
from fastapi import Cookie, FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field
@@ -49,29 +49,16 @@ def test_required_str_missing(path: str):
client = TestClient(app)
response = client.get(path)
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["cookie", "p"],
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["cookie", "p"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["cookie", "p"],
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
@pytest.mark.parametrize(
@@ -127,29 +114,16 @@ def test_required_alias_missing(path: str):
client = TestClient(app)
response = client.get(path)
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["cookie", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["cookie", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["cookie", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
@pytest.mark.parametrize(
@@ -164,32 +138,19 @@ def test_required_alias_by_name(path: str):
client.cookies.set("p", "hello")
response = client.get(path)
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["cookie", "p_alias"],
"msg": "Field required",
"input": IsOneOf(
None,
{"p": "hello"},
),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["cookie", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["cookie", "p_alias"],
"msg": "Field required",
"input": IsOneOf(
None,
{"p": "hello"},
),
}
]
}
@pytest.mark.parametrize(

View File

@@ -75,29 +75,16 @@ def test_list_missing(path: str):
client = TestClient(app)
response = client.post(path)
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["body", "p"],
"msg": "Field required",
"input": None,
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["body", "p"],
"msg": "Field required",
"input": None,
}
]
}
@pytest.mark.parametrize(
@@ -182,29 +169,16 @@ def test_list_alias_missing(path: str):
client = TestClient(app)
response = client.post(path)
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": None,
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": None,
}
]
}
@pytest.mark.parametrize(
@@ -218,29 +192,16 @@ def test_list_alias_by_name(path: str):
client = TestClient(app)
response = client.post(path, files=[("p", b"hello"), ("p", b"world")])
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": None,
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": None,
}
]
}
@pytest.mark.parametrize(

View File

@@ -1,7 +1,6 @@
from typing import Annotated, Optional
import pytest
from dirty_equals import IsDict
from fastapi import FastAPI, File, UploadFile
from fastapi.testclient import TestClient
@@ -36,21 +35,13 @@ def test_optional_schema(path: str):
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p": (
IsDict(
{
"anyOf": [
{"type": "string", "format": "binary"},
{"type": "null"},
],
"title": "P",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "P", "type": "string", "format": "binary"}
)
),
"p": {
"anyOf": [
{"type": "string", "format": "binary"},
{"type": "null"},
],
"title": "P",
}
},
"title": body_model_name,
"type": "object",
@@ -116,21 +107,13 @@ def test_optional_alias_schema(path: str):
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p_alias": (
IsDict(
{
"anyOf": [
{"type": "string", "format": "binary"},
{"type": "null"},
],
"title": "P Alias",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "P Alias", "type": "string", "format": "binary"}
)
),
"p_alias": {
"anyOf": [
{"type": "string", "format": "binary"},
{"type": "null"},
],
"title": "P Alias",
}
},
"title": body_model_name,
"type": "object",
@@ -215,21 +198,13 @@ def test_optional_validation_alias_schema(path: str):
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p_val_alias": (
IsDict(
{
"anyOf": [
{"type": "string", "format": "binary"},
{"type": "null"},
],
"title": "P Val Alias",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "P Val Alias", "type": "string", "format": "binary"}
)
),
"p_val_alias": {
"anyOf": [
{"type": "string", "format": "binary"},
{"type": "null"},
],
"title": "P Val Alias",
}
},
"title": body_model_name,
"type": "object",
@@ -319,21 +294,13 @@ def test_optional_alias_and_validation_alias_schema(path: str):
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p_val_alias": (
IsDict(
{
"anyOf": [
{"type": "string", "format": "binary"},
{"type": "null"},
],
"title": "P Val Alias",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "P Val Alias", "type": "string", "format": "binary"}
)
),
"p_val_alias": {
"anyOf": [
{"type": "string", "format": "binary"},
{"type": "null"},
],
"title": "P Val Alias",
}
},
"title": body_model_name,
"type": "object",

View File

@@ -1,7 +1,6 @@
from typing import Annotated, Optional
import pytest
from dirty_equals import IsDict
from fastapi import FastAPI, File, UploadFile
from fastapi.testclient import TestClient
@@ -38,28 +37,16 @@ def test_optional_list_schema(path: str):
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p": (
IsDict(
"p": {
"anyOf": [
{
"anyOf": [
{
"type": "array",
"items": {"type": "string", "format": "binary"},
},
{"type": "null"},
],
"title": "P",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "P",
"type": "array",
"items": {"type": "string", "format": "binary"},
},
)
),
{"type": "null"},
],
"title": "P",
}
},
"title": body_model_name,
"type": "object",
@@ -125,28 +112,16 @@ def test_optional_list_alias_schema(path: str):
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p_alias": (
IsDict(
"p_alias": {
"anyOf": [
{
"anyOf": [
{
"type": "array",
"items": {"type": "string", "format": "binary"},
},
{"type": "null"},
],
"title": "P Alias",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "P Alias",
"type": "array",
"items": {"type": "string", "format": "binary"},
}
)
),
},
{"type": "null"},
],
"title": "P Alias",
}
},
"title": body_model_name,
"type": "object",
@@ -228,28 +203,16 @@ def test_optional_validation_alias_schema(path: str):
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p_val_alias": (
IsDict(
"p_val_alias": {
"anyOf": [
{
"anyOf": [
{
"type": "array",
"items": {"type": "string", "format": "binary"},
},
{"type": "null"},
],
"title": "P Val Alias",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "P Val Alias",
"type": "array",
"items": {"type": "string", "format": "binary"},
}
)
),
},
{"type": "null"},
],
"title": "P Val Alias",
}
},
"title": body_model_name,
"type": "object",
@@ -336,28 +299,16 @@ def test_optional_list_alias_and_validation_alias_schema(path: str):
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p_val_alias": (
IsDict(
"p_val_alias": {
"anyOf": [
{
"anyOf": [
{
"type": "array",
"items": {"type": "string", "format": "binary"},
},
{"type": "null"},
],
"title": "P Val Alias",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "P Val Alias",
"type": "array",
"items": {"type": "string", "format": "binary"},
}
)
),
},
{"type": "null"},
],
"title": "P Val Alias",
}
},
"title": body_model_name,
"type": "object",

View File

@@ -1,7 +1,6 @@
from typing import Annotated
import pytest
from dirty_equals import IsDict
from fastapi import FastAPI, File, UploadFile
from fastapi.testclient import TestClient
@@ -55,29 +54,16 @@ def test_required_missing(path: str):
client = TestClient(app)
response = client.post(path)
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["body", "p"],
"msg": "Field required",
"input": None,
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["body", "p"],
"msg": "Field required",
"input": None,
}
]
}
@pytest.mark.parametrize(
@@ -142,29 +128,16 @@ def test_required_alias_missing(path: str):
client = TestClient(app)
response = client.post(path)
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": None,
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": None,
}
]
}
@pytest.mark.parametrize(
@@ -178,29 +151,16 @@ def test_required_alias_by_name(path: str):
client = TestClient(app)
response = client.post(path, files=[("p", b"hello")])
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": None,
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": None,
}
]
}
@pytest.mark.parametrize(

View File

@@ -146,29 +146,16 @@ def test_required_list_alias_missing(path: str):
client = TestClient(app)
response = client.post(path)
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
@pytest.mark.parametrize(
@@ -182,29 +169,16 @@ def test_required_list_alias_by_name(path: str):
client = TestClient(app)
response = client.post(path, data={"p": ["hello", "world"]})
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {"p": ["hello", "world"]}),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {"p": ["hello", "world"]}),
}
]
}
@pytest.mark.parametrize(

View File

@@ -1,7 +1,6 @@
from typing import Annotated, Optional
import pytest
from dirty_equals import IsDict
from fastapi import FastAPI, Form
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field
@@ -38,30 +37,19 @@ def test_optional_list_str_schema(path: str):
openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict(
{
"properties": {
"p": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P",
},
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P",
},
"title": body_model_name,
"type": "object",
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"properties": {
"p": {"items": {"type": "string"}, "type": "array", "title": "P"},
},
"title": body_model_name,
"type": "object",
}
)
},
"title": body_model_name,
"type": "object",
}
@pytest.mark.parametrize(
@@ -119,34 +107,19 @@ def test_optional_list_str_alias_schema(path: str):
openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict(
{
"properties": {
"p_alias": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P Alias",
},
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p_alias": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P Alias",
},
"title": body_model_name,
"type": "object",
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"properties": {
"p_alias": {
"items": {"type": "string"},
"type": "array",
"title": "P Alias",
},
},
"title": body_model_name,
"type": "object",
}
)
},
"title": body_model_name,
"type": "object",
}
@pytest.mark.parametrize(
@@ -217,34 +190,19 @@ def test_optional_list_validation_alias_schema(path: str):
openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict(
{
"properties": {
"p_val_alias": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P Val Alias",
},
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p_val_alias": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P Val Alias",
},
"title": body_model_name,
"type": "object",
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"properties": {
"p_val_alias": {
"items": {"type": "string"},
"type": "array",
"title": "P Val Alias",
},
},
"title": body_model_name,
"type": "object",
}
)
},
"title": body_model_name,
"type": "object",
}
@pytest.mark.parametrize(
@@ -326,34 +284,19 @@ def test_optional_list_alias_and_validation_alias_schema(path: str):
openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict(
{
"properties": {
"p_val_alias": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P Val Alias",
},
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p_val_alias": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P Val Alias",
},
"title": body_model_name,
"type": "object",
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"properties": {
"p_val_alias": {
"items": {"type": "string"},
"type": "array",
"title": "P Val Alias",
},
},
"title": body_model_name,
"type": "object",
}
)
},
"title": body_model_name,
"type": "object",
}
@pytest.mark.parametrize(

View File

@@ -1,7 +1,6 @@
from typing import Annotated, Optional
import pytest
from dirty_equals import IsDict
from fastapi import FastAPI, Form
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field
@@ -36,27 +35,16 @@ def test_optional_str_schema(path: str):
openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict(
{
"properties": {
"p": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P",
},
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P",
},
"title": body_model_name,
"type": "object",
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"properties": {
"p": {"type": "string", "title": "P"},
},
"title": body_model_name,
"type": "object",
}
)
},
"title": body_model_name,
"type": "object",
}
@pytest.mark.parametrize(
@@ -112,27 +100,16 @@ def test_optional_str_alias_schema(path: str):
openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict(
{
"properties": {
"p_alias": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P Alias",
},
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p_alias": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P Alias",
},
"title": body_model_name,
"type": "object",
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"properties": {
"p_alias": {"type": "string", "title": "P Alias"},
},
"title": body_model_name,
"type": "object",
}
)
},
"title": body_model_name,
"type": "object",
}
@pytest.mark.parametrize(
@@ -200,27 +177,16 @@ def test_optional_validation_alias_schema(path: str):
openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict(
{
"properties": {
"p_val_alias": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P Val Alias",
},
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p_val_alias": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P Val Alias",
},
"title": body_model_name,
"type": "object",
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"properties": {
"p_val_alias": {"type": "string", "title": "P Val Alias"},
},
"title": body_model_name,
"type": "object",
}
)
},
"title": body_model_name,
"type": "object",
}
@pytest.mark.parametrize(
@@ -303,27 +269,16 @@ def test_optional_alias_and_validation_alias_schema(path: str):
openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict(
{
"properties": {
"p_val_alias": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P Val Alias",
},
assert app.openapi()["components"]["schemas"][body_model_name] == {
"properties": {
"p_val_alias": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P Val Alias",
},
"title": body_model_name,
"type": "object",
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"properties": {
"p_val_alias": {"type": "string", "title": "P Val Alias"},
},
"title": body_model_name,
"type": "object",
}
)
},
"title": body_model_name,
"type": "object",
}
@pytest.mark.parametrize(

View File

@@ -1,7 +1,7 @@
from typing import Annotated
import pytest
from dirty_equals import IsDict, IsOneOf
from dirty_equals import IsOneOf
from fastapi import FastAPI, Form
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field
@@ -54,29 +54,16 @@ def test_required_str_missing(path: str):
client = TestClient(app)
response = client.post(path)
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["body", "p"],
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["body", "p"],
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
@pytest.mark.parametrize(
@@ -137,29 +124,16 @@ def test_required_alias_missing(path: str):
client = TestClient(app)
response = client.post(path)
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
@pytest.mark.parametrize(
@@ -170,29 +144,16 @@ def test_required_alias_by_name(path: str):
client = TestClient(app)
response = client.post(path, data={"p": "hello"})
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {"p": "hello"}),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["body", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {"p": "hello"}),
}
]
}
@pytest.mark.parametrize(

View File

@@ -135,29 +135,16 @@ def test_required_list_alias_missing(path: str):
client = TestClient(app)
response = client.get(path)
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["header", "p_alias"],
"msg": "Field required",
"input": AnyThing,
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["header", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["header", "p_alias"],
"msg": "Field required",
"input": AnyThing,
}
]
}
@pytest.mark.parametrize(
@@ -171,29 +158,16 @@ def test_required_list_alias_by_name(path: str):
client = TestClient(app)
response = client.get(path, headers=[("p", "hello"), ("p", "world")])
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["header", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, IsPartialDict({"p": ["hello", "world"]})),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["header", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["header", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, IsPartialDict({"p": ["hello", "world"]})),
}
]
}
@pytest.mark.parametrize(

View File

@@ -1,7 +1,6 @@
from typing import Annotated, Optional
import pytest
from dirty_equals import IsDict
from fastapi import FastAPI, Header
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field
@@ -36,29 +35,18 @@ async def read_model_optional_list_str(
)
def test_optional_list_str_schema(path: str):
assert app.openapi()["paths"][path]["get"]["parameters"] == [
IsDict(
{
"required": False,
"schema": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P",
},
"name": "p",
"in": "header",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"required": False,
"schema": {"items": {"type": "string"}, "type": "array", "title": "P"},
"name": "p",
"in": "header",
}
)
{
"required": False,
"schema": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P",
},
"name": "p",
"in": "header",
}
]
@@ -112,33 +100,18 @@ async def read_model_optional_list_alias(
)
def test_optional_list_str_alias_schema(path: str):
assert app.openapi()["paths"][path]["get"]["parameters"] == [
IsDict(
{
"required": False,
"schema": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P Alias",
},
"name": "p_alias",
"in": "header",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"required": False,
"schema": {
"items": {"type": "string"},
"type": "array",
"title": "P Alias",
},
"name": "p_alias",
"in": "header",
}
)
{
"required": False,
"schema": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P Alias",
},
"name": "p_alias",
"in": "header",
}
]

View File

@@ -1,7 +1,6 @@
from typing import Annotated, Optional
import pytest
from dirty_equals import IsDict
from fastapi import FastAPI, Header
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field
@@ -32,26 +31,15 @@ async def read_model_optional_str(p: Annotated[HeaderModelOptionalStr, Header()]
)
def test_optional_str_schema(path: str):
assert app.openapi()["paths"][path]["get"]["parameters"] == [
IsDict(
{
"required": False,
"schema": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P",
},
"name": "p",
"in": "header",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"required": False,
"schema": {"title": "P", "type": "string"},
"name": "p",
"in": "header",
}
)
{
"required": False,
"schema": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P",
},
"name": "p",
"in": "header",
}
]
@@ -103,26 +91,15 @@ async def read_model_optional_alias(p: Annotated[HeaderModelOptionalAlias, Heade
)
def test_optional_str_alias_schema(path: str):
assert app.openapi()["paths"][path]["get"]["parameters"] == [
IsDict(
{
"required": False,
"schema": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P Alias",
},
"name": "p_alias",
"in": "header",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"required": False,
"schema": {"title": "P Alias", "type": "string"},
"name": "p_alias",
"in": "header",
}
)
{
"required": False,
"schema": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P Alias",
},
"name": "p_alias",
"in": "header",
}
]

View File

@@ -1,7 +1,7 @@
from typing import Annotated
import pytest
from dirty_equals import AnyThing, IsDict, IsOneOf, IsPartialDict
from dirty_equals import AnyThing, IsOneOf, IsPartialDict
from fastapi import FastAPI, Header
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field
@@ -49,29 +49,16 @@ def test_required_str_missing(path: str):
client = TestClient(app)
response = client.get(path)
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["header", "p"],
"msg": "Field required",
"input": AnyThing,
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["header", "p"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["header", "p"],
"msg": "Field required",
"input": AnyThing,
}
]
}
@pytest.mark.parametrize(
@@ -126,29 +113,16 @@ def test_required_alias_missing(path: str):
client = TestClient(app)
response = client.get(path)
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["header", "p_alias"],
"msg": "Field required",
"input": AnyThing,
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["header", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["header", "p_alias"],
"msg": "Field required",
"input": AnyThing,
}
]
}
@pytest.mark.parametrize(
@@ -162,29 +136,16 @@ def test_required_alias_by_name(path: str):
client = TestClient(app)
response = client.get(path, headers={"p": "hello"})
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["header", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, IsPartialDict({"p": "hello"})),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["header", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["header", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, IsPartialDict({"p": "hello"})),
}
]
}
@pytest.mark.parametrize(

View File

@@ -135,29 +135,16 @@ def test_required_list_alias_missing(path: str):
client = TestClient(app)
response = client.get(path)
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["query", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["query", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
@pytest.mark.parametrize(
@@ -171,29 +158,16 @@ def test_required_list_alias_by_name(path: str):
client = TestClient(app)
response = client.get(f"{path}?p=hello&p=world")
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["query", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {"p": ["hello", "world"]}),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["query", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {"p": ["hello", "world"]}),
}
]
}
@pytest.mark.parametrize(

View File

@@ -1,7 +1,6 @@
from typing import Annotated, Optional
import pytest
from dirty_equals import IsDict
from fastapi import FastAPI, Query
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field
@@ -36,29 +35,18 @@ async def read_model_optional_list_str(
)
def test_optional_list_str_schema(path: str):
assert app.openapi()["paths"][path]["get"]["parameters"] == [
IsDict(
{
"required": False,
"schema": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P",
},
"name": "p",
"in": "query",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"required": False,
"schema": {"items": {"type": "string"}, "type": "array", "title": "P"},
"name": "p",
"in": "query",
}
)
{
"required": False,
"schema": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P",
},
"name": "p",
"in": "query",
}
]
@@ -112,33 +100,18 @@ async def read_model_optional_list_alias(
)
def test_optional_list_str_alias_schema(path: str):
assert app.openapi()["paths"][path]["get"]["parameters"] == [
IsDict(
{
"required": False,
"schema": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P Alias",
},
"name": "p_alias",
"in": "query",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"required": False,
"schema": {
"items": {"type": "string"},
"type": "array",
"title": "P Alias",
},
"name": "p_alias",
"in": "query",
}
)
{
"required": False,
"schema": {
"anyOf": [
{"items": {"type": "string"}, "type": "array"},
{"type": "null"},
],
"title": "P Alias",
},
"name": "p_alias",
"in": "query",
}
]

View File

@@ -1,7 +1,6 @@
from typing import Annotated, Optional
import pytest
from dirty_equals import IsDict
from fastapi import FastAPI, Query
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field
@@ -32,26 +31,15 @@ async def read_model_optional_str(p: Annotated[QueryModelOptionalStr, Query()]):
)
def test_optional_str_schema(path: str):
assert app.openapi()["paths"][path]["get"]["parameters"] == [
IsDict(
{
"required": False,
"schema": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P",
},
"name": "p",
"in": "query",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"required": False,
"schema": {"title": "P", "type": "string"},
"name": "p",
"in": "query",
}
)
{
"required": False,
"schema": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P",
},
"name": "p",
"in": "query",
}
]
@@ -103,26 +91,15 @@ async def read_model_optional_alias(p: Annotated[QueryModelOptionalAlias, Query(
)
def test_optional_str_alias_schema(path: str):
assert app.openapi()["paths"][path]["get"]["parameters"] == [
IsDict(
{
"required": False,
"schema": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P Alias",
},
"name": "p_alias",
"in": "query",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"required": False,
"schema": {"title": "P Alias", "type": "string"},
"name": "p_alias",
"in": "query",
}
)
{
"required": False,
"schema": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "P Alias",
},
"name": "p_alias",
"in": "query",
}
]

View File

@@ -1,7 +1,7 @@
from typing import Annotated
import pytest
from dirty_equals import IsDict, IsOneOf
from dirty_equals import IsOneOf
from fastapi import FastAPI, Query
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field
@@ -49,29 +49,16 @@ def test_required_str_missing(path: str):
client = TestClient(app)
response = client.get(path)
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["query", "p"],
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "p"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["query", "p"],
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
@pytest.mark.parametrize(
@@ -126,29 +113,16 @@ def test_required_alias_missing(path: str):
client = TestClient(app)
response = client.get(path)
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["query", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["query", "p_alias"],
"msg": "Field required",
"input": IsOneOf(None, {}),
}
]
}
@pytest.mark.parametrize(
@@ -162,32 +136,19 @@ def test_required_alias_by_name(path: str):
client = TestClient(app)
response = client.get(f"{path}?p=hello")
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "missing",
"loc": ["query", "p_alias"],
"msg": "Field required",
"input": IsOneOf(
None,
{"p": "hello"},
),
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
assert response.json() == {
"detail": [
{
"type": "missing",
"loc": ["query", "p_alias"],
"msg": "Field required",
"input": IsOneOf(
None,
{"p": "hello"},
),
}
]
}
@pytest.mark.parametrize(