🔥 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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
104 changed files with 4139 additions and 8074 deletions

View File

@ -1,6 +1,5 @@
from typing import Union from typing import Union
from dirty_equals import IsDict
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from pydantic import BaseModel, ConfigDict from pydantic import BaseModel, ConfigDict
@ -52,19 +51,13 @@ def test_openapi_schema():
"requestBody": { "requestBody": {
"content": { "content": {
"application/json": { "application/json": {
"schema": IsDict( "schema": {
{
"anyOf": [ "anyOf": [
{"$ref": "#/components/schemas/Foo"}, {"$ref": "#/components/schemas/Foo"},
{"type": "null"}, {"type": "null"},
], ],
"title": "Foo", "title": "Foo",
} }
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"$ref": "#/components/schemas/Foo"}
)
} }
} }
}, },

View File

@ -1,6 +1,6 @@
from dirty_equals import IsDict
from fastapi import APIRouter, FastAPI from fastapi import APIRouter, FastAPI
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from pydantic import BaseModel, HttpUrl from pydantic import BaseModel, HttpUrl
from starlette.responses import JSONResponse from starlette.responses import JSONResponse
@ -32,7 +32,8 @@ client = TestClient(app)
def test_openapi_schema(): def test_openapi_schema():
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.json() == { assert response.json() == snapshot(
{
"openapi": "3.1.0", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
@ -43,24 +44,13 @@ def test_openapi_schema():
"parameters": [ "parameters": [
{ {
"required": True, "required": True,
"schema": IsDict( "schema": {
{
"title": "Callback Url",
"minLength": 1,
"type": "string",
"format": "uri",
}
)
# TODO: remove when deprecating Pydantic v1
| IsDict(
{
"title": "Callback Url", "title": "Callback Url",
"maxLength": 2083, "maxLength": 2083,
"minLength": 1, "minLength": 1,
"type": "string", "type": "string",
"format": "uri", "format": "uri",
} },
),
"name": "callback_url", "name": "callback_url",
"in": "query", "in": "query",
} }
@ -127,7 +117,9 @@ def test_openapi_schema():
"detail": { "detail": {
"title": "Detail", "title": "Detail",
"type": "array", "type": "array",
"items": {"$ref": "#/components/schemas/ValidationError"}, "items": {
"$ref": "#/components/schemas/ValidationError"
},
} }
}, },
}, },
@ -150,3 +142,4 @@ def test_openapi_schema():
} }
}, },
} }
)

View File

@ -1,7 +1,6 @@
from typing import Annotated from typing import Annotated
import pytest import pytest
from dirty_equals import IsDict
from fastapi import APIRouter, FastAPI, Query from fastapi import APIRouter, FastAPI, Query
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -32,27 +31,16 @@ client = TestClient(app)
foo_is_missing = { foo_is_missing = {
"detail": [ "detail": [
IsDict(
{ {
"loc": ["query", "foo"], "loc": ["query", "foo"],
"msg": "Field required", "msg": "Field required",
"type": "missing", "type": "missing",
"input": None, "input": None,
} }
)
# TODO: remove when deprecating Pydantic v1
| IsDict(
{
"loc": ["query", "foo"],
"msg": "field required",
"type": "value_error.missing",
}
)
] ]
} }
foo_is_short = { foo_is_short = {
"detail": [ "detail": [
IsDict(
{ {
"ctx": {"min_length": 1}, "ctx": {"min_length": 1},
"loc": ["query", "foo"], "loc": ["query", "foo"],
@ -60,16 +48,6 @@ foo_is_short = {
"type": "string_too_short", "type": "string_too_short",
"input": "", "input": "",
} }
)
# TODO: remove when deprecating Pydantic v1
| IsDict(
{
"ctx": {"limit_value": 1},
"loc": ["query", "foo"],
"msg": "ensure this value has at least 1 characters",
"type": "value_error.any_str.min_length",
}
)
] ]
} }

View File

@ -1,5 +1,4 @@
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from .main import app from .main import app
@ -274,14 +273,10 @@ def test_openapi_schema():
"name": "item_id", "name": "item_id",
"in": "path", "in": "path",
"required": True, "required": True,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Item Id", "title": "Item Id",
} },
)
# TODO: remove when deprecating Pydantic v1
| IsDict({"title": "Item Id", "type": "string"}),
} }
], ],
} }
@ -984,14 +979,10 @@ def test_openapi_schema():
"name": "query", "name": "query",
"in": "query", "in": "query",
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "integer"}, {"type": "null"}], "anyOf": [{"type": "integer"}, {"type": "null"}],
"title": "Query", "title": "Query",
} },
)
# TODO: remove when deprecating Pydantic v1
| IsDict({"title": "Query", "type": "integer"}),
} }
], ],
} }

View File

@ -1,4 +1,3 @@
from dirty_equals import IsDict
from fastapi import Depends, FastAPI from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from pydantic import BaseModel from pydantic import BaseModel
@ -46,8 +45,7 @@ async def no_duplicates_sub(
def test_no_duplicates_invalid(): def test_no_duplicates_invalid():
response = client.post("/no-duplicates", json={"item": {"data": "myitem"}}) response = client.post("/no-duplicates", json={"item": {"data": "myitem"}})
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -57,18 +55,6 @@ def test_no_duplicates_invalid():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "item2"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_no_duplicates(): def test_no_duplicates():

View File

@ -1,7 +1,6 @@
from typing import Optional from typing import Optional
import pytest import pytest
from dirty_equals import IsDict
from fastapi import APIRouter, Depends, FastAPI from fastapi import APIRouter, Depends, FastAPI
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -54,8 +53,7 @@ async def overrider_dependency_with_sub(msg: dict = Depends(overrider_sub_depend
def test_main_depends(): def test_main_depends():
response = client.get("/main-depends/") response = client.get("/main-depends/")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -65,18 +63,6 @@ def test_main_depends():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "q"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_main_depends_q_foo(): def test_main_depends_q_foo():
@ -100,8 +86,7 @@ def test_main_depends_q_foo_skip_100_limit_200():
def test_decorator_depends(): def test_decorator_depends():
response = client.get("/decorator-depends/") response = client.get("/decorator-depends/")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -111,18 +96,6 @@ def test_decorator_depends():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "q"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_decorator_depends_q_foo(): def test_decorator_depends_q_foo():
@ -140,8 +113,7 @@ def test_decorator_depends_q_foo_skip_100_limit_200():
def test_router_depends(): def test_router_depends():
response = client.get("/router-depends/") response = client.get("/router-depends/")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -151,18 +123,6 @@ def test_router_depends():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "q"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_router_depends_q_foo(): def test_router_depends_q_foo():
@ -186,8 +146,7 @@ def test_router_depends_q_foo_skip_100_limit_200():
def test_router_decorator_depends(): def test_router_decorator_depends():
response = client.get("/router-decorator-depends/") response = client.get("/router-decorator-depends/")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -197,18 +156,6 @@ def test_router_decorator_depends():
} }
] ]
} }
) | IsDict(
# TODO remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "q"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_router_decorator_depends_q_foo(): def test_router_decorator_depends_q_foo():
@ -272,8 +219,7 @@ def test_override_with_sub_main_depends():
app.dependency_overrides[common_parameters] = overrider_dependency_with_sub app.dependency_overrides[common_parameters] = overrider_dependency_with_sub
response = client.get("/main-depends/") response = client.get("/main-depends/")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -283,18 +229,7 @@ def test_override_with_sub_main_depends():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "k"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
app.dependency_overrides = {} app.dependency_overrides = {}
@ -302,8 +237,7 @@ def test_override_with_sub__main_depends_q_foo():
app.dependency_overrides[common_parameters] = overrider_dependency_with_sub app.dependency_overrides[common_parameters] = overrider_dependency_with_sub
response = client.get("/main-depends/?q=foo") response = client.get("/main-depends/?q=foo")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -313,18 +247,7 @@ def test_override_with_sub__main_depends_q_foo():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "k"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
app.dependency_overrides = {} app.dependency_overrides = {}
@ -340,8 +263,7 @@ def test_override_with_sub_decorator_depends():
app.dependency_overrides[common_parameters] = overrider_dependency_with_sub app.dependency_overrides[common_parameters] = overrider_dependency_with_sub
response = client.get("/decorator-depends/") response = client.get("/decorator-depends/")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -351,18 +273,7 @@ def test_override_with_sub_decorator_depends():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "k"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
app.dependency_overrides = {} app.dependency_overrides = {}
@ -370,8 +281,7 @@ def test_override_with_sub_decorator_depends_q_foo():
app.dependency_overrides[common_parameters] = overrider_dependency_with_sub app.dependency_overrides[common_parameters] = overrider_dependency_with_sub
response = client.get("/decorator-depends/?q=foo") response = client.get("/decorator-depends/?q=foo")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -381,18 +291,7 @@ def test_override_with_sub_decorator_depends_q_foo():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "k"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
app.dependency_overrides = {} app.dependency_overrides = {}
@ -408,8 +307,7 @@ def test_override_with_sub_router_depends():
app.dependency_overrides[common_parameters] = overrider_dependency_with_sub app.dependency_overrides[common_parameters] = overrider_dependency_with_sub
response = client.get("/router-depends/") response = client.get("/router-depends/")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -419,18 +317,7 @@ def test_override_with_sub_router_depends():
} }
] ]
} }
) | IsDict(
# TODO remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "k"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
app.dependency_overrides = {} app.dependency_overrides = {}
@ -438,8 +325,7 @@ def test_override_with_sub_router_depends_q_foo():
app.dependency_overrides[common_parameters] = overrider_dependency_with_sub app.dependency_overrides[common_parameters] = overrider_dependency_with_sub
response = client.get("/router-depends/?q=foo") response = client.get("/router-depends/?q=foo")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -449,18 +335,7 @@ def test_override_with_sub_router_depends_q_foo():
} }
] ]
} }
) | IsDict(
# TODO remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "k"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
app.dependency_overrides = {} app.dependency_overrides = {}
@ -476,8 +351,7 @@ def test_override_with_sub_router_decorator_depends():
app.dependency_overrides[common_parameters] = overrider_dependency_with_sub app.dependency_overrides[common_parameters] = overrider_dependency_with_sub
response = client.get("/router-decorator-depends/") response = client.get("/router-decorator-depends/")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -487,18 +361,7 @@ def test_override_with_sub_router_decorator_depends():
} }
] ]
} }
) | IsDict(
# TODO remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "k"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
app.dependency_overrides = {} app.dependency_overrides = {}
@ -506,8 +369,7 @@ def test_override_with_sub_router_decorator_depends_q_foo():
app.dependency_overrides[common_parameters] = overrider_dependency_with_sub app.dependency_overrides[common_parameters] = overrider_dependency_with_sub
response = client.get("/router-decorator-depends/?q=foo") response = client.get("/router-decorator-depends/?q=foo")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -517,18 +379,7 @@ def test_override_with_sub_router_decorator_depends_q_foo():
} }
] ]
} }
) | IsDict(
# TODO remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "k"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
app.dependency_overrides = {} app.dependency_overrides = {}

View File

@ -1,6 +1,5 @@
from typing import Optional from typing import Optional
from dirty_equals import IsDict
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -328,14 +327,10 @@ def test_openapi_schema():
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"price": IsDict( "price": {
{
"title": "Price", "title": "Price",
"anyOf": [{"type": "number"}, {"type": "null"}], "anyOf": [{"type": "number"}, {"type": "null"}],
} },
)
# TODO: remove when deprecating Pydantic v1
| IsDict({"title": "Price", "type": "number"}),
}, },
}, },
"ValidationError": { "ValidationError": {

View File

@ -1,7 +1,7 @@
from typing import Optional from typing import Optional
import pytest import pytest
from dirty_equals import HasRepr, IsDict, IsOneOf from dirty_equals import HasRepr
from fastapi import Depends, FastAPI from fastapi import Depends, FastAPI
from fastapi.exceptions import ResponseValidationError from fastapi.exceptions import ResponseValidationError
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -63,7 +63,6 @@ def test_validator_is_cloned(client: TestClient):
with pytest.raises(ResponseValidationError) as err: with pytest.raises(ResponseValidationError) as err:
client.get("/model/modelX") client.get("/model/modelX")
assert err.value.errors() == [ assert err.value.errors() == [
IsDict(
{ {
"type": "value_error", "type": "value_error",
"loc": ("response", "name"), "loc": ("response", "name"),
@ -71,15 +70,6 @@ def test_validator_is_cloned(client: TestClient):
"input": "modelX", "input": "modelX",
"ctx": {"error": HasRepr("ValueError('name must end in A')")}, "ctx": {"error": HasRepr("ValueError('name must end in A')")},
} }
)
| IsDict(
# TODO remove when deprecating Pydantic v1
{
"loc": ("response", "name"),
"msg": "name must end in A",
"type": "value_error",
}
)
] ]
@ -145,23 +135,14 @@ def test_openapi_schema(client: TestClient):
}, },
"ModelA": { "ModelA": {
"title": "ModelA", "title": "ModelA",
"required": IsOneOf( "required": ["name", "foo"],
["name", "description", "foo"],
# TODO remove when deprecating Pydantic v1
["name", "foo"],
),
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"description": IsDict( "description": {
{
"title": "Description", "title": "Description",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
)
|
# TODO remove when deprecating Pydantic v1
IsDict({"title": "Description", "type": "string"}),
"foo": {"$ref": "#/components/schemas/ModelB"}, "foo": {"$ref": "#/components/schemas/ModelB"},
"tags": { "tags": {
"additionalProperties": {"type": "string"}, "additionalProperties": {"type": "string"},

View File

@ -1,6 +1,5 @@
from typing import Annotated, Optional from typing import Annotated, Optional
from dirty_equals import IsDict
from fastapi import FastAPI, Form from fastapi import FastAPI, Form
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
@ -79,8 +78,7 @@ def test_invalid_data():
}, },
) )
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -90,25 +88,12 @@ def test_invalid_data():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "age"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
}
)
def test_no_data(): def test_no_data():
response = client.post("/form/") response = client.post("/form/")
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -124,23 +109,6 @@ def test_no_data():
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "username"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "lastname"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_extra_param_single(): def test_extra_param_single():

View File

@ -1,6 +1,5 @@
from typing import Optional from typing import Optional
from dirty_equals import IsDict
from fastapi import APIRouter, FastAPI from fastapi import APIRouter, FastAPI
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -163,16 +162,10 @@ def test_openapi_schema():
"required": False, "required": False,
"name": "user_id", "name": "user_id",
"in": "query", "in": "query",
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "User Id", "title": "User Id",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "User Id", "type": "string"}
),
} }
], ],
"responses": { "responses": {
@ -208,16 +201,10 @@ def test_openapi_schema():
"required": False, "required": False,
"name": "user_id", "name": "user_id",
"in": "query", "in": "query",
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "User Id", "title": "User Id",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "User Id", "type": "string"}
),
}, },
], ],
"responses": { "responses": {
@ -247,16 +234,10 @@ def test_openapi_schema():
"required": True, "required": True,
"name": "user_id", "name": "user_id",
"in": "path", "in": "path",
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "User Id", "title": "User Id",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "User Id", "type": "string"}
),
} }
], ],
"responses": { "responses": {
@ -292,16 +273,10 @@ def test_openapi_schema():
"required": True, "required": True,
"name": "user_id", "name": "user_id",
"in": "path", "in": "path",
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "User Id", "title": "User Id",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "User Id", "type": "string"}
),
}, },
], ],
"responses": { "responses": {

View File

@ -1,8 +1,9 @@
from decimal import Decimal from decimal import Decimal
from dirty_equals import IsDict, IsOneOf from dirty_equals import IsOneOf
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from pydantic import BaseModel, condecimal from pydantic import BaseModel, condecimal
app = FastAPI() app = FastAPI()
@ -24,25 +25,22 @@ client = TestClient(app)
def test_put_correct_body(): def test_put_correct_body():
response = client.post("/items/", json=[{"name": "Foo", "age": 5}]) response = client.post("/items/", json=[{"name": "Foo", "age": 5}])
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.json() == { assert response.json() == snapshot(
{
"item": [ "item": [
{ {
"name": "Foo", "name": "Foo",
"age": IsOneOf( "age": "5",
5,
# TODO: remove when deprecating Pydantic v1
"5",
),
} }
] ]
} }
)
def test_jsonable_encoder_requiring_error(): def test_jsonable_encoder_requiring_error():
response = client.post("/items/", json=[{"name": "Foo", "age": -1.0}]) response = client.post("/items/", json=[{"name": "Foo", "age": -1.0}])
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "greater_than", "type": "greater_than",
@ -53,26 +51,12 @@ def test_jsonable_encoder_requiring_error():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"ctx": {"limit_value": 0.0},
"loc": ["body", 0, "age"],
"msg": "ensure this value is greater than 0",
"type": "value_error.number.not_gt",
}
]
}
)
def test_put_incorrect_body_multiple(): def test_put_incorrect_body_multiple():
response = client.post("/items/", json=[{"age": "five"}, {"age": "six"}]) response = client.post("/items/", json=[{"age": "five"}, {"age": "six"}])
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -100,33 +84,6 @@ def test_put_incorrect_body_multiple():
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", 0, "name"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", 0, "age"],
"msg": "value is not a valid decimal",
"type": "type_error.decimal",
},
{
"loc": ["body", 1, "name"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", 1, "age"],
"msg": "value is not a valid decimal",
"type": "type_error.decimal",
},
]
}
)
def test_openapi_schema(): def test_openapi_schema():
@ -179,8 +136,7 @@ def test_openapi_schema():
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"age": IsDict( "age": {
{
"title": "Age", "title": "Age",
"anyOf": [ "anyOf": [
{"exclusiveMinimum": 0.0, "type": "number"}, {"exclusiveMinimum": 0.0, "type": "number"},
@ -194,16 +150,7 @@ def test_openapi_schema():
}, },
), ),
], ],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "Age",
"exclusiveMinimum": 0.0,
"type": "number",
}
),
}, },
}, },
"ValidationError": { "ValidationError": {

View File

@ -1,4 +1,3 @@
from dirty_equals import IsDict
from fastapi import FastAPI, Query from fastapi import FastAPI, Query
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -22,8 +21,7 @@ def test_multi_query():
def test_multi_query_incorrect(): def test_multi_query_incorrect():
response = client.get("/items/?q=five&q=six") response = client.get("/items/?q=five&q=six")
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -39,23 +37,6 @@ def test_multi_query_incorrect():
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "q", 0],
"msg": "value is not a valid integer",
"type": "type_error.integer",
},
{
"loc": ["query", "q", 1],
"msg": "value is not a valid integer",
"type": "type_error.integer",
},
]
}
)
def test_openapi_schema(): def test_openapi_schema():

View File

