]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
🔥 Remove test variants for Pydantic v1 in test_request_params (#14612)
authorSebastián Ramírez <tiangolo@gmail.com>
Sat, 27 Dec 2025 18:31:34 +0000 (10:31 -0800)
committerGitHub <noreply@github.com>
Sat, 27 Dec 2025 18:31:34 +0000 (19:31 +0100)
tests/test_request_params/test_body/test_list.py
tests/test_request_params/test_file/test_list.py
tests/test_request_params/test_form/test_list.py
tests/test_request_params/test_header/test_list.py
tests/test_request_params/test_query/test_list.py

index 50847335ce7b94b83793c6e8221dc8eb37e8ce97..970e6a6607e99c54033def7ac528feefb4b5a876 100644 (file)
@@ -1,7 +1,7 @@
 from typing import Annotated, Union
 
 import pytest
-from dirty_equals import IsDict, IsOneOf, IsPartialDict
+from dirty_equals import IsOneOf, IsPartialDict
 from fastapi import Body, FastAPI
 from fastapi.testclient import TestClient
 from pydantic import BaseModel, Field
@@ -59,28 +59,16 @@ def test_required_list_str_missing(path: str, json: Union[dict, None]):
     client = TestClient(app)
     response = client.post(path, json=json)
     assert response.status_code == 422
-    assert response.json() == IsDict(
-        {
-            "detail": [
-                {
-                    "type": "missing",
-                    "loc": IsOneOf(["body", "p"], ["body"]),
-                    "msg": "Field required",
-                    "input": IsOneOf(None, {}),
-                }
-            ]
-        }
-    ) | IsDict(
-        {
-            "detail": [
-                {
-                    "loc": IsOneOf(["body", "p"], ["body"]),
-                    "msg": "field required",
-                    "type": "value_error.missing",
-                }
-            ]
-        }
-    )
+    assert response.json() == {
+        "detail": [
+            {
+                "type": "missing",
+                "loc": IsOneOf(["body", "p"], ["body"]),
+                "msg": "Field required",
+                "input": IsOneOf(None, {}),
+            }
+        ]
+    }
 
 
 @pytest.mark.parametrize(
index f096532554f7d2de9ddf68949794dec489b62abe..68280fcf32a87609b60d6ba535877fac5e7d0d75 100644 (file)
@@ -1,7 +1,6 @@
 from typing import Annotated
 
 import pytest
-from dirty_equals import IsDict
 from fastapi import FastAPI, File, UploadFile
 from fastapi.testclient import TestClient
 
@@ -36,27 +35,11 @@ def test_list_schema(path: str):
 
     assert app.openapi()["components"]["schemas"][body_model_name] == {
         "properties": {
-            "p": (
-                IsDict(
-                    {
-                        "anyOf": [
-                            {
-                                "type": "array",
-                                "items": {"type": "string", "format": "binary"},
-                            },
-                            {"type": "null"},
-                        ],
-                        "title": "P",
-                    },
-                )
-                | IsDict(
-                    {
-                        "type": "array",
-                        "items": {"type": "string", "format": "binary"},
-                        "title": "P",
-                    },
-                )
-            )
+            "p": {
+                "type": "array",
+                "items": {"type": "string", "format": "binary"},
+                "title": "P",
+            },
         },
         "required": ["p"],
         "title": body_model_name,
@@ -130,27 +113,11 @@ def test_list_alias_schema(path: str):
 
     assert app.openapi()["components"]["schemas"][body_model_name] == {
         "properties": {
-            "p_alias": (
-                IsDict(
-                    {
-                        "anyOf": [
-                            {
-                                "type": "array",
-                                "items": {"type": "string", "format": "binary"},
-                            },
-                            {"type": "null"},
-                        ],
-                        "title": "P Alias",
-                    },
-                )
-                | IsDict(
-                    {
-                        "type": "array",
-                        "items": {"type": "string", "format": "binary"},
-                        "title": "P Alias",
-                    },
-                )
-            )
+            "p_alias": {
+                "type": "array",
+                "items": {"type": "string", "format": "binary"},
+                "title": "P Alias",
+            },
         },
         "required": ["p_alias"],
         "title": body_model_name,
@@ -252,27 +219,11 @@ def test_list_validation_alias_schema(path: str):
 
     assert app.openapi()["components"]["schemas"][body_model_name] == {
         "properties": {
-            "p_val_alias": (
-                IsDict(
-                    {
-                        "anyOf": [
-                            {
-                                "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",
-                    },
-                )
-            )
+            "p_val_alias": {
+                "type": "array",
+                "items": {"type": "string", "format": "binary"},
+                "title": "P Val Alias",
+            },
         },
         "required": ["p_val_alias"],
         "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] == {
         "properties": {
-            "p_val_alias": (
-                IsDict(
-                    {
-                        "anyOf": [
-                            {
-                                "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",
-                    },
-                )
-            )
+            "p_val_alias": {
+                "type": "array",
+                "items": {"type": "string", "format": "binary"},
+                "title": "P Val Alias",
+            },
         },
         "required": ["p_val_alias"],
         "title": body_model_name,
index cfc42f523af465d8e065c094b9c65d84191e9978..abe781c9451a169d88f2fa124f1502f7277f1640 100644 (file)
@@ -1,7 +1,7 @@
 from typing import Annotated
 
 import pytest
-from dirty_equals import IsDict, IsOneOf, IsPartialDict
+from dirty_equals import IsOneOf, IsPartialDict
 from fastapi import FastAPI, Form
 from fastapi.testclient import TestClient
 from pydantic import BaseModel, Field
@@ -58,28 +58,16 @@ def test_required_list_str_missing(path: str):
     client = TestClient(app)
     response = client.post(path)
     assert response.status_code == 422
-    assert response.json() == IsDict(
-        {
-            "detail": [
-                {
-                    "type": "missing",
-                    "loc": ["body", "p"],
-                    "msg": "Field required",
-                    "input": IsOneOf(None, {}),
-                }
-            ]
-        }
-    ) | IsDict(
-        {
-            "detail": [
-                {
-                    "loc": ["body", "p"],
-                    "msg": "field required",
-                    "type": "value_error.missing",
-                }
-            ]
-        }
-    )
+    assert response.json() == {
+        "detail": [
+            {
+                "type": "missing",
+                "loc": ["body", "p"],
+                "msg": "Field required",
+                "input": IsOneOf(None, {}),
+            }
+        ]
+    }
 
 
 @pytest.mark.parametrize(
index 65510094af597d64952eb3181927f3fc4b212684..489a6b3e7d70ab11083a9a6cab309d2bd6e71261 100644 (file)
@@ -1,7 +1,7 @@
 from typing import Annotated
 
 import pytest
-from dirty_equals import AnyThing, IsDict, IsOneOf, IsPartialDict
+from dirty_equals import AnyThing, IsOneOf, IsPartialDict
 from fastapi import FastAPI, Header
 from fastapi.testclient import TestClient
 from pydantic import BaseModel, Field
@@ -53,28 +53,16 @@ def test_required_list_str_missing(path: str):
     client = TestClient(app)
     response = client.get(path)
     assert response.status_code == 422
-    assert response.json() == IsDict(
-        {
-            "detail": [
-                {
-                    "type": "missing",
-                    "loc": ["header", "p"],
-                    "msg": "Field required",
-                    "input": AnyThing,
-                }
-            ]
-        }
-    ) | IsDict(
-        {
-            "detail": [
-                {
-                    "loc": ["header", "p"],
-                    "msg": "field required",
-                    "type": "value_error.missing",
-                }
-            ]
-        }
-    )
+    assert response.json() == {
+        "detail": [
+            {
+                "type": "missing",
+                "loc": ["header", "p"],
+                "msg": "Field required",
+                "input": AnyThing,
+            }
+        ]
+    }
 
 
 @pytest.mark.parametrize(
index ed2ea6c809f0c8b89139faea5a46874b303b350c..e933da214d1980c054777ea7eaa5c3c46858480d 100644 (file)
@@ -1,7 +1,7 @@
 from typing import Annotated
 
 import pytest
-from dirty_equals import IsDict, IsOneOf
+from dirty_equals import IsOneOf
 from fastapi import FastAPI, Query
 from fastapi.testclient import TestClient
 from pydantic import BaseModel, Field
@@ -53,28 +53,16 @@ def test_required_list_str_missing(path: str):
     client = TestClient(app)
     response = client.get(path)
     assert response.status_code == 422
-    assert response.json() == IsDict(
-        {
-            "detail": [
-                {
-                    "type": "missing",
-                    "loc": ["query", "p"],
-                    "msg": "Field required",
-                    "input": IsOneOf(None, {}),
-                }
-            ]
-        }
-    ) | IsDict(
-        {
-            "detail": [
-                {
-                    "loc": ["query", "p"],
-                    "msg": "field required",
-                    "type": "value_error.missing",
-                }
-            ]
-        }
-    )
+    assert response.json() == {
+        "detail": [
+            {
+                "type": "missing",
+                "loc": ["query", "p"],
+                "msg": "Field required",
+                "input": IsOneOf(None, {}),
+            }
+        ]
+    }
 
 
 @pytest.mark.parametrize(