🔥 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

@@ -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(