@ -1,6 +1,5 @@
from typing import Union from typing import Union
from dirty_equals import IsDict
from fastapi import Body, Cookie, FastAPI, Header, Path, Query from fastapi import Body, Cookie, FastAPI, Header, Path, Query
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from pydantic import BaseModel from pydantic import BaseModel
@ -155,26 +154,12 @@ def test_openapi_schema():
"requestBody": { "requestBody": {
"content": { "content": {
"application/json": { "application/json": {
"schema": IsDict( "schema": {
{
"$ref": "#/components/schemas/Item", "$ref": "#/components/schemas/Item",
"examples": [ "examples": [
{"data": "Data in Body examples, example1"} {"data": "Data in Body examples, example1"}
], ],
} },
)
| IsDict(
{
# TODO: remove when deprecating Pydantic v1
"allOf": [
{"$ref": "#/components/schemas/Item"}
],
"title": "Item",
"examples": [
{"data": "Data in Body examples, example1"}
],
}
),
"examples": { "examples": {
"Example One": { "Example One": {
"summary": "Example One Summary", "summary": "Example One Summary",
@ -265,27 +250,14 @@ def test_openapi_schema():
"name": "data", "name": "data",
"in": "query", "in": "query",
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"examples": [ "examples": [
"json_schema_query1", "json_schema_query1",
"json_schema_query2", "json_schema_query2",
], ],
"title": "Data", "title": "Data",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"examples": [
"json_schema_query1",
"json_schema_query2",
],
"type": "string",
"title": "Data",
}
),
"examples": { "examples": {
"Query One": { "Query One": {
"summary": "Query One Summary", "summary": "Query One Summary",
@ -323,27 +295,14 @@ def test_openapi_schema():
"name": "data", "name": "data",
"in": "header", "in": "header",
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"examples": [ "examples": [
"json_schema_header1", "json_schema_header1",
"json_schema_header2", "json_schema_header2",
], ],
"title": "Data", "title": "Data",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "string",
"examples": [
"json_schema_header1",
"json_schema_header2",
],
"title": "Data",
}
),
"examples": { "examples": {
"Header One": { "Header One": {
"summary": "Header One Summary", "summary": "Header One Summary",
@ -381,27 +340,14 @@ def test_openapi_schema():
"name": "data", "name": "data",
"in": "cookie", "in": "cookie",
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"examples": [ "examples": [
"json_schema_cookie1", "json_schema_cookie1",
"json_schema_cookie2", "json_schema_cookie2",
], ],
"title": "Data", "title": "Data",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "string",
"examples": [
"json_schema_cookie1",
"json_schema_cookie2",
],
"title": "Data",
}
),
"examples": { "examples": {
"Cookie One": { "Cookie One": {
"summary": "Cookie One Summary", "summary": "Cookie One Summary",

View File

@ -1,6 +1,5 @@
from typing import Optional from typing import Optional
from dirty_equals import IsDict
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -53,21 +52,11 @@ def test_openapi():
"parameters": [ "parameters": [
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "integer"}, {"type": "null"}], "anyOf": [{"type": "integer"}, {"type": "null"}],
"default": 50, "default": 50,
"title": "Standard Query Param", "title": "Standard Query Param",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "Standard Query Param",
"type": "integer",
"default": 50,
}
),
"name": "standard_query_param", "name": "standard_query_param",
"in": "query", "in": "query",
}, },

View File

@ -1,6 +1,6 @@
from dirty_equals import IsOneOf
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
app = FastAPI( app = FastAPI(
servers=[ servers=[
@ -30,26 +30,17 @@ def test_app():
def test_openapi_schema(): def test_openapi_schema():
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.json() == { assert response.json() == snapshot(
{
"openapi": "3.1.0", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"servers": [ "servers": [
{"url": "/", "description": "Default, relative server"}, {"url": "/", "description": "Default, relative server"},
{ {
"url": IsOneOf( "url": "http://staging.localhost.tiangolo.com:8000",
"http://staging.localhost.tiangolo.com:8000/",
# TODO: remove when deprecating Pydantic v1
"http://staging.localhost.tiangolo.com:8000",
),
"description": "Staging but actually localhost still", "description": "Staging but actually localhost still",
}, },
{ {"url": "https://prod.example.com"},
"url": IsOneOf(
"https://prod.example.com/",
# TODO: remove when deprecating Pydantic v1
"https://prod.example.com",
)
},
], ],
"paths": { "paths": {
"/foo": { "/foo": {
@ -66,3 +57,4 @@ def test_openapi_schema():
} }
}, },
} }
)

View File

@ -1,6 +1,5 @@
from typing import Any from typing import Any
from dirty_equals import IsOneOf
from fastapi.params import Body, Cookie, Header, Param, Path, Query from fastapi.params import Body, Cookie, Header, Param, Path, Query
test_data: list[Any] = ["teststr", None, ..., 1, []] test_data: list[Any] = ["teststr", None, ..., 1, []]
@ -19,11 +18,7 @@ def test_param_repr_none():
def test_param_repr_ellipsis(): def test_param_repr_ellipsis():
assert repr(Param(...)) == IsOneOf( assert repr(Param(...)) == "Param(PydanticUndefined)"
"Param(PydanticUndefined)",
# TODO: remove when deprecating Pydantic v1
"Param(Ellipsis)",
)
def test_param_repr_number(): def test_param_repr_number():
@ -35,16 +30,8 @@ def test_param_repr_list():
def test_path_repr(): def test_path_repr():
assert repr(Path()) == IsOneOf( assert repr(Path()) == "Path(PydanticUndefined)"
"Path(PydanticUndefined)", assert repr(Path(...)) == "Path(PydanticUndefined)"
# TODO: remove when deprecating Pydantic v1
"Path(Ellipsis)",
)
assert repr(Path(...)) == IsOneOf(
"Path(PydanticUndefined)",
# TODO: remove when deprecating Pydantic v1
"Path(Ellipsis)",
)
def test_query_repr_str(): def test_query_repr_str():
@ -56,11 +43,7 @@ def test_query_repr_none():
def test_query_repr_ellipsis(): def test_query_repr_ellipsis():
assert repr(Query(...)) == IsOneOf( assert repr(Query(...)) == "Query(PydanticUndefined)"
"Query(PydanticUndefined)",
# TODO: remove when deprecating Pydantic v1
"Query(Ellipsis)",
)
def test_query_repr_number(): def test_query_repr_number():
@ -80,11 +63,7 @@ def test_header_repr_none():
def test_header_repr_ellipsis(): def test_header_repr_ellipsis():
assert repr(Header(...)) == IsOneOf( assert repr(Header(...)) == "Header(PydanticUndefined)"
"Header(PydanticUndefined)",
# TODO: remove when deprecating Pydantic v1
"Header(Ellipsis)",
)
def test_header_repr_number(): def test_header_repr_number():
@ -104,11 +83,7 @@ def test_cookie_repr_none():
def test_cookie_repr_ellipsis(): def test_cookie_repr_ellipsis():
assert repr(Cookie(...)) == IsOneOf( assert repr(Cookie(...)) == "Cookie(PydanticUndefined)"
"Cookie(PydanticUndefined)",
# TODO: remove when deprecating Pydantic v1
"Cookie(Ellipsis)",
)
def test_cookie_repr_number(): def test_cookie_repr_number():
@ -128,11 +103,7 @@ def test_body_repr_none():
def test_body_repr_ellipsis(): def test_body_repr_ellipsis():
assert repr(Body(...)) == IsOneOf( assert repr(Body(...)) == "Body(PydanticUndefined)"
"Body(PydanticUndefined)",
# TODO: remove when deprecating Pydantic v1
"Body(Ellipsis)",
)
def test_body_repr_number(): def test_body_repr_number():

View File

@ -1,4 +1,3 @@
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from .main import app from .main import app
@ -45,8 +44,7 @@ def test_path_str_True():
def test_path_int_foobar(): def test_path_int_foobar():
response = client.get("/path/int/foobar") response = client.get("/path/int/foobar")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -56,25 +54,12 @@ def test_path_int_foobar():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
}
)
def test_path_int_True(): def test_path_int_True():
response = client.get("/path/int/True") response = client.get("/path/int/True")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -84,18 +69,6 @@ def test_path_int_True():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
}
)
def test_path_int_42(): def test_path_int_42():
@ -107,8 +80,7 @@ def test_path_int_42():
def test_path_int_42_5(): def test_path_int_42_5():
response = client.get("/path/int/42.5") response = client.get("/path/int/42.5")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -118,25 +90,12 @@ def test_path_int_42_5():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
}
)
def test_path_float_foobar(): def test_path_float_foobar():
response = client.get("/path/float/foobar") response = client.get("/path/float/foobar")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "float_parsing", "type": "float_parsing",
@ -146,25 +105,12 @@ def test_path_float_foobar():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "value is not a valid float",
"type": "type_error.float",
}
]
}
)
def test_path_float_True(): def test_path_float_True():
response = client.get("/path/float/True") response = client.get("/path/float/True")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "float_parsing", "type": "float_parsing",
@ -174,18 +120,6 @@ def test_path_float_True():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "value is not a valid float",
"type": "type_error.float",
}
]
}
)
def test_path_float_42(): def test_path_float_42():
@ -203,8 +137,7 @@ def test_path_float_42_5():
def test_path_bool_foobar(): def test_path_bool_foobar():
response = client.get("/path/bool/foobar") response = client.get("/path/bool/foobar")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "bool_parsing", "type": "bool_parsing",
@ -214,18 +147,6 @@ def test_path_bool_foobar():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "value could not be parsed to a boolean",
"type": "type_error.bool",
}
]
}
)
def test_path_bool_True(): def test_path_bool_True():
@ -237,8 +158,7 @@ def test_path_bool_True():
def test_path_bool_42(): def test_path_bool_42():
response = client.get("/path/bool/42") response = client.get("/path/bool/42")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "bool_parsing", "type": "bool_parsing",
@ -248,25 +168,12 @@ def test_path_bool_42():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "value could not be parsed to a boolean",
"type": "type_error.bool",
}
]
}
)
def test_path_bool_42_5(): def test_path_bool_42_5():
response = client.get("/path/bool/42.5") response = client.get("/path/bool/42.5")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "bool_parsing", "type": "bool_parsing",
@ -276,18 +183,6 @@ def test_path_bool_42_5():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "value could not be parsed to a boolean",
"type": "type_error.bool",
}
]
}
)
def test_path_bool_1(): def test_path_bool_1():
@ -335,8 +230,7 @@ def test_path_param_minlength_foo():
def test_path_param_minlength_fo(): def test_path_param_minlength_fo():
response = client.get("/path/param-minlength/fo") response = client.get("/path/param-minlength/fo")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "string_too_short", "type": "string_too_short",
@ -347,19 +241,6 @@ def test_path_param_minlength_fo():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value has at least 3 characters",
"type": "value_error.any_str.min_length",
"ctx": {"limit_value": 3},
}
]
}
)
def test_path_param_maxlength_foo(): def test_path_param_maxlength_foo():
@ -371,8 +252,7 @@ def test_path_param_maxlength_foo():
def test_path_param_maxlength_foobar(): def test_path_param_maxlength_foobar():
response = client.get("/path/param-maxlength/foobar") response = client.get("/path/param-maxlength/foobar")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "string_too_long", "type": "string_too_long",
@ -383,19 +263,6 @@ def test_path_param_maxlength_foobar():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value has at most 3 characters",
"type": "value_error.any_str.max_length",
"ctx": {"limit_value": 3},
}
]
}
)
def test_path_param_min_maxlength_foo(): def test_path_param_min_maxlength_foo():
@ -407,8 +274,7 @@ def test_path_param_min_maxlength_foo():
def test_path_param_min_maxlength_foobar(): def test_path_param_min_maxlength_foobar():
response = client.get("/path/param-min_maxlength/foobar") response = client.get("/path/param-min_maxlength/foobar")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "string_too_long", "type": "string_too_long",
@ -419,26 +285,12 @@ def test_path_param_min_maxlength_foobar():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value has at most 3 characters",
"type": "value_error.any_str.max_length",
"ctx": {"limit_value": 3},
}
]
}
)
def test_path_param_min_maxlength_f(): def test_path_param_min_maxlength_f():
response = client.get("/path/param-min_maxlength/f") response = client.get("/path/param-min_maxlength/f")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "string_too_short", "type": "string_too_short",
@ -449,18 +301,6 @@ def test_path_param_min_maxlength_f():
} }
] ]
} }
) | IsDict(
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value has at least 2 characters",
"type": "value_error.any_str.min_length",
"ctx": {"limit_value": 2},
}
]
}
)
def test_path_param_gt_42(): def test_path_param_gt_42():
@ -472,8 +312,7 @@ def test_path_param_gt_42():
def test_path_param_gt_2(): def test_path_param_gt_2():
response = client.get("/path/param-gt/2") response = client.get("/path/param-gt/2")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "greater_than", "type": "greater_than",
@ -484,19 +323,6 @@ def test_path_param_gt_2():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value is greater than 3",
"type": "value_error.number.not_gt",
"ctx": {"limit_value": 3},
}
]
}
)
def test_path_param_gt0_0_05(): def test_path_param_gt0_0_05():
@ -508,8 +334,7 @@ def test_path_param_gt0_0_05():
def test_path_param_gt0_0(): def test_path_param_gt0_0():
response = client.get("/path/param-gt0/0") response = client.get("/path/param-gt0/0")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "greater_than", "type": "greater_than",
@ -520,19 +345,6 @@ def test_path_param_gt0_0():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value is greater than 0",
"type": "value_error.number.not_gt",
"ctx": {"limit_value": 0},
}
]
}
)
def test_path_param_ge_42(): def test_path_param_ge_42():
@ -550,8 +362,7 @@ def test_path_param_ge_3():
def test_path_param_ge_2(): def test_path_param_ge_2():
response = client.get("/path/param-ge/2") response = client.get("/path/param-ge/2")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "greater_than_equal", "type": "greater_than_equal",
@ -562,26 +373,12 @@ def test_path_param_ge_2():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value is greater than or equal to 3",
"type": "value_error.number.not_ge",
"ctx": {"limit_value": 3},
}
]
}
)
def test_path_param_lt_42(): def test_path_param_lt_42():
response = client.get("/path/param-lt/42") response = client.get("/path/param-lt/42")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "less_than", "type": "less_than",
@ -592,19 +389,6 @@ def test_path_param_lt_42():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value is less than 3",
"type": "value_error.number.not_lt",
"ctx": {"limit_value": 3},
}
]
}
)
def test_path_param_lt_2(): def test_path_param_lt_2():
@ -622,8 +406,7 @@ def test_path_param_lt0__1():
def test_path_param_lt0_0(): def test_path_param_lt0_0():
response = client.get("/path/param-lt0/0") response = client.get("/path/param-lt0/0")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "less_than", "type": "less_than",
@ -634,26 +417,12 @@ def test_path_param_lt0_0():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value is less than 0",
"type": "value_error.number.not_lt",
"ctx": {"limit_value": 0},
}
]
}
)
def test_path_param_le_42(): def test_path_param_le_42():
response = client.get("/path/param-le/42") response = client.get("/path/param-le/42")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "less_than_equal", "type": "less_than_equal",
@ -664,19 +433,6 @@ def test_path_param_le_42():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value is less than or equal to 3",
"type": "value_error.number.not_le",
"ctx": {"limit_value": 3},
}
]
}
)
def test_path_param_le_3(): def test_path_param_le_3():
@ -700,8 +456,7 @@ def test_path_param_lt_gt_2():
def test_path_param_lt_gt_4(): def test_path_param_lt_gt_4():
response = client.get("/path/param-lt-gt/4") response = client.get("/path/param-lt-gt/4")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "less_than", "type": "less_than",
@ -712,26 +467,12 @@ def test_path_param_lt_gt_4():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value is less than 3",
"type": "value_error.number.not_lt",
"ctx": {"limit_value": 3},
}
]
}
)
def test_path_param_lt_gt_0(): def test_path_param_lt_gt_0():
response = client.get("/path/param-lt-gt/0") response = client.get("/path/param-lt-gt/0")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "greater_than", "type": "greater_than",
@ -742,19 +483,6 @@ def test_path_param_lt_gt_0():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value is greater than 1",
"type": "value_error.number.not_gt",
"ctx": {"limit_value": 1},
}
]
}
)
def test_path_param_le_ge_2(): def test_path_param_le_ge_2():
@ -777,8 +505,7 @@ def test_path_param_le_ge_3():
def test_path_param_le_ge_4(): def test_path_param_le_ge_4():
response = client.get("/path/param-le-ge/4") response = client.get("/path/param-le-ge/4")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "less_than_equal", "type": "less_than_equal",
@ -789,19 +516,6 @@ def test_path_param_le_ge_4():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value is less than or equal to 3",
"type": "value_error.number.not_le",
"ctx": {"limit_value": 3},
}
]
}
)
def test_path_param_lt_int_2(): def test_path_param_lt_int_2():
@ -813,8 +527,7 @@ def test_path_param_lt_int_2():
def test_path_param_lt_int_42(): def test_path_param_lt_int_42():
response = client.get("/path/param-lt-int/42") response = client.get("/path/param-lt-int/42")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "less_than", "type": "less_than",
@ -825,26 +538,12 @@ def test_path_param_lt_int_42():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value is less than 3",
"type": "value_error.number.not_lt",
"ctx": {"limit_value": 3},
}
]
}
)
def test_path_param_lt_int_2_7(): def test_path_param_lt_int_2_7():
response = client.get("/path/param-lt-int/2.7") response = client.get("/path/param-lt-int/2.7")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -854,18 +553,6 @@ def test_path_param_lt_int_2_7():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
}
)
def test_path_param_gt_int_42(): def test_path_param_gt_int_42():
@ -877,8 +564,7 @@ def test_path_param_gt_int_42():
def test_path_param_gt_int_2(): def test_path_param_gt_int_2():
response = client.get("/path/param-gt-int/2") response = client.get("/path/param-gt-int/2")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "greater_than", "type": "greater_than",
@ -889,26 +575,12 @@ def test_path_param_gt_int_2():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value is greater than 3",
"type": "value_error.number.not_gt",
"ctx": {"limit_value": 3},
}
]
}
)
def test_path_param_gt_int_2_7(): def test_path_param_gt_int_2_7():
response = client.get("/path/param-gt-int/2.7") response = client.get("/path/param-gt-int/2.7")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -918,25 +590,12 @@ def test_path_param_gt_int_2_7():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
}
)
def test_path_param_le_int_42(): def test_path_param_le_int_42():
response = client.get("/path/param-le-int/42") response = client.get("/path/param-le-int/42")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "less_than_equal", "type": "less_than_equal",
@ -947,19 +606,6 @@ def test_path_param_le_int_42():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value is less than or equal to 3",
"type": "value_error.number.not_le",
"ctx": {"limit_value": 3},
}
]
}
)
def test_path_param_le_int_3(): def test_path_param_le_int_3():
@ -977,8 +623,7 @@ def test_path_param_le_int_2():
def test_path_param_le_int_2_7(): def test_path_param_le_int_2_7():
response = client.get("/path/param-le-int/2.7") response = client.get("/path/param-le-int/2.7")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -988,18 +633,6 @@ def test_path_param_le_int_2_7():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
}
)
def test_path_param_ge_int_42(): def test_path_param_ge_int_42():
@ -1017,8 +650,7 @@ def test_path_param_ge_int_3():
def test_path_param_ge_int_2(): def test_path_param_ge_int_2():
response = client.get("/path/param-ge-int/2") response = client.get("/path/param-ge-int/2")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "greater_than_equal", "type": "greater_than_equal",
@ -1029,26 +661,12 @@ def test_path_param_ge_int_2():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value is greater than or equal to 3",
"type": "value_error.number.not_ge",
"ctx": {"limit_value": 3},
}
]
}
)
def test_path_param_ge_int_2_7(): def test_path_param_ge_int_2_7():
response = client.get("/path/param-ge-int/2.7") response = client.get("/path/param-ge-int/2.7")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -1058,18 +676,6 @@ def test_path_param_ge_int_2_7():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
}
)
def test_path_param_lt_gt_int_2(): def test_path_param_lt_gt_int_2():
@ -1081,8 +687,7 @@ def test_path_param_lt_gt_int_2():
def test_path_param_lt_gt_int_4(): def test_path_param_lt_gt_int_4():
response = client.get("/path/param-lt-gt-int/4") response = client.get("/path/param-lt-gt-int/4")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "less_than", "type": "less_than",
@ -1093,26 +698,12 @@ def test_path_param_lt_gt_int_4():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value is less than 3",
"type": "value_error.number.not_lt",
"ctx": {"limit_value": 3},
}
]
}
)
def test_path_param_lt_gt_int_0(): def test_path_param_lt_gt_int_0():
response = client.get("/path/param-lt-gt-int/0") response = client.get("/path/param-lt-gt-int/0")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "greater_than", "type": "greater_than",
@ -1123,26 +714,12 @@ def test_path_param_lt_gt_int_0():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value is greater than 1",
"type": "value_error.number.not_gt",
"ctx": {"limit_value": 1},
}
]
}
)
def test_path_param_lt_gt_int_2_7(): def test_path_param_lt_gt_int_2_7():
response = client.get("/path/param-lt-gt-int/2.7") response = client.get("/path/param-lt-gt-int/2.7")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -1152,18 +729,6 @@ def test_path_param_lt_gt_int_2_7():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
}
)
def test_path_param_le_ge_int_2(): def test_path_param_le_ge_int_2():
@ -1187,8 +752,7 @@ def test_path_param_le_ge_int_3():
def test_path_param_le_ge_int_4(): def test_path_param_le_ge_int_4():
response = client.get("/path/param-le-ge-int/4") response = client.get("/path/param-le-ge-int/4")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "less_than_equal", "type": "less_than_equal",
@ -1199,26 +763,12 @@ def test_path_param_le_ge_int_4():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "ensure this value is less than or equal to 3",
"type": "value_error.number.not_le",
"ctx": {"limit_value": 3},
}
]
}
)
def test_path_param_le_ge_int_2_7(): def test_path_param_le_ge_int_2_7():
response = client.get("/path/param-le-ge-int/2.7") response = client.get("/path/param-le-ge-int/2.7")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -1228,15 +778,3 @@ def test_path_param_le_ge_int_2_7():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
}
)

