mirror of
https://github.com/fastapi/fastapi.git
synced 2026-08-07 04:23:32 -04:00
🔥 Remove test variants for Pydantic v1 in test_request_params (#14612)
This commit is contained in:
1 parent
ded035a421
commit
1b42639296
5 files changed
+64
-177
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
from typing import Annotated, Union
|
from typing import Annotated, Union
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import IsDict, IsOneOf, IsPartialDict
|
from dirty_equals import IsOneOf, IsPartialDict
|
||||||
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
|
||||||
@@ -59,28 +59,16 @@ def test_required_list_str_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",
|
"loc": IsOneOf(["body", "p"], ["body"]),
|
||||||
"loc": IsOneOf(["body", "p"], ["body"]),
|
"msg": "Field required",
|
||||||
"msg": "Field required",
|
"input": IsOneOf(None, {}),
|
||||||
"input": IsOneOf(None, {}),
|
}
|
||||||
}
|
]
|
||||||
]
|
}
|
||||||
}
|
|
||||||
) | IsDict(
|
|
||||||
{
|
|
||||||
"detail": [
|
|
||||||
{
|
|
||||||
"loc": IsOneOf(["body", "p"], ["body"]),
|
|
||||||
"msg": "field required",
|
|
||||||
"type": "value_error.missing",
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
@@ -36,27 +35,11 @@ def test_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(
|
"type": "array",
|
||||||
{
|
"items": {"type": "string", "format": "binary"},
|
||||||
"anyOf": [
|
"title": "P",
|
||||||
{
|
},
|
||||||
"type": "array",
|
|
||||||
"items": {"type": "string", "format": "binary"},
|
|
||||||
},
|
|
||||||
{"type": "null"},
|
|
||||||
],
|
|
||||||
"title": "P",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
| IsDict(
|
|
||||||
{
|
|
||||||
"type": "array",
|
|
||||||
"items": {"type": "string", "format": "binary"},
|
|
||||||
"title": "P",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
"required": ["p"],
|
"required": ["p"],
|
||||||
"title": body_model_name,
|
"title": body_model_name,
|
||||||
@@ -130,27 +113,11 @@ def test_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(
|
"type": "array",
|
||||||
{
|
"items": {"type": "string", "format": "binary"},
|
||||||
"anyOf": [
|
"title": "P Alias",
|
||||||
{
|
},
|
||||||
"type": "array",
|
|
||||||
"items": {"type": "string", "format": "binary"},
|
|
||||||
},
|
|
||||||
{"type": "null"},
|
|
||||||
],
|
|
||||||
"title": "P Alias",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
| IsDict(
|
|
||||||
{
|
|
||||||
"type": "array",
|
|
||||||
"items": {"type": "string", "format": "binary"},
|
|
||||||
"title": "P Alias",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
"required": ["p_alias"],
|
"required": ["p_alias"],
|
||||||
"title": body_model_name,
|
"title": body_model_name,
|
||||||
@@ -252,27 +219,11 @@ def test_list_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(
|
"type": "array",
|
||||||
{
|
"items": {"type": "string", "format": "binary"},
|
||||||
"anyOf": [
|
"title": "P Val Alias",
|
||||||
{
|
},
|
||||||
"type": "array",
|
|
||||||
"items": {"type": "string", "format": "binary"},
|
|
||||||
},
|
|
||||||
{"type": "null"},
|
|
||||||
],
|
|
||||||
"title": "P Val Alias",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
| IsDict(
|
|
||||||
{
|
|
||||||
"type": "array",
|
|
||||||
"items": {"type": "string", "format": "binary"},
|
|
||||||
"title": "P Val Alias",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
"required": ["p_val_alias"],
|
"required": ["p_val_alias"],
|
||||||
"title": body_model_name,
|
"title": body_model_name,
|
||||||
@@ -385,27 +336,11 @@ def test_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(
|
"type": "array",
|
||||||
{
|
"items": {"type": "string", "format": "binary"},
|
||||||
"anyOf": [
|
"title": "P Val Alias",
|
||||||
{
|
},
|
||||||
"type": "array",
|
|
||||||
"items": {"type": "string", "format": "binary"},
|
|
||||||
},
|
|
||||||
{"type": "null"},
|
|
||||||
],
|
|
||||||
"title": "P Val Alias",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
| IsDict(
|
|
||||||
{
|
|
||||||
"type": "array",
|
|
||||||
"items": {"type": "string", "format": "binary"},
|
|
||||||
"title": "P Val Alias",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
"required": ["p_val_alias"],
|
"required": ["p_val_alias"],
|
||||||
"title": body_model_name,
|
"title": body_model_name,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from typing import Annotated
|
from typing import Annotated
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import IsDict, IsOneOf, IsPartialDict
|
from dirty_equals import IsOneOf, IsPartialDict
|
||||||
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
|
||||||
@@ -58,28 +58,16 @@ def test_required_list_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",
|
"loc": ["body", "p"],
|
||||||
"loc": ["body", "p"],
|
"msg": "Field required",
|
||||||
"msg": "Field required",
|
"input": IsOneOf(None, {}),
|
||||||
"input": IsOneOf(None, {}),
|
}
|
||||||
}
|
]
|
||||||
]
|
}
|
||||||
}
|
|
||||||
) | IsDict(
|
|
||||||
{
|
|
||||||
"detail": [
|
|
||||||
{
|
|
||||||
"loc": ["body", "p"],
|
|
||||||
"msg": "field required",
|
|
||||||
"type": "value_error.missing",
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -53,28 +53,16 @@ def test_required_list_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",
|
"loc": ["header", "p"],
|
||||||
"loc": ["header", "p"],
|
"msg": "Field required",
|
||||||
"msg": "Field required",
|
"input": AnyThing,
|
||||||
"input": AnyThing,
|
}
|
||||||
}
|
]
|
||||||
]
|
}
|
||||||
}
|
|
||||||
) | IsDict(
|
|
||||||
{
|
|
||||||
"detail": [
|
|
||||||
{
|
|
||||||
"loc": ["header", "p"],
|
|
||||||
"msg": "field required",
|
|
||||||
"type": "value_error.missing",
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -53,28 +53,16 @@ def test_required_list_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",
|
"loc": ["query", "p"],
|
||||||
"loc": ["query", "p"],
|
"msg": "Field required",
|
||||||
"msg": "Field required",
|
"input": IsOneOf(None, {}),
|
||||||
"input": IsOneOf(None, {}),
|
}
|
||||||
}
|
]
|
||||||
]
|
}
|
||||||
}
|
|
||||||
) | IsDict(
|
|
||||||
{
|
|
||||||
"detail": [
|
|
||||||
{
|
|
||||||
"loc": ["query", "p"],
|
|
||||||
"msg": "field required",
|
|
||||||
"type": "value_error.missing",
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|||||||
Reference in new issue
Block a user