View File

@ -1,4 +1,3 @@
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from .main import app from .main import app
@ -9,8 +8,7 @@ client = TestClient(app)
def test_query(): def test_query():
response = client.get("/query") response = client.get("/query")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -20,18 +18,6 @@ def test_query():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "query"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_query_query_baz(): def test_query_query_baz():
@ -43,8 +29,7 @@ def test_query_query_baz():
def test_query_not_declared_baz(): def test_query_not_declared_baz():
response = client.get("/query?not_declared=baz") response = client.get("/query?not_declared=baz")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -54,18 +39,6 @@ def test_query_not_declared_baz():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "query"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_query_optional(): def test_query_optional():
@ -89,8 +62,7 @@ def test_query_optional_not_declared_baz():
def test_query_int(): def test_query_int():
response = client.get("/query/int") response = client.get("/query/int")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -100,18 +72,6 @@ def test_query_int():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "query"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_query_int_query_42(): def test_query_int_query_42():
@ -123,8 +83,7 @@ def test_query_int_query_42():
def test_query_int_query_42_5(): def test_query_int_query_42_5():
response = client.get("/query/int?query=42.5") response = client.get("/query/int?query=42.5")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -134,25 +93,12 @@ def test_query_int_query_42_5():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "query"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
}
)
def test_query_int_query_baz(): def test_query_int_query_baz():
response = client.get("/query/int?query=baz") response = client.get("/query/int?query=baz")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -162,25 +108,12 @@ def test_query_int_query_baz():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "query"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
}
)
def test_query_int_not_declared_baz(): def test_query_int_not_declared_baz():
response = client.get("/query/int?not_declared=baz") response = client.get("/query/int?not_declared=baz")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -190,18 +123,6 @@ def test_query_int_not_declared_baz():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "query"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_query_int_optional(): def test_query_int_optional():
@ -219,8 +140,7 @@ def test_query_int_optional_query_50():
def test_query_int_optional_query_foo(): def test_query_int_optional_query_foo():
response = client.get("/query/int/optional?query=foo") response = client.get("/query/int/optional?query=foo")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -230,18 +150,6 @@ def test_query_int_optional_query_foo():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "query"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
}
)
def test_query_int_default(): def test_query_int_default():
@ -259,8 +167,7 @@ def test_query_int_default_query_50():
def test_query_int_default_query_foo(): def test_query_int_default_query_foo():
response = client.get("/query/int/default?query=foo") response = client.get("/query/int/default?query=foo")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -270,18 +177,6 @@ def test_query_int_default_query_foo():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "query"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
}
)
def test_query_param(): def test_query_param():
@ -299,8 +194,7 @@ def test_query_param_query_50():
def test_query_param_required(): def test_query_param_required():
response = client.get("/query/param-required") response = client.get("/query/param-required")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -310,18 +204,6 @@ def test_query_param_required():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "query"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_query_param_required_query_50(): def test_query_param_required_query_50():
@ -333,8 +215,7 @@ def test_query_param_required_query_50():
def test_query_param_required_int(): def test_query_param_required_int():
response = client.get("/query/param-required/int") response = client.get("/query/param-required/int")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -344,18 +225,6 @@ def test_query_param_required_int():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "query"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_query_param_required_int_query_50(): def test_query_param_required_int_query_50():
@ -367,8 +236,7 @@ def test_query_param_required_int_query_50():
def test_query_param_required_int_query_foo(): def test_query_param_required_int_query_foo():
response = client.get("/query/param-required/int?query=foo") response = client.get("/query/param-required/int?query=foo")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -378,18 +246,6 @@ def test_query_param_required_int_query_foo():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "query"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
}
)
def test_query_frozenset_query_1_query_1_query_2(): def test_query_frozenset_query_1_query_1_query_2():

View File

@ -1,10 +1,10 @@
from typing import Annotated from typing import Annotated
import pytest import pytest
from dirty_equals import IsDict
from fastapi import FastAPI, Form from fastapi import FastAPI, Form
from fastapi.exceptions import FastAPIDeprecationWarning from fastapi.exceptions import FastAPIDeprecationWarning
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from .utils import needs_py310 from .utils import needs_py310
@ -47,8 +47,7 @@ def test_query_nonregexquery():
client = get_client() client = get_client()
response = client.post("/items/", data={"q": "nonregexquery"}) response = client.post("/items/", data={"q": "nonregexquery"})
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "string_pattern_mismatch", "type": "string_pattern_mismatch",
@ -59,19 +58,6 @@ def test_query_nonregexquery():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"ctx": {"pattern": "^fixedquery$"},
"loc": ["body", "q"],
"msg": 'string does not match regex "^fixedquery$"',
"type": "value_error.str.regex",
}
]
}
)
@needs_py310 @needs_py310
@ -79,8 +65,8 @@ def test_openapi_schema():
client = get_client() client = get_client()
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
# insert_assert(response.json()) assert response.json() == snapshot(
assert response.json() == { {
"openapi": "3.1.0", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
@ -91,22 +77,9 @@ def test_openapi_schema():
"requestBody": { "requestBody": {
"content": { "content": {
"application/x-www-form-urlencoded": { "application/x-www-form-urlencoded": {
"schema": IsDict( "schema": {
{
"allOf": [
{
"$ref": "#/components/schemas/Body_read_items_items__post" "$ref": "#/components/schemas/Body_read_items_items__post"
} }
],
"title": "Body",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"$ref": "#/components/schemas/Body_read_items_items__post"
}
)
} }
} }
}, },
@ -133,19 +106,13 @@ def test_openapi_schema():
"schemas": { "schemas": {
"Body_read_items_items__post": { "Body_read_items_items__post": {
"properties": { "properties": {
"q": IsDict( "q": {
{
"anyOf": [ "anyOf": [
{"type": "string", "pattern": "^fixedquery$"}, {"type": "string", "pattern": "^fixedquery$"},
{"type": "null"}, {"type": "null"},
], ],
"title": "Q", "title": "Q",
} }
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"type": "string", "pattern": "^fixedquery$", "title": "Q"}
)
}, },
"type": "object", "type": "object",
"title": "Body_read_items_items__post", "title": "Body_read_items_items__post",
@ -153,7 +120,9 @@ def test_openapi_schema():
"HTTPValidationError": { "HTTPValidationError": {
"properties": { "properties": {
"detail": { "detail": {
"items": {"$ref": "#/components/schemas/ValidationError"}, "items": {
"$ref": "#/components/schemas/ValidationError"
},
"type": "array", "type": "array",
"title": "Detail", "title": "Detail",
} }
@ -180,3 +149,4 @@ def test_openapi_schema():
} }
}, },
} }
)

View File

@ -1,7 +1,6 @@
from typing import Annotated from typing import Annotated
import pytest import pytest
from dirty_equals import IsDict
from fastapi import FastAPI, Query from fastapi import FastAPI, Query
from fastapi.exceptions import FastAPIDeprecationWarning from fastapi.exceptions import FastAPIDeprecationWarning
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -47,8 +46,7 @@ def test_query_params_str_validations_item_query_nonregexquery():
client = get_client() client = get_client()
response = client.get("/items/", params={"q": "nonregexquery"}) response = client.get("/items/", params={"q": "nonregexquery"})
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "string_pattern_mismatch", "type": "string_pattern_mismatch",
@ -59,19 +57,6 @@ def test_query_params_str_validations_item_query_nonregexquery():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"ctx": {"pattern": "^fixedquery$"},
"loc": ["query", "q"],
"msg": 'string does not match regex "^fixedquery$"',
"type": "value_error.str.regex",
}
]
}
)
@needs_py310 @needs_py310
@ -93,23 +78,13 @@ def test_openapi_schema():
"name": "q", "name": "q",
"in": "query", "in": "query",
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [ "anyOf": [
{"type": "string", "pattern": "^fixedquery$"}, {"type": "string", "pattern": "^fixedquery$"},
{"type": "null"}, {"type": "null"},
], ],
"title": "Q", "title": "Q",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "string",
"pattern": "^fixedquery$",
"title": "Q",
}
),
} }
], ],
"responses": { "responses": {

View File

@ -148,8 +148,7 @@ def test_required_list_alias_missing(path: str, json: Union[dict, None]):
client = TestClient(app) client = TestClient(app)
response = client.post(path, json=json) response = client.post(path, json=json)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -159,18 +158,6 @@ def test_required_list_alias_missing(path: str, json: Union[dict, None]):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": IsOneOf(["body", "p_alias"], ["body"]),
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -181,8 +168,7 @@ def test_required_list_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
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -192,18 +178,6 @@ def test_required_list_alias_by_name(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -1,7 +1,6 @@
from typing import Annotated, Optional from typing import Annotated, Optional
import pytest import pytest
from dirty_equals import IsDict
from fastapi import Body, FastAPI from fastapi import Body, FastAPI
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
@ -38,8 +37,7 @@ def test_optional_list_str_schema(path: str):
openapi = app.openapi() openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path) body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict( assert app.openapi()["components"]["schemas"][body_model_name] == {
{
"properties": { "properties": {
"p": { "p": {
"anyOf": [ "anyOf": [
@ -52,16 +50,6 @@ def test_optional_list_str_schema(path: str):
"title": body_model_name, "title": body_model_name,
"type": "object", "type": "object",
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"properties": {
"p": {"items": {"type": "string"}, "type": "array", "title": "P"},
},
"title": body_model_name,
"type": "object",
}
)
def test_optional_list_str_missing(): def test_optional_list_str_missing():
@ -75,8 +63,7 @@ def test_model_optional_list_str_missing():
client = TestClient(app) client = TestClient(app)
response = client.post("/model-optional-list-str") response = client.post("/model-optional-list-str")
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"input": None, "input": None,
@ -86,18 +73,6 @@ def test_model_optional_list_str_missing():
}, },
], ],
} }
) | IsDict(
{
# TODO: remove when deprecating Pydantic v1
"detail": [
{
"loc": ["body"],
"msg": "field required",
"type": "value_error.missing",
},
],
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -153,8 +128,7 @@ def test_optional_list_str_alias_schema(path: str):
openapi = app.openapi() openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path) body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict( assert app.openapi()["components"]["schemas"][body_model_name] == {
{
"properties": { "properties": {
"p_alias": { "p_alias": {
"anyOf": [ "anyOf": [
@ -167,20 +141,6 @@ def test_optional_list_str_alias_schema(path: str):
"title": body_model_name, "title": body_model_name,
"type": "object", "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",
}
)
def test_optional_list_alias_missing(): def test_optional_list_alias_missing():
@ -194,8 +154,7 @@ def test_model_optional_list_alias_missing():
client = TestClient(app) client = TestClient(app)
response = client.post("/model-optional-list-alias") response = client.post("/model-optional-list-alias")
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"input": None, "input": None,
@ -205,18 +164,6 @@ def test_model_optional_list_alias_missing():
}, },
], ],
} }
) | IsDict(
{
# TODO: remove when deprecating Pydantic v1
"detail": [
{
"loc": ["body"],
"msg": "field required",
"type": "value_error.missing",
},
],
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -289,8 +236,7 @@ def test_optional_list_validation_alias_schema(path: str):
openapi = app.openapi() openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path) body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict( assert app.openapi()["components"]["schemas"][body_model_name] == {
{
"properties": { "properties": {
"p_val_alias": { "p_val_alias": {
"anyOf": [ "anyOf": [
@ -303,20 +249,6 @@ def test_optional_list_validation_alias_schema(path: str):
"title": body_model_name, "title": body_model_name,
"type": "object", "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",
}
)
def test_optional_list_validation_alias_missing(): def test_optional_list_validation_alias_missing():
@ -330,8 +262,7 @@ def test_model_optional_list_validation_alias_missing():
client = TestClient(app) client = TestClient(app)
response = client.post("/model-optional-list-validation-alias") response = client.post("/model-optional-list-validation-alias")
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"input": None, "input": None,
@ -341,18 +272,6 @@ def test_model_optional_list_validation_alias_missing():
}, },
], ],
} }
) | IsDict(
{
# TODO: remove when deprecating Pydantic v1
"detail": [
{
"loc": ["body"],
"msg": "field required",
"type": "value_error.missing",
},
],
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -438,8 +357,7 @@ def test_optional_list_alias_and_validation_alias_schema(path: str):
openapi = app.openapi() openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path) body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict( assert app.openapi()["components"]["schemas"][body_model_name] == {
{
"properties": { "properties": {
"p_val_alias": { "p_val_alias": {
"anyOf": [ "anyOf": [
@ -452,20 +370,6 @@ def test_optional_list_alias_and_validation_alias_schema(path: str):
"title": body_model_name, "title": body_model_name,
"type": "object", "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",
}
)
def test_optional_list_alias_and_validation_alias_missing(): def test_optional_list_alias_and_validation_alias_missing():
@ -479,8 +383,7 @@ def test_model_optional_list_alias_and_validation_alias_missing():
client = TestClient(app) client = TestClient(app)
response = client.post("/model-optional-list-alias-and-validation-alias") response = client.post("/model-optional-list-alias-and-validation-alias")
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"input": None, "input": None,
@ -490,18 +393,6 @@ def test_model_optional_list_alias_and_validation_alias_missing():
}, },
], ],
} }
) | IsDict(
{
# TODO: remove when deprecating Pydantic v1
"detail": [
{
"loc": ["body"],
"msg": "field required",
"type": "value_error.missing",
},
],
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

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

View File

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

View File

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

View File

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

View File

@ -75,8 +75,7 @@ def test_list_missing(path: str):
client = TestClient(app) client = TestClient(app)
response = client.post(path) response = client.post(path)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -86,18 +85,6 @@ def test_list_missing(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -182,8 +169,7 @@ def test_list_alias_missing(path: str):
client = TestClient(app) client = TestClient(app)
response = client.post(path) response = client.post(path)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -193,18 +179,6 @@ def test_list_alias_missing(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -218,8 +192,7 @@ def test_list_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 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -229,18 +202,6 @@ def test_list_alias_by_name(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

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

View File

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

View File

@ -1,7 +1,6 @@
from typing import Annotated from typing import Annotated
import pytest import pytest
from dirty_equals import IsDict
from fastapi import FastAPI, File, UploadFile from fastapi import FastAPI, File, UploadFile
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -55,8 +54,7 @@ def test_required_missing(path: str):
client = TestClient(app) client = TestClient(app)
response = client.post(path) response = client.post(path)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -66,18 +64,6 @@ def test_required_missing(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -142,8 +128,7 @@ def test_required_alias_missing(path: str):
client = TestClient(app) client = TestClient(app)
response = client.post(path) response = client.post(path)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -153,18 +138,6 @@ def test_required_alias_missing(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -178,8 +151,7 @@ def test_required_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 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -189,18 +161,6 @@ def test_required_alias_by_name(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -146,8 +146,7 @@ def test_required_list_alias_missing(path: str):
client = TestClient(app) client = TestClient(app)
response = client.post(path) response = client.post(path)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -157,18 +156,6 @@ def test_required_list_alias_missing(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -182,8 +169,7 @@ def test_required_list_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
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -193,18 +179,6 @@ def test_required_list_alias_by_name(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -1,7 +1,6 @@
from typing import Annotated, Optional from typing import Annotated, Optional
import pytest import pytest
from dirty_equals import IsDict
from fastapi import FastAPI, Form from fastapi import FastAPI, Form
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
@ -38,8 +37,7 @@ def test_optional_list_str_schema(path: str):
openapi = app.openapi() openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path) body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict( assert app.openapi()["components"]["schemas"][body_model_name] == {
{
"properties": { "properties": {
"p": { "p": {
"anyOf": [ "anyOf": [
@ -52,16 +50,6 @@ def test_optional_list_str_schema(path: str):
"title": body_model_name, "title": body_model_name,
"type": "object", "type": "object",
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"properties": {
"p": {"items": {"type": "string"}, "type": "array", "title": "P"},
},
"title": body_model_name,
"type": "object",
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -119,8 +107,7 @@ def test_optional_list_str_alias_schema(path: str):
openapi = app.openapi() openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path) body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict( assert app.openapi()["components"]["schemas"][body_model_name] == {
{
"properties": { "properties": {
"p_alias": { "p_alias": {
"anyOf": [ "anyOf": [
@ -133,20 +120,6 @@ def test_optional_list_str_alias_schema(path: str):
"title": body_model_name, "title": body_model_name,
"type": "object", "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",
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -217,8 +190,7 @@ def test_optional_list_validation_alias_schema(path: str):
openapi = app.openapi() openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path) body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict( assert app.openapi()["components"]["schemas"][body_model_name] == {
{
"properties": { "properties": {
"p_val_alias": { "p_val_alias": {
"anyOf": [ "anyOf": [
@ -231,20 +203,6 @@ def test_optional_list_validation_alias_schema(path: str):
"title": body_model_name, "title": body_model_name,
"type": "object", "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",
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -326,8 +284,7 @@ def test_optional_list_alias_and_validation_alias_schema(path: str):
openapi = app.openapi() openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path) body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == IsDict( assert app.openapi()["components"]["schemas"][body_model_name] == {
{
"properties": { "properties": {
"p_val_alias": { "p_val_alias": {
"anyOf": [ "anyOf": [
@ -340,20 +297,6 @@ def test_optional_list_alias_and_validation_alias_schema(path: str):
"title": body_model_name, "title": body_model_name,
"type": "object", "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",
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

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

View File

@ -1,7 +1,7 @@
from typing import Annotated from typing import Annotated
import pytest import pytest
from dirty_equals import IsDict, IsOneOf from dirty_equals import IsOneOf
from fastapi import FastAPI, Form from fastapi import FastAPI, Form
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
@ -54,8 +54,7 @@ def test_required_str_missing(path: str):
client = TestClient(app) client = TestClient(app)
response = client.post(path) response = client.post(path)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -65,18 +64,6 @@ def test_required_str_missing(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -137,8 +124,7 @@ def test_required_alias_missing(path: str):
client = TestClient(app) client = TestClient(app)
response = client.post(path) response = client.post(path)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -148,18 +134,6 @@ def test_required_alias_missing(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -170,8 +144,7 @@ def test_required_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 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -181,18 +154,6 @@ def test_required_alias_by_name(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -135,8 +135,7 @@ def test_required_list_alias_missing(path: str):
client = TestClient(app) client = TestClient(app)
response = client.get(path) response = client.get(path)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -146,18 +145,6 @@ def test_required_list_alias_missing(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["header", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -171,8 +158,7 @@ def test_required_list_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 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -182,18 +168,6 @@ def test_required_list_alias_by_name(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["header", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

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

View File

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

View File

@ -1,7 +1,7 @@
from typing import Annotated from typing import Annotated
import pytest import pytest
from dirty_equals import AnyThing, IsDict, IsOneOf, IsPartialDict from dirty_equals import AnyThing, IsOneOf, IsPartialDict
from fastapi import FastAPI, Header from fastapi import FastAPI, Header
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
@ -49,8 +49,7 @@ def test_required_str_missing(path: str):
client = TestClient(app) client = TestClient(app)
response = client.get(path) response = client.get(path)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -60,18 +59,6 @@ def test_required_str_missing(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["header", "p"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -126,8 +113,7 @@ def test_required_alias_missing(path: str):
client = TestClient(app) client = TestClient(app)
response = client.get(path) response = client.get(path)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -137,18 +123,6 @@ def test_required_alias_missing(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["header", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -162,8 +136,7 @@ def test_required_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 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -173,18 +146,6 @@ def test_required_alias_by_name(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["header", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -135,8 +135,7 @@ def test_required_list_alias_missing(path: str):
client = TestClient(app) client = TestClient(app)
response = client.get(path) response = client.get(path)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -146,18 +145,6 @@ def test_required_list_alias_missing(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -171,8 +158,7 @@ def test_required_list_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 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -182,18 +168,6 @@ def test_required_list_alias_by_name(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

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

View File

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

View File

@ -1,7 +1,7 @@
from typing import Annotated from typing import Annotated
import pytest import pytest
from dirty_equals import IsDict, IsOneOf from dirty_equals import IsOneOf
from fastapi import FastAPI, Query from fastapi import FastAPI, Query
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
@ -49,8 +49,7 @@ def test_required_str_missing(path: str):
client = TestClient(app) client = TestClient(app)
response = client.get(path) response = client.get(path)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -60,18 +59,6 @@ def test_required_str_missing(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "p"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -126,8 +113,7 @@ def test_required_alias_missing(path: str):
client = TestClient(app) client = TestClient(app)
response = client.get(path) response = client.get(path)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -137,18 +123,6 @@ def test_required_alias_missing(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -162,8 +136,7 @@ def test_required_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 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -176,18 +149,6 @@ def test_required_alias_by_name(path: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "p_alias"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -1,7 +1,6 @@
from typing import Union from typing import Union
import pytest import pytest
from dirty_equals import IsDict
from fastapi import Body, Cookie, FastAPI, Header, Path, Query from fastapi import Body, Cookie, FastAPI, Header, Path, Query
from fastapi.exceptions import FastAPIDeprecationWarning from fastapi.exceptions import FastAPIDeprecationWarning
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -336,28 +335,13 @@ def test_openapi_schema():
"requestBody": { "requestBody": {
"content": { "content": {
"application/json": { "application/json": {
"schema": IsDict( "schema": {
{
"$ref": "#/components/schemas/Item", "$ref": "#/components/schemas/Item",
"examples": [ "examples": [
{"data": "Data in Body examples, example1"}, {"data": "Data in Body examples, example1"},
{"data": "Data in Body examples, example2"}, {"data": "Data in Body examples, example2"},
], ],
} }
)
| IsDict(
# TODO: remove this when deprecating Pydantic v1
{
"allOf": [
{"$ref": "#/components/schemas/Item"}
],
"title": "Item",
"examples": [
{"data": "Data in Body examples, example1"},
{"data": "Data in Body examples, example2"},
],
}
)
} }
}, },
"required": True, "required": True,
@ -387,28 +371,13 @@ def test_openapi_schema():
"requestBody": { "requestBody": {
"content": { "content": {
"application/json": { "application/json": {
"schema": IsDict( "schema": {
{
"$ref": "#/components/schemas/Item", "$ref": "#/components/schemas/Item",
"examples": [ "examples": [
{"data": "examples example_examples 1"}, {"data": "examples example_examples 1"},
{"data": "examples example_examples 2"}, {"data": "examples example_examples 2"},
], ],
}
)
| IsDict(
# TODO: remove this when deprecating Pydantic v1
{
"allOf": [
{"$ref": "#/components/schemas/Item"}
],
"title": "Item",
"examples": [
{"data": "examples example_examples 1"},
{"data": "examples example_examples 2"},
],
}, },
),
"example": {"data": "Overridden example"}, "example": {"data": "Overridden example"},
} }
}, },
@ -539,16 +508,10 @@ def test_openapi_schema():
"parameters": [ "parameters": [
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Data", "title": "Data",
} },
)
| IsDict(
# TODO: Remove this when deprecating Pydantic v1
{"title": "Data", "type": "string"}
),
"example": "query1", "example": "query1",
"name": "data", "name": "data",
"in": "query", "in": "query",
@ -579,21 +542,11 @@ def test_openapi_schema():
"parameters": [ "parameters": [
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Data", "title": "Data",
"examples": ["query1", "query2"], "examples": ["query1", "query2"],
} },
)
| IsDict(
# TODO: Remove this when deprecating Pydantic v1
{
"type": "string",
"title": "Data",
"examples": ["query1", "query2"],
}
),
"name": "data", "name": "data",
"in": "query", "in": "query",
} }
@ -623,21 +576,11 @@ def test_openapi_schema():
"parameters": [ "parameters": [
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Data", "title": "Data",
"examples": ["query1", "query2"], "examples": ["query1", "query2"],
} },
)
| IsDict(
# TODO: Remove this when deprecating Pydantic v1
{
"type": "string",
"title": "Data",
"examples": ["query1", "query2"],
}
),
"example": "query_overridden", "example": "query_overridden",
"name": "data", "name": "data",
"in": "query", "in": "query",
@ -668,16 +611,10 @@ def test_openapi_schema():
"parameters": [ "parameters": [
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Data", "title": "Data",
} },
)
| IsDict(
# TODO: Remove this when deprecating Pydantic v1
{"title": "Data", "type": "string"}
),
"example": "header1", "example": "header1",
"name": "data", "name": "data",
"in": "header", "in": "header",
@ -708,21 +645,11 @@ def test_openapi_schema():
"parameters": [ "parameters": [
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Data", "title": "Data",
"examples": ["header1", "header2"], "examples": ["header1", "header2"],
} },
)
| IsDict(
# TODO: Remove this when deprecating Pydantic v1
{
"type": "string",
"title": "Data",
"examples": ["header1", "header2"],
}
),
"name": "data", "name": "data",
"in": "header", "in": "header",
} }
@ -752,21 +679,11 @@ def test_openapi_schema():
"parameters": [ "parameters": [
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Data", "title": "Data",
"examples": ["header1", "header2"], "examples": ["header1", "header2"],
} },
)
| IsDict(
# TODO: Remove this when deprecating Pydantic v1
{
"title": "Data",
"type": "string",
"examples": ["header1", "header2"],
}
),
"example": "header_overridden", "example": "header_overridden",
"name": "data", "name": "data",
"in": "header", "in": "header",
@ -797,16 +714,10 @@ def test_openapi_schema():
"parameters": [ "parameters": [
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Data", "title": "Data",
} },
)
| IsDict(
# TODO: Remove this when deprecating Pydantic v1
{"title": "Data", "type": "string"}
),
"example": "cookie1", "example": "cookie1",
"name": "data", "name": "data",
"in": "cookie", "in": "cookie",
@ -837,21 +748,11 @@ def test_openapi_schema():
"parameters": [ "parameters": [
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Data", "title": "Data",
"examples": ["cookie1", "cookie2"], "examples": ["cookie1", "cookie2"],
} },
)
| IsDict(
# TODO: Remove this when deprecating Pydantic v1
{
"title": "Data",
"type": "string",
"examples": ["cookie1", "cookie2"],
}
),
"name": "data", "name": "data",
"in": "cookie", "in": "cookie",
} }
@ -881,21 +782,11 @@ def test_openapi_schema():
"parameters": [ "parameters": [
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Data", "title": "Data",
"examples": ["cookie1", "cookie2"], "examples": ["cookie1", "cookie2"],
} },
)
| IsDict(
# TODO: Remove this when deprecating Pydantic v1
{
"title": "Data",
"type": "string",
"examples": ["cookie1", "cookie2"],
}
),
"example": "cookie_overridden", "example": "cookie_overridden",
"name": "data", "name": "data",
"in": "cookie", "in": "cookie",

View File

@ -1,5 +1,4 @@
import pytest import pytest
from dirty_equals import IsDict
from fastapi import Depends, FastAPI, Security from fastapi import Depends, FastAPI, Security
from fastapi.security import OAuth2, OAuth2PasswordRequestFormStrict from fastapi.security import OAuth2, OAuth2PasswordRequestFormStrict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -64,8 +63,7 @@ def test_security_oauth2_password_bearer_no_header():
def test_strict_login_no_data(): def test_strict_login_no_data():
response = client.post("/login") response = client.post("/login")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -87,35 +85,12 @@ def test_strict_login_no_data():
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "grant_type"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "username"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "password"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_strict_login_no_grant_type(): def test_strict_login_no_grant_type():
response = client.post("/login", data={"username": "johndoe", "password": "secret"}) response = client.post("/login", data={"username": "johndoe", "password": "secret"})
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -125,18 +100,6 @@ def test_strict_login_no_grant_type():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "grant_type"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -153,8 +116,7 @@ def test_strict_login_incorrect_grant_type(grant_type: str):
data={"username": "johndoe", "password": "secret", "grant_type": grant_type}, data={"username": "johndoe", "password": "secret", "grant_type": grant_type},
) )
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "string_pattern_mismatch", "type": "string_pattern_mismatch",
@ -165,19 +127,6 @@ def test_strict_login_incorrect_grant_type(grant_type: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "grant_type"],
"msg": 'string does not match regex "^password$"',
"type": "value_error.str.regex",
"ctx": {"pattern": "^password$"},
}
]
}
)
def test_strict_login_correct_grant_type(): def test_strict_login_correct_grant_type():
@ -264,26 +213,14 @@ def test_openapi_schema():
"username": {"title": "Username", "type": "string"}, "username": {"title": "Username", "type": "string"},
"password": {"title": "Password", "type": "string"}, "password": {"title": "Password", "type": "string"},
"scope": {"title": "Scope", "type": "string", "default": ""}, "scope": {"title": "Scope", "type": "string", "default": ""},
"client_id": IsDict( "client_id": {
{
"title": "Client Id", "title": "Client Id",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
) "client_secret": {
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Client Id", "type": "string"}
),
"client_secret": IsDict(
{
"title": "Client Secret", "title": "Client Secret",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Client Secret", "type": "string"}
),
}, },
}, },
"ValidationError": { "ValidationError": {

View File

@ -1,7 +1,6 @@
from typing import Optional from typing import Optional
import pytest import pytest
from dirty_equals import IsDict
from fastapi import Depends, FastAPI, Security from fastapi import Depends, FastAPI, Security
from fastapi.security import OAuth2, OAuth2PasswordRequestFormStrict from fastapi.security import OAuth2, OAuth2PasswordRequestFormStrict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -67,8 +66,7 @@ def test_security_oauth2_password_bearer_no_header():
def test_strict_login_no_data(): def test_strict_login_no_data():
response = client.post("/login") response = client.post("/login")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -90,35 +88,12 @@ def test_strict_login_no_data():
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "grant_type"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "username"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "password"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_strict_login_no_grant_type(): def test_strict_login_no_grant_type():
response = client.post("/login", data={"username": "johndoe", "password": "secret"}) response = client.post("/login", data={"username": "johndoe", "password": "secret"})
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -128,18 +103,6 @@ def test_strict_login_no_grant_type():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "grant_type"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -156,8 +119,7 @@ def test_strict_login_incorrect_grant_type(grant_type: str):
data={"username": "johndoe", "password": "secret", "grant_type": grant_type}, data={"username": "johndoe", "password": "secret", "grant_type": grant_type},
) )
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "string_pattern_mismatch", "type": "string_pattern_mismatch",
@ -168,19 +130,6 @@ def test_strict_login_incorrect_grant_type(grant_type: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "grant_type"],
"msg": 'string does not match regex "^password$"',
"type": "value_error.str.regex",
"ctx": {"pattern": "^password$"},
}
]
}
)
def test_strict_login_correct_data(): def test_strict_login_correct_data():
@ -267,26 +216,14 @@ def test_openapi_schema():
"username": {"title": "Username", "type": "string"}, "username": {"title": "Username", "type": "string"},
"password": {"title": "Password", "type": "string"}, "password": {"title": "Password", "type": "string"},
"scope": {"title": "Scope", "type": "string", "default": ""}, "scope": {"title": "Scope", "type": "string", "default": ""},
"client_id": IsDict( "client_id": {
{
"title": "Client Id", "title": "Client Id",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
) "client_secret": {
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Client Id", "type": "string"}
),
"client_secret": IsDict(
{
"title": "Client Secret", "title": "Client Secret",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Client Secret", "type": "string"}
),
}, },
}, },
"ValidationError": { "ValidationError": {

View File

@ -1,7 +1,6 @@
from typing import Optional from typing import Optional
import pytest import pytest
from dirty_equals import IsDict
from fastapi import Depends, FastAPI, Security from fastapi import Depends, FastAPI, Security
from fastapi.security import OAuth2, OAuth2PasswordRequestFormStrict from fastapi.security import OAuth2, OAuth2PasswordRequestFormStrict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -68,8 +67,7 @@ def test_security_oauth2_password_bearer_no_header():
def test_strict_login_None(): def test_strict_login_None():
response = client.post("/login", data=None) response = client.post("/login", data=None)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -91,35 +89,12 @@ def test_strict_login_None():
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "grant_type"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "username"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "password"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_strict_login_no_grant_type(): def test_strict_login_no_grant_type():
response = client.post("/login", data={"username": "johndoe", "password": "secret"}) response = client.post("/login", data={"username": "johndoe", "password": "secret"})
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -129,18 +104,6 @@ def test_strict_login_no_grant_type():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "grant_type"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -157,8 +120,7 @@ def test_strict_login_incorrect_grant_type(grant_type: str):
data={"username": "johndoe", "password": "secret", "grant_type": grant_type}, data={"username": "johndoe", "password": "secret", "grant_type": grant_type},
) )
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "string_pattern_mismatch", "type": "string_pattern_mismatch",
@ -169,19 +131,6 @@ def test_strict_login_incorrect_grant_type(grant_type: str):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "grant_type"],
"msg": 'string does not match regex "^password$"',
"type": "value_error.str.regex",
"ctx": {"pattern": "^password$"},
}
]
}
)
def test_strict_login_correct_correct_grant_type(): def test_strict_login_correct_correct_grant_type():
@ -268,26 +217,14 @@ def test_openapi_schema():
"username": {"title": "Username", "type": "string"}, "username": {"title": "Username", "type": "string"},
"password": {"title": "Password", "type": "string"}, "password": {"title": "Password", "type": "string"},
"scope": {"title": "Scope", "type": "string", "default": ""}, "scope": {"title": "Scope", "type": "string", "default": ""},
"client_id": IsDict( "client_id": {
{
"title": "Client Id", "title": "Client Id",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
) "client_secret": {
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Client Id", "type": "string"}
),
"client_secret": IsDict(
{
"title": "Client Secret", "title": "Client Secret",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Client Secret", "type": "string"}
),
}, },
}, },
"ValidationError": { "ValidationError": {

View File

@ -1,6 +1,5 @@
from typing import Optional from typing import Optional
from dirty_equals import IsDict
from fastapi import APIRouter, FastAPI from fastapi import APIRouter, FastAPI
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from pydantic import BaseModel, HttpUrl from pydantic import BaseModel, HttpUrl
@ -99,8 +98,7 @@ def test_openapi_schema():
"parameters": [ "parameters": [
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"title": "Callback Url", "title": "Callback Url",
"anyOf": [ "anyOf": [
{ {
@ -111,18 +109,7 @@ def test_openapi_schema():
}, },
{"type": "null"}, {"type": "null"},
], ],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "Callback Url",
"maxLength": 2083,
"minLength": 1,
"type": "string",
"format": "uri",
}
),
"name": "callback_url", "name": "callback_url",
"in": "query", "in": "query",
} }
@ -262,16 +249,10 @@ def test_openapi_schema():
"type": "object", "type": "object",
"properties": { "properties": {
"id": {"title": "Id", "type": "string"}, "id": {"title": "Id", "type": "string"},
"title": IsDict( "title": {
{
"title": "Title", "title": "Title",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Title", "type": "string"}
),
"customer": {"title": "Customer", "type": "string"}, "customer": {"title": "Customer", "type": "string"},
"total": {"title": "Total", "type": "number"}, "total": {"title": "Total", "type": "number"},
}, },

View File

@ -1,4 +1,3 @@
from dirty_equals import IsDict
from fastapi import FastAPI, Form from fastapi import FastAPI, Form
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from pydantic import BaseModel from pydantic import BaseModel
@ -125,8 +124,7 @@ def test_openapi_schema():
"requestBody": { "requestBody": {
"content": { "content": {
"application/json": { "application/json": {
"schema": IsDict( "schema": {
{
"title": "Square", "title": "Square",
"maxItems": 2, "maxItems": 2,
"minItems": 2, "minItems": 2,
@ -136,20 +134,6 @@ def test_openapi_schema():
{"$ref": "#/components/schemas/Coordinate"}, {"$ref": "#/components/schemas/Coordinate"},
], ],
} }
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "Square",
"maxItems": 2,
"minItems": 2,
"type": "array",
"items": [
{"$ref": "#/components/schemas/Coordinate"},
{"$ref": "#/components/schemas/Coordinate"},
],
}
)
} }
}, },
"required": True, "required": True,
@ -212,8 +196,7 @@ def test_openapi_schema():
"required": ["values"], "required": ["values"],
"type": "object", "type": "object",
"properties": { "properties": {
"values": IsDict( "values": {
{
"title": "Values", "title": "Values",
"maxItems": 2, "maxItems": 2,
"minItems": 2, "minItems": 2,
@ -223,17 +206,6 @@ def test_openapi_schema():
{"type": "integer"}, {"type": "integer"},
], ],
} }
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "Values",
"maxItems": 2,
"minItems": 2,
"type": "array",
"items": [{"type": "integer"}, {"type": "integer"}],
}
)
}, },
}, },
"Coordinate": { "Coordinate": {
@ -264,8 +236,7 @@ def test_openapi_schema():
"items": { "items": {
"title": "Items", "title": "Items",
"type": "array", "type": "array",
"items": IsDict( "items": {
{
"maxItems": 2, "maxItems": 2,
"minItems": 2, "minItems": 2,
"type": "array", "type": "array",
@ -273,17 +244,7 @@ def test_openapi_schema():
{"type": "string"}, {"type": "string"},
{"type": "string"}, {"type": "string"},
], ],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"maxItems": 2,
"minItems": 2,
"type": "array",
"items": [{"type": "string"}, {"type": "string"}],
}
),
} }
}, },
}, },

View File

@ -3,7 +3,6 @@ import os
import shutil import shutil
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from tests.utils import needs_py310 from tests.utils import needs_py310
@ -80,16 +79,10 @@ def test_openapi_schema(client: TestClient):
}, },
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "boolean"}, {"type": "null"}], "anyOf": [{"type": "boolean"}, {"type": "null"}],
"title": "Img", "title": "Img",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Img", "type": "boolean"}
),
"name": "img", "name": "img",
"in": "query", "in": "query",
}, },

View File

@ -3,7 +3,6 @@ import os
import shutil import shutil
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from tests.utils import needs_py310 from tests.utils import needs_py310
@ -83,16 +82,10 @@ def test_openapi_schema(client: TestClient):
}, },
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "boolean"}, {"type": "null"}], "anyOf": [{"type": "boolean"}, {"type": "null"}],
"title": "Img", "title": "Img",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Img", "type": "boolean"}
),
"name": "img", "name": "img",
"in": "query", "in": "query",
}, },

View File

@ -1,5 +1,5 @@
from dirty_equals import IsOneOf
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from docs_src.behind_a_proxy.tutorial003_py39 import app from docs_src.behind_a_proxy.tutorial003_py39 import app
@ -15,25 +15,18 @@ def test_main():
def test_openapi_schema(): def test_openapi_schema():
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200 assert response.status_code == 200
assert response.json() == { assert response.json() == snapshot(
{
"openapi": "3.1.0", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"servers": [ "servers": [
{"url": "/api/v1"}, {"url": "/api/v1"},
{ {
"url": IsOneOf( "url": "https://stag.example.com",
"https://stag.example.com/",
# TODO: remove when deprecating Pydantic v1
"https://stag.example.com",
),
"description": "Staging environment", "description": "Staging environment",
}, },
{ {
"url": IsOneOf( "url": "https://prod.example.com",
"https://prod.example.com/",
# TODO: remove when deprecating Pydantic v1
"https://prod.example.com",
),
"description": "Production environment", "description": "Production environment",
}, },
], ],
@ -52,3 +45,4 @@ def test_openapi_schema():
} }
}, },
} }
)

View File

@ -1,5 +1,5 @@
from dirty_equals import IsOneOf
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from docs_src.behind_a_proxy.tutorial004_py39 import app from docs_src.behind_a_proxy.tutorial004_py39 import app
@ -15,24 +15,17 @@ def test_main():
def test_openapi_schema(): def test_openapi_schema():
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200 assert response.status_code == 200
assert response.json() == { assert response.json() == snapshot(
{
"openapi": "3.1.0", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"servers": [ "servers": [
{ {
"url": IsOneOf( "url": "https://stag.example.com",
"https://stag.example.com/",
# TODO: remove when deprecating Pydantic v1
"https://stag.example.com",
),
"description": "Staging environment", "description": "Staging environment",
}, },
{ {
"url": IsOneOf( "url": "https://prod.example.com",
"https://prod.example.com/",
# TODO: remove when deprecating Pydantic v1
"https://prod.example.com",
),
"description": "Production environment", "description": "Production environment",
}, },
], ],
@ -51,3 +44,4 @@ def test_openapi_schema():
} }
}, },
} }
)

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -28,8 +27,7 @@ def test_users_token_jessica(client: TestClient):
def test_users_with_no_token(client: TestClient): def test_users_with_no_token(client: TestClient):
response = client.get("/users") response = client.get("/users")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -39,18 +37,6 @@ def test_users_with_no_token(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "token"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_users_foo_token_jessica(client: TestClient): def test_users_foo_token_jessica(client: TestClient):
@ -62,8 +48,7 @@ def test_users_foo_token_jessica(client: TestClient):
def test_users_foo_with_no_token(client: TestClient): def test_users_foo_with_no_token(client: TestClient):
response = client.get("/users/foo") response = client.get("/users/foo")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -73,18 +58,6 @@ def test_users_foo_with_no_token(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "token"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_users_me_token_jessica(client: TestClient): def test_users_me_token_jessica(client: TestClient):
@ -96,8 +69,7 @@ def test_users_me_token_jessica(client: TestClient):
def test_users_me_with_no_token(client: TestClient): def test_users_me_with_no_token(client: TestClient):
response = client.get("/users/me") response = client.get("/users/me")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -107,18 +79,6 @@ def test_users_me_with_no_token(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "token"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_users_token_monica_with_no_jessica(client: TestClient): def test_users_token_monica_with_no_jessica(client: TestClient):
@ -141,8 +101,7 @@ def test_items_token_jessica(client: TestClient):
def test_items_with_no_token_jessica(client: TestClient): def test_items_with_no_token_jessica(client: TestClient):
response = client.get("/items", headers={"X-Token": "fake-super-secret-token"}) response = client.get("/items", headers={"X-Token": "fake-super-secret-token"})
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -152,18 +111,6 @@ def test_items_with_no_token_jessica(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "token"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_items_plumbus_token_jessica(client: TestClient): def test_items_plumbus_token_jessica(client: TestClient):
@ -187,8 +134,7 @@ def test_items_plumbus_with_no_token(client: TestClient):
"/items/plumbus", headers={"X-Token": "fake-super-secret-token"} "/items/plumbus", headers={"X-Token": "fake-super-secret-token"}
) )
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -198,18 +144,6 @@ def test_items_plumbus_with_no_token(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "token"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_items_with_invalid_token(client: TestClient): def test_items_with_invalid_token(client: TestClient):
@ -227,8 +161,7 @@ def test_items_bar_with_invalid_token(client: TestClient):
def test_items_with_missing_x_token_header(client: TestClient): def test_items_with_missing_x_token_header(client: TestClient):
response = client.get("/items?token=jessica") response = client.get("/items?token=jessica")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -238,25 +171,12 @@ def test_items_with_missing_x_token_header(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["header", "x-token"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_items_plumbus_with_missing_x_token_header(client: TestClient): def test_items_plumbus_with_missing_x_token_header(client: TestClient):
response = client.get("/items/plumbus?token=jessica") response = client.get("/items/plumbus?token=jessica")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -266,18 +186,6 @@ def test_items_plumbus_with_missing_x_token_header(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["header", "x-token"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_root_token_jessica(client: TestClient): def test_root_token_jessica(client: TestClient):
@ -289,8 +197,7 @@ def test_root_token_jessica(client: TestClient):
def test_root_with_no_token(client: TestClient): def test_root_with_no_token(client: TestClient):
response = client.get("/") response = client.get("/")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -300,25 +207,12 @@ def test_root_with_no_token(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "token"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_put_no_header(client: TestClient): def test_put_no_header(client: TestClient):
response = client.put("/items/foo") response = client.put("/items/foo")
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -334,23 +228,6 @@ def test_put_no_header(client: TestClient):
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "token"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["header", "x-token"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_put_invalid_header(client: TestClient): def test_put_invalid_header(client: TestClient):

View File

@ -2,7 +2,6 @@ import importlib
from unittest.mock import patch from unittest.mock import patch
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from ...utils import needs_py310 from ...utils import needs_py310
@ -74,8 +73,7 @@ def test_post_with_str_float_description_tax(client: TestClient):
def test_post_with_only_name(client: TestClient): def test_post_with_only_name(client: TestClient):
response = client.post("/items/", json={"name": "Foo"}) response = client.post("/items/", json={"name": "Foo"})
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -85,25 +83,12 @@ def test_post_with_only_name(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "price"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_post_with_only_name_price(client: TestClient): def test_post_with_only_name_price(client: TestClient):
response = client.post("/items/", json={"name": "Foo", "price": "twenty"}) response = client.post("/items/", json={"name": "Foo", "price": "twenty"})
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "float_parsing", "type": "float_parsing",
@ -113,25 +98,12 @@ def test_post_with_only_name_price(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "price"],
"msg": "value is not a valid float",
"type": "type_error.float",
}
]
}
)
def test_post_with_no_data(client: TestClient): def test_post_with_no_data(client: TestClient):
response = client.post("/items/", json={}) response = client.post("/items/", json={})
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -147,30 +119,12 @@ def test_post_with_no_data(client: TestClient):
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "name"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "price"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_post_with_none(client: TestClient): def test_post_with_none(client: TestClient):
response = client.post("/items/", json=None) response = client.post("/items/", json=None)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -180,18 +134,6 @@ def test_post_with_none(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_post_broken_body(client: TestClient): def test_post_broken_body(client: TestClient):
@ -201,46 +143,23 @@ def test_post_broken_body(client: TestClient):
content="{some broken json}", content="{some broken json}",
) )
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "json_invalid", "type": "json_invalid",
"loc": ["body", 1], "loc": ["body", 1],
"msg": "JSON decode error", "msg": "JSON decode error",
"input": {}, "input": {},
"ctx": { "ctx": {"error": "Expecting property name enclosed in double quotes"},
"error": "Expecting property name enclosed in double quotes"
},
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", 1],
"msg": "Expecting property name enclosed in double quotes: line 1 column 2 (char 1)",
"type": "value_error.jsondecode",
"ctx": {
"msg": "Expecting property name enclosed in double quotes",
"doc": "{some broken json}",
"pos": 1,
"lineno": 1,
"colno": 2,
},
}
]
}
)
def test_post_form_for_json(client: TestClient): def test_post_form_for_json(client: TestClient):
response = client.post("/items/", data={"name": "Foo", "price": 50.5}) response = client.post("/items/", data={"name": "Foo", "price": 50.5})
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "model_attributes_type", "type": "model_attributes_type",
@ -250,18 +169,6 @@ def test_post_form_for_json(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body"],
"msg": "value is not a valid dict",
"type": "type_error.dict",
}
]
}
)
def test_explicit_content_type(client: TestClient): def test_explicit_content_type(client: TestClient):
@ -302,8 +209,7 @@ def test_wrong_headers(client: TestClient):
"/items/", content=data, headers={"Content-Type": "text/plain"} "/items/", content=data, headers={"Content-Type": "text/plain"}
) )
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "model_attributes_type", "type": "model_attributes_type",
@ -313,25 +219,12 @@ def test_wrong_headers(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body"],
"msg": "value is not a valid dict",
"type": "type_error.dict",
}
]
}
)
response = client.post( response = client.post(
"/items/", content=data, headers={"Content-Type": "application/geo+json-seq"} "/items/", content=data, headers={"Content-Type": "application/geo+json-seq"}
) )
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "model_attributes_type", "type": "model_attributes_type",
@ -341,24 +234,12 @@ def test_wrong_headers(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body"],
"msg": "value is not a valid dict",
"type": "type_error.dict",
}
]
}
)
response = client.post( response = client.post(
"/items/", content=data, headers={"Content-Type": "application/not-really-json"} "/items/", content=data, headers={"Content-Type": "application/not-really-json"}
) )
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "model_attributes_type", "type": "model_attributes_type",
@ -368,18 +249,6 @@ def test_wrong_headers(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body"],
"msg": "value is not a valid dict",
"type": "type_error.dict",
}
]
}
)
def test_other_exceptions(client: TestClient): def test_other_exceptions(client: TestClient):
@ -435,26 +304,14 @@ def test_openapi_schema(client: TestClient):
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"price": {"title": "Price", "type": "number"}, "price": {"title": "Price", "type": "number"},
"description": IsDict( "description": {
{
"title": "Description", "title": "Description",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
) "tax": {
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Description", "type": "string"}
),
"tax": IsDict(
{
"title": "Tax", "title": "Tax",
"anyOf": [{"type": "number"}, {"type": "null"}], "anyOf": [{"type": "number"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Tax", "type": "number"}
),
}, },
}, },
"ValidationError": { "ValidationError": {

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from ...utils import needs_py310 from ...utils import needs_py310
@ -59,8 +58,7 @@ def test_items_6(client: TestClient):
def test_invalid_price(client: TestClient): def test_invalid_price(client: TestClient):
response = client.put("/items/5", json={"item": {"name": "Foo", "price": -3.0}}) response = client.put("/items/5", json={"item": {"name": "Foo", "price": -3.0}})
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "greater_than", "type": "greater_than",
@ -71,19 +69,6 @@ def test_invalid_price(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"ctx": {"limit_value": 0},
"loc": ["body", "item", "price"],
"msg": "ensure this value is greater than 0",
"type": "value_error.number.not_gt",
}
]
}
)
def test_openapi_schema(client: TestClient): def test_openapi_schema(client: TestClient):
@ -142,39 +127,23 @@ def test_openapi_schema(client: TestClient):
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"description": IsDict( "description": {
{
"title": "The description of the item", "title": "The description of the item",
"anyOf": [ "anyOf": [
{"maxLength": 300, "type": "string"}, {"maxLength": 300, "type": "string"},
{"type": "null"}, {"type": "null"},
], ],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "The description of the item",
"maxLength": 300,
"type": "string",
}
),
"price": { "price": {
"title": "Price", "title": "Price",
"exclusiveMinimum": 0.0, "exclusiveMinimum": 0.0,
"type": "number", "type": "number",
"description": "The price must be greater than zero", "description": "The price must be greater than zero",
}, },
"tax": IsDict( "tax": {
{
"title": "Tax", "title": "Tax",
"anyOf": [{"type": "number"}, {"type": "null"}], "anyOf": [{"type": "number"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Tax", "type": "number"}
),
}, },
}, },
"Body_update_item_items__item_id__put": { "Body_update_item_items__item_id__put": {

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from ...utils import needs_py310 from ...utils import needs_py310
@ -53,8 +52,7 @@ def test_post_no_body(client: TestClient):
def test_post_id_foo(client: TestClient): def test_post_id_foo(client: TestClient):
response = client.put("/items/foo", json=None) response = client.put("/items/foo", json=None)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -64,18 +62,6 @@ def test_post_id_foo(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
}
)
def test_openapi_schema(client: TestClient): def test_openapi_schema(client: TestClient):
@ -119,16 +105,10 @@ def test_openapi_schema(client: TestClient):
}, },
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Q", "title": "Q",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Q", "type": "string"}
),
"name": "q", "name": "q",
"in": "query", "in": "query",
}, },
@ -136,19 +116,13 @@ def test_openapi_schema(client: TestClient):
"requestBody": { "requestBody": {
"content": { "content": {
"application/json": { "application/json": {
"schema": IsDict( "schema": {
{
"anyOf": [ "anyOf": [
{"$ref": "#/components/schemas/Item"}, {"$ref": "#/components/schemas/Item"},
{"type": "null"}, {"type": "null"},
], ],
"title": "Item", "title": "Item",
} }
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"$ref": "#/components/schemas/Item"}
)
} }
} }
}, },
@ -163,27 +137,15 @@ def test_openapi_schema(client: TestClient):
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"description": IsDict( "description": {
{
"title": "Description", "title": "Description",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Description", "type": "string"}
),
"price": {"title": "Price", "type": "number"}, "price": {"title": "Price", "type": "number"},
"tax": IsDict( "tax": {
{
"title": "Tax", "title": "Tax",
"anyOf": [{"type": "number"}, {"type": "null"}], "anyOf": [{"type": "number"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Tax", "type": "number"}
),
}, },
}, },
"ValidationError": { "ValidationError": {

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from ...utils import needs_py310 from ...utils import needs_py310
@ -49,8 +48,7 @@ def test_post_body_valid(client: TestClient):
def test_post_body_no_data(client: TestClient): def test_post_body_no_data(client: TestClient):
response = client.put("/items/5", json=None) response = client.put("/items/5", json=None)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -72,35 +70,12 @@ def test_post_body_no_data(client: TestClient):
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "item"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "user"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "importance"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_post_body_empty_list(client: TestClient): def test_post_body_empty_list(client: TestClient):
response = client.put("/items/5", json=[]) response = client.put("/items/5", json=[])
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -122,28 +97,6 @@ def test_post_body_empty_list(client: TestClient):
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "item"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "user"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "importance"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_openapi_schema(client: TestClient): def test_openapi_schema(client: TestClient):
@ -202,27 +155,15 @@ def test_openapi_schema(client: TestClient):
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"description": IsDict( "description": {
{
"title": "Description", "title": "Description",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Description", "type": "string"}
),
"price": {"title": "Price", "type": "number"}, "price": {"title": "Price", "type": "number"},
"tax": IsDict( "tax": {
{
"title": "Tax", "title": "Tax",
"anyOf": [{"type": "number"}, {"type": "null"}], "anyOf": [{"type": "number"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Tax", "type": "number"}
),
}, },
}, },
"User": { "User": {
@ -231,16 +172,10 @@ def test_openapi_schema(client: TestClient):
"type": "object", "type": "object",
"properties": { "properties": {
"username": {"title": "Username", "type": "string"}, "username": {"title": "Username", "type": "string"},
"full_name": IsDict( "full_name": {
{
"title": "Full Name", "title": "Full Name",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Full Name", "type": "string"}
),
}, },
}, },
"Body_update_item_items__item_id__put": { "Body_update_item_items__item_id__put": {

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -29,8 +28,7 @@ def test_post_invalid_body(client: TestClient):
data = {"foo": 2.2, "3": 3.3} data = {"foo": 2.2, "3": 3.3}
response = client.post("/index-weights/", json=data) response = client.post("/index-weights/", json=data)
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -40,18 +38,6 @@ def test_post_invalid_body(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "__key__"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
}
)
def test_openapi_schema(client: TestClient): def test_openapi_schema(client: TestClient):

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot from inline_snapshot import snapshot
@ -54,7 +53,6 @@ def test_cookie_param_model_invalid(client: TestClient):
response = client.get("/items/") response = client.get("/items/")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == snapshot( assert response.json() == snapshot(
IsDict(
{ {
"detail": [ "detail": [
{ {
@ -66,19 +64,6 @@ def test_cookie_param_model_invalid(client: TestClient):
] ]
} }
) )
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"type": "value_error.missing",
"loc": ["cookie", "session_id"],
"msg": "field required",
}
]
}
)
)
def test_cookie_param_model_extra(client: TestClient): def test_cookie_param_model_extra(client: TestClient):
@ -115,37 +100,19 @@ def test_openapi_schema(client: TestClient):
"name": "fatebook_tracker", "name": "fatebook_tracker",
"in": "cookie", "in": "cookie",
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Fatebook Tracker", "title": "Fatebook Tracker",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "string",
"title": "Fatebook Tracker",
}
),
}, },
{ {
"name": "googall_tracker", "name": "googall_tracker",
"in": "cookie", "in": "cookie",
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Googall Tracker", "title": "Googall Tracker",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "string",
"title": "Googall Tracker",
}
),
}, },
], ],
"responses": { "responses": {

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot from inline_snapshot import snapshot
@ -72,7 +71,6 @@ def test_cookie_param_model_extra(client: TestClient):
response = c.get("/items/") response = c.get("/items/")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == snapshot( assert response.json() == snapshot(
IsDict(
{ {
"detail": [ "detail": [
{ {
@ -84,19 +82,6 @@ def test_cookie_param_model_extra(client: TestClient):
] ]
} }
) )
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"type": "value_error.extra",
"loc": ["cookie", "extra"],
"msg": "extra fields not permitted",
}
]
}
)
)
def test_openapi_schema(client: TestClient): def test_openapi_schema(client: TestClient):
@ -134,19 +119,10 @@ def test_openapi_schema(client: TestClient):
"name": "googall_tracker", "name": "googall_tracker",
"in": "cookie", "in": "cookie",
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Googall Tracker", "title": "Googall Tracker",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "string",
"title": "Googall Tracker",
}
),
}, },
], ],
"responses": { "responses": {

View File

@ -2,7 +2,6 @@ import importlib
from types import ModuleType from types import ModuleType
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from ...utils import needs_py310 from ...utils import needs_py310
@ -75,16 +74,10 @@ def test_openapi_schema(mod: ModuleType):
"parameters": [ "parameters": [
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Ads Id", "title": "Ads Id",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Ads Id", "type": "string"}
),
"name": "ads_id", "name": "ads_id",
"in": "cookie", "in": "cookie",
} }

View File

@ -1,7 +1,7 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict, IsOneOf from dirty_equals import IsOneOf
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from tests.utils import needs_py310 from tests.utils import needs_py310
@ -30,8 +30,7 @@ def test_endpoint_works(client: TestClient):
def test_exception_handler_body_access(client: TestClient): def test_exception_handler_body_access(client: TestClient):
response = client.post("/", json={"numbers": [1, 2, 3]}) response = client.post("/", json={"numbers": [1, 2, 3]})
assert response.json() == IsDict( assert response.json() == {
{
"detail": { "detail": {
"errors": [ "errors": [
{ {
@ -45,19 +44,3 @@ def test_exception_handler_body_access(client: TestClient):
"body": IsOneOf('{"numbers": [1, 2, 3]}', '{"numbers":[1,2,3]}'), "body": IsOneOf('{"numbers": [1, 2, 3]}', '{"numbers":[1,2,3]}'),
} }
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": {
# httpx 0.28.0 switches to compact JSON https://github.com/encode/httpx/issues/3363
"body": IsOneOf('{"numbers": [1, 2, 3]}', '{"numbers":[1,2,3]}'),
"errors": [
{
"loc": ["body"],
"msg": "value is not a valid list",
"type": "type_error.list",
}
],
}
}
)

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from tests.utils import needs_py310 from tests.utils import needs_py310
@ -36,8 +35,7 @@ def test_post_item(client: TestClient):
def test_post_invalid_item(client: TestClient): def test_post_invalid_item(client: TestClient):
response = client.post("/items/", json={"name": "Foo", "price": "invalid price"}) response = client.post("/items/", json={"name": "Foo", "price": "invalid price"})
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "float_parsing", "type": "float_parsing",
@ -47,18 +45,6 @@ def test_post_invalid_item(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "price"],
"msg": "value is not a valid float",
"type": "type_error.float",
}
]
}
)
def test_openapi_schema(client: TestClient): def test_openapi_schema(client: TestClient):
@ -119,26 +105,14 @@ def test_openapi_schema(client: TestClient):
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"price": {"title": "Price", "type": "number"}, "price": {"title": "Price", "type": "number"},
"description": IsDict( "description": {
{
"title": "Description", "title": "Description",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
) "tax": {
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Description", "type": "string"}
),
"tax": IsDict(
{
"title": "Tax", "title": "Tax",
"anyOf": [{"type": "number"}, {"type": "null"}], "anyOf": [{"type": "number"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Tax", "type": "number"}
),
}, },
}, },
"ValidationError": { "ValidationError": {

View File

@ -1,8 +1,8 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict, IsOneOf
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from tests.utils import needs_py310 from tests.utils import needs_py310
@ -37,7 +37,8 @@ def test_get_item(client: TestClient):
def test_openapi_schema(client: TestClient): def test_openapi_schema(client: TestClient):
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200 assert response.status_code == 200
assert response.json() == { assert response.json() == snapshot(
{
"openapi": "3.1.0", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
@ -62,52 +63,27 @@ def test_openapi_schema(client: TestClient):
"schemas": { "schemas": {
"Item": { "Item": {
"title": "Item", "title": "Item",
"required": IsOneOf( "required": ["name", "price"],
["name", "price", "tags", "description", "tax"],
# TODO: remove when deprecating Pydantic v1
["name", "price"],
),
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"price": {"title": "Price", "type": "number"}, "price": {"title": "Price", "type": "number"},
"tags": IsDict( "tags": {
{
"title": "Tags", "title": "Tags",
"type": "array", "type": "array",
"items": {"type": "string"}, "items": {"type": "string"},
} },
) "description": {
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "Tags",
"type": "array",
"items": {"type": "string"},
}
),
"description": IsDict(
{
"title": "Description", "title": "Description",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
) "tax": {
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Description", "type": "string"}
),
"tax": IsDict(
{
"title": "Tax", "title": "Tax",
"anyOf": [{"type": "number"}, {"type": "null"}], "anyOf": [{"type": "number"}, {"type": "null"}],
},
},
}
}
},
} }
) )
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Tax", "type": "number"}
),
},
}
}
},
}

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -22,8 +21,7 @@ def get_client(request: pytest.FixtureRequest):
def test_get_no_headers(client: TestClient): def test_get_no_headers(client: TestClient):
response = client.get("/items/") response = client.get("/items/")
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -39,23 +37,6 @@ def test_get_no_headers(client: TestClient):
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["header", "x-token"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["header", "x-key"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_get_invalid_one_header(client: TestClient): def test_get_invalid_one_header(client: TestClient):

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -22,8 +21,7 @@ def get_client(request: pytest.FixtureRequest):
def test_get_no_headers_items(client: TestClient): def test_get_no_headers_items(client: TestClient):
response = client.get("/items/") response = client.get("/items/")
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -39,30 +37,12 @@ def test_get_no_headers_items(client: TestClient):
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["header", "x-token"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["header", "x-key"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_get_no_headers_users(client: TestClient): def test_get_no_headers_users(client: TestClient):
response = client.get("/users/") response = client.get("/users/")
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -78,23 +58,6 @@ def test_get_no_headers_users(client: TestClient):
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["header", "x-token"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["header", "x-key"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_get_invalid_one_header_items(client: TestClient): def test_get_invalid_one_header_items(client: TestClient):

View File

@ -1,8 +1,8 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from ...utils import needs_py310 from ...utils import needs_py310
@ -47,7 +47,8 @@ def test_extra_types(client: TestClient):
def test_openapi_schema(client: TestClient): def test_openapi_schema(client: TestClient):
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.json() == { assert response.json() == snapshot(
{
"openapi": "3.1.0", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
@ -87,22 +88,9 @@ def test_openapi_schema(client: TestClient):
"required": True, "required": True,
"content": { "content": {
"application/json": { "application/json": {
"schema": IsDict( "schema": {
{
"allOf": [
{
"$ref": "#/components/schemas/Body_read_items_items__item_id__put" "$ref": "#/components/schemas/Body_read_items_items__item_id__put"
} }
],
"title": "Body",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"$ref": "#/components/schemas/Body_read_items_items__item_id__put"
}
)
} }
}, },
}, },
@ -125,38 +113,18 @@ def test_openapi_schema(client: TestClient):
"type": "string", "type": "string",
"format": "date-time", "format": "date-time",
}, },
"repeat_at": IsDict( "repeat_at": {
{
"title": "Repeat At", "title": "Repeat At",
"anyOf": [ "anyOf": [
{"type": "string", "format": "time"}, {"type": "string", "format": "time"},
{"type": "null"}, {"type": "null"},
], ],
} },
) "process_after": {
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "Repeat At",
"type": "string",
"format": "time",
}
),
"process_after": IsDict(
{
"title": "Process After", "title": "Process After",
"type": "string", "type": "string",
"format": "duration", "format": "duration",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "Process After",
"type": "number",
"format": "time-delta",
}
),
}, },
"required": ["start_datetime", "end_datetime", "process_after"], "required": ["start_datetime", "end_datetime", "process_after"],
}, },
@ -183,10 +151,13 @@ def test_openapi_schema(client: TestClient):
"detail": { "detail": {
"title": "Detail", "title": "Detail",
"type": "array", "type": "array",
"items": {"$ref": "#/components/schemas/ValidationError"}, "items": {
"$ref": "#/components/schemas/ValidationError"
},
} }
}, },
}, },
} }
}, },
} }
)

View File

@ -1,8 +1,8 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsOneOf
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from ...utils import needs_py310 from ...utils import needs_py310
@ -43,7 +43,8 @@ def test_get_plane(client: TestClient):
def test_openapi_schema(client: TestClient): def test_openapi_schema(client: TestClient):
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.json() == { assert response.json() == snapshot(
{
"openapi": "3.1.0", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
@ -57,8 +58,12 @@ def test_openapi_schema(client: TestClient):
"schema": { "schema": {
"title": "Response Read Item Items Item Id Get", "title": "Response Read Item Items Item Id Get",
"anyOf": [ "anyOf": [
{"$ref": "#/components/schemas/PlaneItem"}, {
{"$ref": "#/components/schemas/CarItem"}, "$ref": "#/components/schemas/PlaneItem"
},
{
"$ref": "#/components/schemas/CarItem"
},
], ],
} }
} }
@ -92,29 +97,29 @@ def test_openapi_schema(client: TestClient):
"schemas": { "schemas": {
"PlaneItem": { "PlaneItem": {
"title": "PlaneItem", "title": "PlaneItem",
"required": IsOneOf( "required": ["description", "size"],
["description", "type", "size"],
# TODO: remove when deprecating Pydantic v1
["description", "size"],
),
"type": "object", "type": "object",
"properties": { "properties": {
"description": {"title": "Description", "type": "string"}, "description": {"title": "Description", "type": "string"},
"type": {"title": "Type", "type": "string", "default": "plane"}, "type": {
"title": "Type",
"type": "string",
"default": "plane",
},
"size": {"title": "Size", "type": "integer"}, "size": {"title": "Size", "type": "integer"},
}, },
}, },
"CarItem": { "CarItem": {
"title": "CarItem", "title": "CarItem",
"required": IsOneOf( "required": ["description"],
["description", "type"],
# TODO: remove when deprecating Pydantic v1
["description"],
),
"type": "object", "type": "object",
"properties": { "properties": {
"description": {"title": "Description", "type": "string"}, "description": {"title": "Description", "type": "string"},
"type": {"title": "Type", "type": "string", "default": "car"}, "type": {
"title": "Type",
"type": "string",
"default": "car",
},
}, },
}, },
"ValidationError": { "ValidationError": {
@ -140,10 +145,13 @@ def test_openapi_schema(client: TestClient):
"detail": { "detail": {
"title": "Detail", "title": "Detail",
"type": "array", "type": "array",
"items": {"$ref": "#/components/schemas/ValidationError"}, "items": {
"$ref": "#/components/schemas/ValidationError"
},
} }
}, },
}, },
} }
}, },
} }
)

View File

@ -1,4 +1,3 @@
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from docs_src.handling_errors.tutorial005_py39 import app from docs_src.handling_errors.tutorial005_py39 import app
@ -9,8 +8,7 @@ client = TestClient(app)
def test_post_validation_error(): def test_post_validation_error():
response = client.post("/items/", json={"title": "towel", "size": "XL"}) response = client.post("/items/", json={"title": "towel", "size": "XL"})
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -21,19 +19,6 @@ def test_post_validation_error():
], ],
"body": {"title": "towel", "size": "XL"}, "body": {"title": "towel", "size": "XL"},
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "size"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
],
"body": {"title": "towel", "size": "XL"},
}
)
def test_post(): def test_post():

View File

@ -1,4 +1,3 @@
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from docs_src.handling_errors.tutorial006_py39 import app from docs_src.handling_errors.tutorial006_py39 import app
@ -9,8 +8,7 @@ client = TestClient(app)
def test_get_validation_error(): def test_get_validation_error():
response = client.get("/items/foo") response = client.get("/items/foo")
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "int_parsing", "type": "int_parsing",
@ -20,18 +18,6 @@ def test_get_validation_error():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["path", "item_id"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
}
)
def test_get_http_error(): def test_get_http_error():

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot from inline_snapshot import snapshot
@ -63,7 +62,6 @@ def test_header_param_model_invalid(client: TestClient):
assert response.json() == snapshot( assert response.json() == snapshot(
{ {
"detail": [ "detail": [
IsDict(
{ {
"type": "missing", "type": "missing",
"loc": ["header", "save_data"], "loc": ["header", "save_data"],
@ -77,15 +75,6 @@ def test_header_param_model_invalid(client: TestClient):
"user-agent": "testclient", "user-agent": "testclient",
}, },
} }
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "value_error.missing",
"loc": ["header", "save_data"],
"msg": "field required",
}
)
] ]
} }
) )
@ -136,37 +125,19 @@ def test_openapi_schema(client: TestClient):
"name": "if-modified-since", "name": "if-modified-since",
"in": "header", "in": "header",
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "If Modified Since", "title": "If Modified Since",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "string",
"title": "If Modified Since",
}
),
}, },
{ {
"name": "traceparent", "name": "traceparent",
"in": "header", "in": "header",
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Traceparent", "title": "Traceparent",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "string",
"title": "Traceparent",
}
),
}, },
{ {
"name": "x-tag", "name": "x-tag",

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot from inline_snapshot import snapshot
@ -64,22 +63,12 @@ def test_header_param_model_invalid(client: TestClient):
assert response.json() == snapshot( assert response.json() == snapshot(
{ {
"detail": [ "detail": [
IsDict(
{ {
"type": "missing", "type": "missing",
"loc": ["header", "save_data"], "loc": ["header", "save_data"],
"msg": "Field required", "msg": "Field required",
"input": {"x_tag": [], "host": "testserver"}, "input": {"x_tag": [], "host": "testserver"},
} }
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "value_error.missing",
"loc": ["header", "save_data"],
"msg": "field required",
}
)
] ]
} }
) )
@ -93,22 +82,12 @@ def test_header_param_model_extra(client: TestClient):
assert response.json() == snapshot( assert response.json() == snapshot(
{ {
"detail": [ "detail": [
IsDict(
{ {
"type": "extra_forbidden", "type": "extra_forbidden",
"loc": ["header", "tool"], "loc": ["header", "tool"],
"msg": "Extra inputs are not permitted", "msg": "Extra inputs are not permitted",
"input": "plumbus", "input": "plumbus",
} }
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "value_error.extra",
"loc": ["header", "tool"],
"msg": "extra fields not permitted",
}
)
] ]
} }
) )
@ -143,37 +122,19 @@ def test_openapi_schema(client: TestClient):
"name": "if-modified-since", "name": "if-modified-since",
"in": "header", "in": "header",
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "If Modified Since", "title": "If Modified Since",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "string",
"title": "If Modified Since",
}
),
}, },
{ {
"name": "traceparent", "name": "traceparent",
"in": "header", "in": "header",
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Traceparent", "title": "Traceparent",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "string",
"title": "Traceparent",
}
),
}, },
{ {
"name": "x-tag", "name": "x-tag",

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot from inline_snapshot import snapshot
@ -60,7 +59,6 @@ def test_header_param_model_no_underscore(client: TestClient):
assert response.json() == snapshot( assert response.json() == snapshot(
{ {
"detail": [ "detail": [
IsDict(
{ {
"type": "missing", "type": "missing",
"loc": ["header", "save_data"], "loc": ["header", "save_data"],
@ -78,15 +76,6 @@ def test_header_param_model_no_underscore(client: TestClient):
"x-tag": ["one", "two"], "x-tag": ["one", "two"],
}, },
} }
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "value_error.missing",
"loc": ["header", "save_data"],
"msg": "field required",
}
)
] ]
} }
) )
@ -110,7 +99,6 @@ def test_header_param_model_invalid(client: TestClient):
assert response.json() == snapshot( assert response.json() == snapshot(
{ {
"detail": [ "detail": [
IsDict(
{ {
"type": "missing", "type": "missing",
"loc": ["header", "save_data"], "loc": ["header", "save_data"],
@ -124,15 +112,6 @@ def test_header_param_model_invalid(client: TestClient):
"user-agent": "testclient", "user-agent": "testclient",
}, },
} }
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "value_error.missing",
"loc": ["header", "save_data"],
"msg": "field required",
}
)
] ]
} }
) )
@ -183,37 +162,19 @@ def test_openapi_schema(client: TestClient):
"name": "if_modified_since", "name": "if_modified_since",
"in": "header", "in": "header",
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "If Modified Since", "title": "If Modified Since",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "string",
"title": "If Modified Since",
}
),
}, },
{ {
"name": "traceparent", "name": "traceparent",
"in": "header", "in": "header",
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Traceparent", "title": "Traceparent",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "string",
"title": "Traceparent",
}
),
}, },
{ {
"name": "x_tag", "name": "x_tag",

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from ...utils import needs_py310 from ...utils import needs_py310
@ -67,16 +66,10 @@ def test_openapi_schema(client: TestClient):
"parameters": [ "parameters": [
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "User-Agent", "title": "User-Agent",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "User-Agent", "type": "string"}
),
"name": "user-agent", "name": "user-agent",
"in": "header", "in": "header",
} }

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from ...utils import needs_py310 from ...utils import needs_py310
@ -78,16 +77,10 @@ def test_openapi_schema(client: TestClient):
"parameters": [ "parameters": [
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Strange Header", "title": "Strange Header",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Strange Header", "type": "string"}
),
"name": "strange_header", "name": "strange_header",
"in": "header", "in": "header",
} }

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from ...utils import needs_py310 from ...utils import needs_py310
@ -56,23 +55,13 @@ def test_openapi_schema(client: TestClient):
"parameters": [ "parameters": [
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"title": "X-Token", "title": "X-Token",
"anyOf": [ "anyOf": [
{"type": "array", "items": {"type": "string"}}, {"type": "array", "items": {"type": "string"}},
{"type": "null"}, {"type": "null"},
], ],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "X-Token",
"type": "array",
"items": {"type": "string"},
}
),
"name": "x-token", "name": "x-token",
"in": "header", "in": "header",
} }

View File

@ -2,7 +2,6 @@ import importlib
from types import ModuleType from types import ModuleType
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from tests.utils import needs_py310 from tests.utils import needs_py310
@ -55,8 +54,7 @@ def test_openapi_schema(client: TestClient):
"parameters": [ "parameters": [
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [ "anyOf": [
{ {
"type": "string", "type": "string",
@ -67,18 +65,7 @@ def test_openapi_schema(client: TestClient):
{"type": "null"}, {"type": "null"},
], ],
"title": "Callback Url", "title": "Callback Url",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "Callback Url",
"maxLength": 2083,
"minLength": 1,
"type": "string",
"format": "uri",
}
),
"name": "callback_url", "name": "callback_url",
"in": "query", "in": "query",
} }
@ -171,16 +158,10 @@ def test_openapi_schema(client: TestClient):
"type": "object", "type": "object",
"properties": { "properties": {
"id": {"title": "Id", "type": "string"}, "id": {"title": "Id", "type": "string"},
"title": IsDict( "title": {
{
"title": "Title", "title": "Title",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Title", "type": "string"}
),
"customer": {"title": "Customer", "type": "string"}, "customer": {"title": "Customer", "type": "string"},
"total": {"title": "Total", "type": "number"}, "total": {"title": "Total", "type": "number"},
}, },

View File

@ -1,4 +1,3 @@
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from docs_src.path_params.tutorial005_py39 import app from docs_src.path_params.tutorial005_py39 import app
@ -27,8 +26,7 @@ def test_get_enums_resnet():
def test_get_enums_invalid(): def test_get_enums_invalid():
response = client.get("/models/foo") response = client.get("/models/foo")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "enum", "type": "enum",
@ -39,19 +37,6 @@ def test_get_enums_invalid():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"ctx": {"enum_values": ["alexnet", "resnet", "lenet"]},
"loc": ["path", "model_name"],
"msg": "value is not a valid enumeration member; permitted: 'alexnet', 'resnet', 'lenet'",
"type": "type_error.enum",
}
]
}
)
def test_openapi_schema(): def test_openapi_schema():
@ -106,22 +91,11 @@ def test_openapi_schema():
} }
}, },
}, },
"ModelName": IsDict( "ModelName": {
{
"title": "ModelName", "title": "ModelName",
"enum": ["alexnet", "resnet", "lenet"], "enum": ["alexnet", "resnet", "lenet"],
"type": "string", "type": "string",
} },
)
| IsDict(
{
# TODO: remove when deprecating Pydantic v1
"title": "ModelName",
"enum": ["alexnet", "resnet", "lenet"],
"type": "string",
"description": "An enumeration.",
}
),
"ValidationError": { "ValidationError": {
"title": "ValidationError", "title": "ValidationError",
"required": ["loc", "msg", "type"], "required": ["loc", "msg", "type"],

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot from inline_snapshot import snapshot
@ -65,7 +64,6 @@ def test_query_param_model_invalid(client: TestClient):
) )
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == snapshot( assert response.json() == snapshot(
IsDict(
{ {
"detail": [ "detail": [
{ {
@ -92,35 +90,6 @@ def test_query_param_model_invalid(client: TestClient):
] ]
} }
) )
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"type": "value_error.number.not_le",
"loc": ["query", "limit"],
"msg": "ensure this value is less than or equal to 100",
"ctx": {"limit_value": 100},
},
{
"type": "value_error.number.not_ge",
"loc": ["query", "offset"],
"msg": "ensure this value is greater than or equal to 0",
"ctx": {"limit_value": 0},
},
{
"type": "value_error.const",
"loc": ["query", "order_by"],
"msg": "unexpected value; permitted: 'created_at', 'updated_at'",
"ctx": {
"given": "invalid",
"permitted": ["created_at", "updated_at"],
},
},
]
}
)
)
def test_query_param_model_extra(client: TestClient): def test_query_param_model_extra(client: TestClient):

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot from inline_snapshot import snapshot
@ -65,7 +64,6 @@ def test_query_param_model_invalid(client: TestClient):
) )
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == snapshot( assert response.json() == snapshot(
IsDict(
{ {
"detail": [ "detail": [
{ {
@ -92,35 +90,6 @@ def test_query_param_model_invalid(client: TestClient):
] ]
} }
) )
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"type": "value_error.number.not_le",
"loc": ["query", "limit"],
"msg": "ensure this value is less than or equal to 100",
"ctx": {"limit_value": 100},
},
{
"type": "value_error.number.not_ge",
"loc": ["query", "offset"],
"msg": "ensure this value is greater than or equal to 0",
"ctx": {"limit_value": 0},
},
{
"type": "value_error.const",
"loc": ["query", "order_by"],
"msg": "unexpected value; permitted: 'created_at', 'updated_at'",
"ctx": {
"given": "invalid",
"permitted": ["created_at", "updated_at"],
},
},
]
}
)
)
def test_query_param_model_extra(client: TestClient): def test_query_param_model_extra(client: TestClient):
@ -138,22 +107,12 @@ def test_query_param_model_extra(client: TestClient):
assert response.json() == snapshot( assert response.json() == snapshot(
{ {
"detail": [ "detail": [
IsDict(
{ {
"type": "extra_forbidden", "type": "extra_forbidden",
"loc": ["query", "tool"], "loc": ["query", "tool"],
"msg": "Extra inputs are not permitted", "msg": "Extra inputs are not permitted",
"input": "plumbus", "input": "plumbus",
} }
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "value_error.extra",
"loc": ["query", "tool"],
"msg": "extra fields not permitted",
}
)
] ]
} }
) )

View File

@ -1,4 +1,3 @@
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from docs_src.query_params.tutorial005_py39 import app from docs_src.query_params.tutorial005_py39 import app
@ -15,8 +14,7 @@ def test_foo_needy_very():
def test_foo_no_needy(): def test_foo_no_needy():
response = client.get("/items/foo") response = client.get("/items/foo")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -26,18 +24,6 @@ def test_foo_no_needy():
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "needy"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_openapi_schema(): def test_openapi_schema():

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from ...utils import needs_py310 from ...utils import needs_py310
@ -35,8 +34,7 @@ def test_foo_needy_very(client: TestClient):
def test_foo_no_needy(client: TestClient): def test_foo_no_needy(client: TestClient):
response = client.get("/items/foo?skip=a&limit=b") response = client.get("/items/foo?skip=a&limit=b")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -58,28 +56,6 @@ def test_foo_no_needy(client: TestClient):
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["query", "needy"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["query", "skip"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
},
{
"loc": ["query", "limit"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
},
]
}
)
def test_openapi_schema(client: TestClient): def test_openapi_schema(client: TestClient):
@ -134,16 +110,10 @@ def test_openapi_schema(client: TestClient):
}, },
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [{"type": "integer"}, {"type": "null"}], "anyOf": [{"type": "integer"}, {"type": "null"}],
"title": "Limit", "title": "Limit",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Limit", "type": "integer"}
),
"name": "limit", "name": "limit",
"in": "query", "in": "query",
}, },

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi._compat import PYDANTIC_VERSION_MINOR_TUPLE from fastapi._compat import PYDANTIC_VERSION_MINOR_TUPLE
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -50,8 +49,7 @@ def test_query_params_str_validations_q_fixedquery(client: TestClient):
def test_query_params_str_validations_item_query_nonregexquery(client: TestClient): def test_query_params_str_validations_item_query_nonregexquery(client: TestClient):
response = client.get("/items/", params={"item-query": "nonregexquery"}) response = client.get("/items/", params={"item-query": "nonregexquery"})
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "string_pattern_mismatch", "type": "string_pattern_mismatch",
@ -62,19 +60,6 @@ def test_query_params_str_validations_item_query_nonregexquery(client: TestClien
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"ctx": {"pattern": "^fixedquery$"},
"loc": ["query", "item-query"],
"msg": 'string does not match regex "^fixedquery$"',
"type": "value_error.str.regex",
}
]
}
)
def test_openapi_schema(client: TestClient): def test_openapi_schema(client: TestClient):
@ -109,8 +94,7 @@ def test_openapi_schema(client: TestClient):
"description": "Query string for the items to search in the database that have a good match", "description": "Query string for the items to search in the database that have a good match",
"required": False, "required": False,
"deprecated": True, "deprecated": True,
"schema": IsDict( "schema": {
{
"anyOf": [ "anyOf": [
{ {
"type": "string", "type": "string",
@ -128,19 +112,7 @@ def test_openapi_schema(client: TestClient):
if PYDANTIC_VERSION_MINOR_TUPLE >= (2, 10) if PYDANTIC_VERSION_MINOR_TUPLE >= (2, 10)
else {} else {}
), ),
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "Query string",
"maxLength": 50,
"minLength": 3,
"pattern": "^fixedquery$",
"type": "string",
"description": "Query string for the items to search in the database that have a good match",
}
),
"name": "item-query", "name": "item-query",
"in": "query", "in": "query",
} }

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from ...utils import needs_py310 from ...utils import needs_py310
@ -69,23 +68,13 @@ def test_openapi_schema(client: TestClient):
"parameters": [ "parameters": [
{ {
"required": False, "required": False,
"schema": IsDict( "schema": {
{
"anyOf": [ "anyOf": [
{"type": "array", "items": {"type": "string"}}, {"type": "array", "items": {"type": "string"}},
{"type": "null"}, {"type": "null"},
], ],
"title": "Q", "title": "Q",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "Q",
"type": "array",
"items": {"type": "string"},
}
),
"name": "q", "name": "q",
"in": "query", "in": "query",
} }

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -22,8 +21,7 @@ def get_client(request: pytest.FixtureRequest):
def test_post_form_no_body(client: TestClient): def test_post_form_no_body(client: TestClient):
response = client.post("/files/") response = client.post("/files/")
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -33,25 +31,12 @@ def test_post_form_no_body(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "file"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_post_body_json(client: TestClient): def test_post_body_json(client: TestClient):
response = client.post("/files/", json={"file": "Foo"}) response = client.post("/files/", json={"file": "Foo"})
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -61,18 +46,6 @@ def test_post_body_json(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "file"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_post_file(tmp_path, client: TestClient): def test_post_file(tmp_path, client: TestClient):

View File

@ -2,8 +2,8 @@ import importlib
from pathlib import Path from pathlib import Path
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from ...utils import needs_py310 from ...utils import needs_py310
@ -59,7 +59,8 @@ def test_post_upload_file(tmp_path: Path, client: TestClient):
def test_openapi_schema(client: TestClient): def test_openapi_schema(client: TestClient):
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.json() == { assert response.json() == snapshot(
{
"openapi": "3.1.0", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
@ -70,22 +71,9 @@ def test_openapi_schema(client: TestClient):
"requestBody": { "requestBody": {
"content": { "content": {
"multipart/form-data": { "multipart/form-data": {
"schema": IsDict( "schema": {
{
"allOf": [
{
"$ref": "#/components/schemas/Body_create_file_files__post" "$ref": "#/components/schemas/Body_create_file_files__post"
} }
],
"title": "Body",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"$ref": "#/components/schemas/Body_create_file_files__post"
}
)
} }
} }
}, },
@ -114,22 +102,9 @@ def test_openapi_schema(client: TestClient):
"requestBody": { "requestBody": {
"content": { "content": {
"multipart/form-data": { "multipart/form-data": {
"schema": IsDict( "schema": {
{
"allOf": [
{
"$ref": "#/components/schemas/Body_create_upload_file_uploadfile__post" "$ref": "#/components/schemas/Body_create_upload_file_uploadfile__post"
} }
],
"title": "Body",
}
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"$ref": "#/components/schemas/Body_create_upload_file_uploadfile__post"
}
)
} }
} }
}, },
@ -158,38 +133,26 @@ def test_openapi_schema(client: TestClient):
"title": "Body_create_file_files__post", "title": "Body_create_file_files__post",
"type": "object", "type": "object",
"properties": { "properties": {
"file": IsDict( "file": {
{
"title": "File", "title": "File",
"anyOf": [ "anyOf": [
{"type": "string", "format": "binary"}, {"type": "string", "format": "binary"},
{"type": "null"}, {"type": "null"},
], ],
} }
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "File", "type": "string", "format": "binary"}
)
}, },
}, },
"Body_create_upload_file_uploadfile__post": { "Body_create_upload_file_uploadfile__post": {
"title": "Body_create_upload_file_uploadfile__post", "title": "Body_create_upload_file_uploadfile__post",
"type": "object", "type": "object",
"properties": { "properties": {
"file": IsDict( "file": {
{
"title": "File", "title": "File",
"anyOf": [ "anyOf": [
{"type": "string", "format": "binary"}, {"type": "string", "format": "binary"},
{"type": "null"}, {"type": "null"},
], ],
} }
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "File", "type": "string", "format": "binary"}
)
}, },
}, },
"HTTPValidationError": { "HTTPValidationError": {
@ -199,7 +162,9 @@ def test_openapi_schema(client: TestClient):
"detail": { "detail": {
"title": "Detail", "title": "Detail",
"type": "array", "type": "array",
"items": {"$ref": "#/components/schemas/ValidationError"}, "items": {
"$ref": "#/components/schemas/ValidationError"
},
} }
}, },
}, },
@ -222,3 +187,4 @@ def test_openapi_schema(client: TestClient):
} }
}, },
} }
)

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -28,8 +27,7 @@ def get_client(app: FastAPI):
def test_post_form_no_body(client: TestClient): def test_post_form_no_body(client: TestClient):
response = client.post("/files/") response = client.post("/files/")
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -39,25 +37,12 @@ def test_post_form_no_body(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "files"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_post_body_json(client: TestClient): def test_post_body_json(client: TestClient):
response = client.post("/files/", json={"file": "Foo"}) response = client.post("/files/", json={"file": "Foo"})
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -67,18 +52,6 @@ def test_post_body_json(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "files"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_post_files(tmp_path, app: FastAPI): def test_post_files(tmp_path, app: FastAPI):

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -28,8 +27,7 @@ def test_post_body_form(client: TestClient):
def test_post_body_form_no_password(client: TestClient): def test_post_body_form_no_password(client: TestClient):
response = client.post("/login/", data={"username": "Foo"}) response = client.post("/login/", data={"username": "Foo"})
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -39,25 +37,12 @@ def test_post_body_form_no_password(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "password"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_post_body_form_no_username(client: TestClient): def test_post_body_form_no_username(client: TestClient):
response = client.post("/login/", data={"password": "secret"}) response = client.post("/login/", data={"password": "secret"})
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -67,25 +52,12 @@ def test_post_body_form_no_username(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "username"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_post_body_form_no_data(client: TestClient): def test_post_body_form_no_data(client: TestClient):
response = client.post("/login/") response = client.post("/login/")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -101,30 +73,12 @@ def test_post_body_form_no_data(client: TestClient):
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "username"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "password"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_post_body_json(client: TestClient): def test_post_body_json(client: TestClient):
response = client.post("/login/", json={"username": "Foo", "password": "secret"}) response = client.post("/login/", json={"username": "Foo", "password": "secret"})
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -140,23 +94,6 @@ def test_post_body_json(client: TestClient):
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "username"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "password"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_openapi_schema(client: TestClient): def test_openapi_schema(client: TestClient):

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -28,8 +27,7 @@ def test_post_body_form(client: TestClient):
def test_post_body_form_no_password(client: TestClient): def test_post_body_form_no_password(client: TestClient):
response = client.post("/login/", data={"username": "Foo"}) response = client.post("/login/", data={"username": "Foo"})
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -39,25 +37,12 @@ def test_post_body_form_no_password(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "password"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_post_body_form_no_username(client: TestClient): def test_post_body_form_no_username(client: TestClient):
response = client.post("/login/", data={"password": "secret"}) response = client.post("/login/", data={"password": "secret"})
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -67,25 +52,12 @@ def test_post_body_form_no_username(client: TestClient):
} }
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "username"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)
def test_post_body_form_no_data(client: TestClient): def test_post_body_form_no_data(client: TestClient):
response = client.post("/login/") response = client.post("/login/")
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -101,30 +73,12 @@ def test_post_body_form_no_data(client: TestClient):
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "username"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "password"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_post_body_json(client: TestClient): def test_post_body_json(client: TestClient):
response = client.post("/login/", json={"username": "Foo", "password": "secret"}) response = client.post("/login/", json={"username": "Foo", "password": "secret"})
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -140,23 +94,6 @@ def test_post_body_json(client: TestClient):
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "username"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "password"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_openapi_schema(client: TestClient): def test_openapi_schema(client: TestClient):

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -28,8 +27,7 @@ def get_client(app: FastAPI):
def test_post_form_no_body(client: TestClient): def test_post_form_no_body(client: TestClient):
response = client.post("/files/") response = client.post("/files/")
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -51,35 +49,12 @@ def test_post_form_no_body(client: TestClient):
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "file"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "fileb"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "token"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_post_form_no_file(client: TestClient): def test_post_form_no_file(client: TestClient):
response = client.post("/files/", data={"token": "foo"}) response = client.post("/files/", data={"token": "foo"})
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -95,30 +70,12 @@ def test_post_form_no_file(client: TestClient):
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "file"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "fileb"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_post_body_json(client: TestClient): def test_post_body_json(client: TestClient):
response = client.post("/files/", json={"file": "Foo", "token": "Bar"}) response = client.post("/files/", json={"file": "Foo", "token": "Bar"})
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -140,28 +97,6 @@ def test_post_body_json(client: TestClient):
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "file"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "fileb"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "token"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_post_file_no_token(tmp_path, app: FastAPI): def test_post_file_no_token(tmp_path, app: FastAPI):
@ -172,8 +107,7 @@ def test_post_file_no_token(tmp_path, app: FastAPI):
with path.open("rb") as file: with path.open("rb") as file:
response = client.post("/files/", files={"file": file}) response = client.post("/files/", files={"file": file})
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == IsDict( assert response.json() == {
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -189,23 +123,6 @@ def test_post_file_no_token(tmp_path, app: FastAPI):
}, },
] ]
} }
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"loc": ["body", "fileb"],
"msg": "field required",
"type": "value_error.missing",
},
{
"loc": ["body", "token"],
"msg": "field required",
"type": "value_error.missing",
},
]
}
)
def test_post_files_and_token(tmp_path, app: FastAPI): def test_post_files_and_token(tmp_path, app: FastAPI):

View File

@ -1,8 +1,8 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict, IsOneOf
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from ...utils import needs_py310 from ...utils import needs_py310
@ -42,7 +42,8 @@ def test_post_user(client: TestClient):
def test_openapi_schema(client: TestClient): def test_openapi_schema(client: TestClient):
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.json() == { assert response.json() == snapshot(
{
"openapi": "3.1.0", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
@ -53,7 +54,9 @@ def test_openapi_schema(client: TestClient):
"description": "Successful Response", "description": "Successful Response",
"content": { "content": {
"application/json": { "application/json": {
"schema": {"$ref": "#/components/schemas/UserOut"} "schema": {
"$ref": "#/components/schemas/UserOut"
}
} }
}, },
}, },
@ -85,11 +88,7 @@ def test_openapi_schema(client: TestClient):
"schemas": { "schemas": {
"UserOut": { "UserOut": {
"title": "UserOut", "title": "UserOut",
"required": IsOneOf( "required": ["username", "email"],
["username", "email", "full_name"],
# TODO: remove when deprecating Pydantic v1
["username", "email"],
),
"type": "object", "type": "object",
"properties": { "properties": {
"username": {"title": "Username", "type": "string"}, "username": {"title": "Username", "type": "string"},
@ -98,16 +97,10 @@ def test_openapi_schema(client: TestClient):
"type": "string", "type": "string",
"format": "email", "format": "email",
}, },
"full_name": IsDict( "full_name": {
{
"title": "Full Name", "title": "Full Name",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Full Name", "type": "string"}
),
}, },
}, },
"UserIn": { "UserIn": {
@ -122,16 +115,10 @@ def test_openapi_schema(client: TestClient):
"type": "string", "type": "string",
"format": "email", "format": "email",
}, },
"full_name": IsDict( "full_name": {
{
"title": "Full Name", "title": "Full Name",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Full Name", "type": "string"}
),
}, },
}, },
"ValidationError": { "ValidationError": {
@ -157,10 +144,13 @@ def test_openapi_schema(client: TestClient):
"detail": { "detail": {
"title": "Detail", "title": "Detail",
"type": "array", "type": "array",
"items": {"$ref": "#/components/schemas/ValidationError"}, "items": {
"$ref": "#/components/schemas/ValidationError"
},
} }
}, },
}, },
} }
}, },
} }
)

View File

@ -1,8 +1,8 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict, IsOneOf
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from ...utils import needs_py310 from ...utils import needs_py310
@ -42,7 +42,8 @@ def test_post_user(client: TestClient):
def test_openapi_schema(client: TestClient): def test_openapi_schema(client: TestClient):
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.json() == { assert response.json() == snapshot(
{
"openapi": "3.1.0", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
@ -63,7 +64,9 @@ def test_openapi_schema(client: TestClient):
"description": "Successful Response", "description": "Successful Response",
"content": { "content": {
"application/json": { "application/json": {
"schema": {"$ref": "#/components/schemas/BaseUser"} "schema": {
"$ref": "#/components/schemas/BaseUser"
}
} }
}, },
}, },
@ -85,11 +88,7 @@ def test_openapi_schema(client: TestClient):
"schemas": { "schemas": {
"BaseUser": { "BaseUser": {
"title": "BaseUser", "title": "BaseUser",
"required": IsOneOf( "required": ["username", "email"],
["username", "email", "full_name"],
# TODO: remove when deprecating Pydantic v1
["username", "email"],
),
"type": "object", "type": "object",
"properties": { "properties": {
"username": {"title": "Username", "type": "string"}, "username": {"title": "Username", "type": "string"},
@ -98,16 +97,10 @@ def test_openapi_schema(client: TestClient):
"type": "string", "type": "string",
"format": "email", "format": "email",
}, },
"full_name": IsDict( "full_name": {
{
"title": "Full Name", "title": "Full Name",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Full Name", "type": "string"}
),
}, },
}, },
"HTTPValidationError": { "HTTPValidationError": {
@ -117,7 +110,9 @@ def test_openapi_schema(client: TestClient):
"detail": { "detail": {
"title": "Detail", "title": "Detail",
"type": "array", "type": "array",
"items": {"$ref": "#/components/schemas/ValidationError"}, "items": {
"$ref": "#/components/schemas/ValidationError"
},
} }
}, },
}, },
@ -132,16 +127,10 @@ def test_openapi_schema(client: TestClient):
"type": "string", "type": "string",
"format": "email", "format": "email",
}, },
"full_name": IsDict( "full_name": {
{
"title": "Full Name", "title": "Full Name",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Full Name", "type": "string"}
),
"password": {"title": "Password", "type": "string"}, "password": {"title": "Password", "type": "string"},
}, },
}, },
@ -164,3 +153,4 @@ def test_openapi_schema(client: TestClient):
} }
}, },
} }
)

View File

@ -1,8 +1,8 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict, IsOneOf
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from ...utils import needs_py310 from ...utils import needs_py310
@ -50,7 +50,8 @@ def test_get(url, data, client: TestClient):
def test_openapi_schema(client: TestClient): def test_openapi_schema(client: TestClient):
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.json() == { assert response.json() == snapshot(
{
"openapi": "3.1.0", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
@ -93,25 +94,15 @@ def test_openapi_schema(client: TestClient):
"schemas": { "schemas": {
"Item": { "Item": {
"title": "Item", "title": "Item",
"required": IsOneOf( "required": ["name", "price"],
["name", "description", "price", "tax", "tags"],
# TODO: remove when deprecating Pydantic v1
["name", "price"],
),
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"price": {"title": "Price", "type": "number"}, "price": {"title": "Price", "type": "number"},
"description": IsDict( "description": {
{
"title": "Description", "title": "Description",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Description", "type": "string"}
),
"tax": {"title": "Tax", "type": "number", "default": 10.5}, "tax": {"title": "Tax", "type": "number", "default": 10.5},
"tags": { "tags": {
"title": "Tags", "title": "Tags",
@ -144,10 +135,13 @@ def test_openapi_schema(client: TestClient):
"detail": { "detail": {
"title": "Detail", "title": "Detail",
"type": "array", "type": "array",
"items": {"$ref": "#/components/schemas/ValidationError"}, "items": {
"$ref": "#/components/schemas/ValidationError"
},
} }
}, },
}, },
} }
}, },
} }
)

View File

@ -1,8 +1,8 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict, IsOneOf
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from ...utils import needs_py310 from ...utils import needs_py310
@ -40,7 +40,8 @@ def test_read_item_public_data(client: TestClient):
def test_openapi_schema(client: TestClient): def test_openapi_schema(client: TestClient):
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.json() == { assert response.json() == snapshot(
{
"openapi": "3.1.0", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
@ -117,25 +118,15 @@ def test_openapi_schema(client: TestClient):
"schemas": { "schemas": {
"Item": { "Item": {
"title": "Item", "title": "Item",
"required": IsOneOf( "required": ["name", "price"],
["name", "description", "price", "tax"],
# TODO: remove when deprecating Pydantic v1
["name", "price"],
),
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"price": {"title": "Price", "type": "number"}, "price": {"title": "Price", "type": "number"},
"description": IsDict( "description": {
{
"title": "Description", "title": "Description",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Description", "type": "string"}
),
"tax": {"title": "Tax", "type": "number", "default": 10.5}, "tax": {"title": "Tax", "type": "number", "default": 10.5},
}, },
}, },
@ -162,10 +153,13 @@ def test_openapi_schema(client: TestClient):
"detail": { "detail": {
"title": "Detail", "title": "Detail",
"type": "array", "type": "array",
"items": {"$ref": "#/components/schemas/ValidationError"}, "items": {
"$ref": "#/components/schemas/ValidationError"
},
} }
}, },
}, },
} }
}, },
} }
)

View File

@ -1,8 +1,8 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict, IsOneOf
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from ...utils import needs_py310 from ...utils import needs_py310
@ -40,7 +40,8 @@ def test_read_item_public_data(client: TestClient):
def test_openapi_schema(client: TestClient): def test_openapi_schema(client: TestClient):
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.json() == { assert response.json() == snapshot(
{
"openapi": "3.1.0", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
@ -117,25 +118,15 @@ def test_openapi_schema(client: TestClient):
"schemas": { "schemas": {
"Item": { "Item": {
"title": "Item", "title": "Item",
"required": IsOneOf( "required": ["name", "price"],
["name", "description", "price", "tax"],
# TODO: remove when deprecating Pydantic v1
["name", "price"],
),
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"price": {"title": "Price", "type": "number"}, "price": {"title": "Price", "type": "number"},
"description": IsDict( "description": {
{
"title": "Description", "title": "Description",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Description", "type": "string"}
),
"tax": {"title": "Tax", "type": "number", "default": 10.5}, "tax": {"title": "Tax", "type": "number", "default": 10.5},
}, },
}, },
@ -162,10 +153,13 @@ def test_openapi_schema(client: TestClient):
"detail": { "detail": {
"title": "Detail", "title": "Detail",
"type": "array", "type": "array",
"items": {"$ref": "#/components/schemas/ValidationError"}, "items": {
"$ref": "#/components/schemas/ValidationError"
},
} }
}, },
}, },
} }
}, },
} }
)

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from ...utils import needs_py310 from ...utils import needs_py310
@ -58,8 +57,7 @@ def test_openapi_schema(client: TestClient):
"requestBody": { "requestBody": {
"content": { "content": {
"application/json": { "application/json": {
"schema": IsDict( "schema": {
{
"$ref": "#/components/schemas/Item", "$ref": "#/components/schemas/Item",
"examples": [ "examples": [
{ {
@ -75,29 +73,6 @@ def test_openapi_schema(client: TestClient):
}, },
], ],
} }
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"allOf": [
{"$ref": "#/components/schemas/Item"}
],
"title": "Item",
"examples": [
{
"name": "Foo",
"description": "A very nice Item",
"price": 35.4,
"tax": 3.2,
},
{"name": "Bar", "price": "35.4"},
{
"name": "Baz",
"price": "thirty five point four",
},
],
}
)
} }
}, },
"required": True, "required": True,
@ -140,27 +115,15 @@ def test_openapi_schema(client: TestClient):
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"description": IsDict( "description": {
{
"title": "Description", "title": "Description",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Description", "type": "string"}
),
"price": {"title": "Price", "type": "number"}, "price": {"title": "Price", "type": "number"},
"tax": IsDict( "tax": {
{
"title": "Tax", "title": "Tax",
"anyOf": [{"type": "number"}, {"type": "null"}], "anyOf": [{"type": "number"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Tax", "type": "number"}
),
}, },
}, },
"ValidationError": { "ValidationError": {

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from ...utils import needs_py310 from ...utils import needs_py310
@ -58,16 +57,7 @@ def test_openapi_schema(client: TestClient) -> None:
"requestBody": { "requestBody": {
"content": { "content": {
"application/json": { "application/json": {
"schema": IsDict({"$ref": "#/components/schemas/Item"}) "schema": {"$ref": "#/components/schemas/Item"},
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"allOf": [
{"$ref": "#/components/schemas/Item"}
],
"title": "Item",
}
),
"examples": { "examples": {
"normal": { "normal": {
"summary": "A normal example", "summary": "A normal example",
@ -134,27 +124,15 @@ def test_openapi_schema(client: TestClient) -> None:
"type": "object", "type": "object",
"properties": { "properties": {
"name": {"title": "Name", "type": "string"}, "name": {"title": "Name", "type": "string"},
"description": IsDict( "description": {
{
"title": "Description", "title": "Description",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Description", "type": "string"}
),
"price": {"title": "Price", "type": "number"}, "price": {"title": "Price", "type": "number"},
"tax": IsDict( "tax": {
{
"title": "Tax", "title": "Tax",
"anyOf": [{"type": "number"}, {"type": "null"}], "anyOf": [{"type": "number"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Tax", "type": "number"}
),
}, },
}, },
"ValidationError": { "ValidationError": {

View File

@ -1,7 +1,6 @@
import importlib import importlib
import pytest import pytest
from dirty_equals import IsDict
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from ...utils import needs_py310 from ...utils import needs_py310
@ -144,23 +143,13 @@ def test_openapi_schema(client: TestClient):
"required": ["username", "password"], "required": ["username", "password"],
"type": "object", "type": "object",
"properties": { "properties": {
"grant_type": IsDict( "grant_type": {
{
"title": "Grant Type", "title": "Grant Type",
"anyOf": [ "anyOf": [
{"pattern": "^password$", "type": "string"}, {"pattern": "^password$", "type": "string"},
{"type": "null"}, {"type": "null"},
], ],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "Grant Type",
"pattern": "^password$",
"type": "string",
}
),
"username": {"title": "Username", "type": "string"}, "username": {"title": "Username", "type": "string"},
"password": { "password": {
"title": "Password", "title": "Password",
@ -168,31 +157,15 @@ def test_openapi_schema(client: TestClient):
"format": "password", "format": "password",
}, },
"scope": {"title": "Scope", "type": "string", "default": ""}, "scope": {"title": "Scope", "type": "string", "default": ""},
"client_id": IsDict( "client_id": {
{
"title": "Client Id", "title": "Client Id",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
) "client_secret": {
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Client Id", "type": "string"}
),
"client_secret": IsDict(
{
"title": "Client Secret", "title": "Client Secret",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"format": "password", "format": "password",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "Client Secret",
"type": "string",
"format": "password",
}
),
}, },
}, },
"ValidationError": { "ValidationError": {

View File

@ -2,8 +2,8 @@ import importlib
from types import ModuleType from types import ModuleType
import pytest import pytest
from dirty_equals import IsDict, IsOneOf
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from ...utils import needs_py310 from ...utils import needs_py310
@ -215,7 +215,8 @@ def test_openapi_schema(mod: ModuleType):
client = TestClient(mod.app) client = TestClient(mod.app)
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.json() == { assert response.json() == snapshot(
{
"openapi": "3.1.0", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {
@ -303,44 +304,22 @@ def test_openapi_schema(mod: ModuleType):
"schemas": { "schemas": {
"User": { "User": {
"title": "User", "title": "User",
"required": IsOneOf( "required": ["username"],
["username", "email", "full_name", "disabled"],
# TODO: remove when deprecating Pydantic v1
["username"],
),
"type": "object", "type": "object",
"properties": { "properties": {
"username": {"title": "Username", "type": "string"}, "username": {"title": "Username", "type": "string"},
"email": IsDict( "email": {
{
"title": "Email", "title": "Email",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
) "full_name": {
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Email", "type": "string"}
),
"full_name": IsDict(
{
"title": "Full Name", "title": "Full Name",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
) "disabled": {
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Full Name", "type": "string"}
),
"disabled": IsDict(
{
"title": "Disabled", "title": "Disabled",
"anyOf": [{"type": "boolean"}, {"type": "null"}], "anyOf": [{"type": "boolean"}, {"type": "null"}],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Disabled", "type": "boolean"}
),
}, },
}, },
"Token": { "Token": {
@ -357,55 +336,33 @@ def test_openapi_schema(mod: ModuleType):
"required": ["username", "password"], "required": ["username", "password"],
"type": "object", "type": "object",
"properties": { "properties": {
"grant_type": IsDict( "grant_type": {
{
"title": "Grant Type", "title": "Grant Type",
"anyOf": [ "anyOf": [
{"pattern": "^password$", "type": "string"}, {"pattern": "^password$", "type": "string"},
{"type": "null"}, {"type": "null"},
], ],
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "Grant Type",
"pattern": "^password$",
"type": "string",
}
),
"username": {"title": "Username", "type": "string"}, "username": {"title": "Username", "type": "string"},
"password": { "password": {
"title": "Password", "title": "Password",
"type": "string", "type": "string",
"format": "password", "format": "password",
}, },
"scope": {"title": "Scope", "type": "string", "default": ""}, "scope": {
"client_id": IsDict( "title": "Scope",
{ "type": "string",
"default": "",
},
"client_id": {
"title": "Client Id", "title": "Client Id",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
} },
) "client_secret": {
| IsDict(
# TODO: remove when deprecating Pydantic v1
{"title": "Client Id", "type": "string"}
),
"client_secret": IsDict(
{
"title": "Client Secret", "title": "Client Secret",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"format": "password", "format": "password",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"title": "Client Secret",
"type": "string",
"format": "password",
}
),
}, },
}, },
"ValidationError": { "ValidationError": {
@ -431,7 +388,9 @@ def test_openapi_schema(mod: ModuleType):
"detail": { "detail": {
"title": "Detail", "title": "Detail",
"type": "array", "type": "array",
"items": {"$ref": "#/components/schemas/ValidationError"}, "items": {
"$ref": "#/components/schemas/ValidationError"
},
} }
}, },
}, },
@ -452,3 +411,4 @@ def test_openapi_schema(mod: ModuleType):
}, },
}, },
} }
)

View File

@ -2,7 +2,7 @@ import importlib
import warnings import warnings
import pytest import pytest
from dirty_equals import IsDict, IsInt from dirty_equals import IsInt
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot from inline_snapshot import snapshot
from sqlalchemy import StaticPool from sqlalchemy import StaticPool
@ -318,33 +318,15 @@ def test_openapi_schema(client: TestClient):
}, },
"Hero": { "Hero": {
"properties": { "properties": {
"id": IsDict( "id": {
{
"anyOf": [{"type": "integer"}, {"type": "null"}], "anyOf": [{"type": "integer"}, {"type": "null"}],
"title": "Id", "title": "Id",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "integer",
"title": "Id",
}
),
"name": {"type": "string", "title": "Name"}, "name": {"type": "string", "title": "Name"},
"age": IsDict( "age": {
{
"anyOf": [{"type": "integer"}, {"type": "null"}], "anyOf": [{"type": "integer"}, {"type": "null"}],
"title": "Age", "title": "Age",
} },
)
| IsDict(
# TODO: remove when deprecating Pydantic v1
{
"type": "integer",
"title": "Age",
}
),
"secret_name": {"type": "string", "title": "Secret Name"}, "secret_name": {"type": "string", "title": "Secret Name"},
}, },
"type": "object", "type": "object",

Some files were not shown because too many files have changed in this diff Show More