]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
✅ Fix tests for compatibility with pydantic 2.1.1 (#9943)
authorDavid Montague <35119617+dmontagu@users.noreply.github.com>
Thu, 3 Aug 2023 15:46:57 +0000 (16:46 +0100)
committerGitHub <noreply@github.com>
Thu, 3 Aug 2023 15:46:57 +0000 (17:46 +0200)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
.github/workflows/test.yml
tests/test_filter_pydantic_sub_model_pv2.py
tests/test_multi_body_errors.py

index b95358d0136d4d628be502302a703792745ed046..fbaf759c3238ab480c44bcabe3e5484006761d52 100644 (file)
@@ -25,7 +25,7 @@ jobs:
         id: cache
         with:
           path: ${{ env.pythonLocation }}
-          key: ${{ runner.os }}-python-${{ env.pythonLocation }}-pydantic-v2-${{ hashFiles('pyproject.toml', 'requirements-tests.txt') }}-test-v03
+          key: ${{ runner.os }}-python-${{ env.pythonLocation }}-pydantic-v2-${{ hashFiles('pyproject.toml', 'requirements-tests.txt') }}-test-v04
       - name: Install Dependencies
         if: steps.cache.outputs.cache-hit != 'true'
         run: pip install -r requirements-tests.txt
@@ -54,7 +54,7 @@ jobs:
         id: cache
         with:
           path: ${{ env.pythonLocation }}
-          key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ matrix.pydantic-version }}-${{ hashFiles('pyproject.toml', 'requirements-tests.txt') }}-test-v03
+          key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ matrix.pydantic-version }}-${{ hashFiles('pyproject.toml', 'requirements-tests.txt') }}-test-v04
       - name: Install Dependencies
         if: steps.cache.outputs.cache-hit != 'true'
         run: pip install -r requirements-tests.txt
index 656332a010249091df3633db7d826282f1f9cfe4..ae12179bdf3149a137bdde2910cedba24547bcb0 100644 (file)
@@ -1,7 +1,7 @@
 from typing import Optional
 
 import pytest
-from dirty_equals import IsDict
+from dirty_equals import HasRepr, IsDict
 from fastapi import Depends, FastAPI
 from fastapi.exceptions import ResponseValidationError
 from fastapi.testclient import TestClient
@@ -66,7 +66,7 @@ def test_validator_is_cloned(client: TestClient):
                 "loc": ("response", "name"),
                 "msg": "Value error, name must end in A",
                 "input": "modelX",
-                "ctx": {"error": "name must end in A"},
+                "ctx": {"error": HasRepr("ValueError('name must end in A')")},
                 "url": match_pydantic_error_url("value_error"),
             }
         )
index aa989c612874f404e189d3e169ab0e975a4f879b..931f08fc1cf5c6725239d7bd393fecd8556da391 100644 (file)
@@ -51,7 +51,7 @@ def test_jsonable_encoder_requiring_error():
                     "loc": ["body", 0, "age"],
                     "msg": "Input should be greater than 0",
                     "input": -1.0,
-                    "ctx": {"gt": 0.0},
+                    "ctx": {"gt": "0"},
                     "url": match_pydantic_error_url("greater_than"),
                 }
             ]
@@ -84,9 +84,23 @@ def test_put_incorrect_body_multiple():
                     "input": {"age": "five"},
                     "url": match_pydantic_error_url("missing"),
                 },
+                {
+                    "ctx": {"class": "Decimal"},
+                    "input": "five",
+                    "loc": ["body", 0, "age", "is-instance[Decimal]"],
+                    "msg": "Input should be an instance of Decimal",
+                    "type": "is_instance_of",
+                    "url": match_pydantic_error_url("is_instance_of"),
+                },
                 {
                     "type": "decimal_parsing",
-                    "loc": ["body", 0, "age"],
+                    "loc": [
+                        "body",
+                        0,
+                        "age",
+                        "function-after[to_decimal(), "
+                        "union[int,constrained-str,function-plain[str()]]]",
+                    ],
                     "msg": "Input should be a valid decimal",
                     "input": "five",
                 },
@@ -97,9 +111,23 @@ def test_put_incorrect_body_multiple():
                     "input": {"age": "six"},
                     "url": match_pydantic_error_url("missing"),
                 },
+                {
+                    "ctx": {"class": "Decimal"},
+                    "input": "six",
+                    "loc": ["body", 1, "age", "is-instance[Decimal]"],
+                    "msg": "Input should be an instance of Decimal",
+                    "type": "is_instance_of",
+                    "url": match_pydantic_error_url("is_instance_of"),
+                },
                 {
                     "type": "decimal_parsing",
-                    "loc": ["body", 1, "age"],
+                    "loc": [
+                        "body",
+                        1,
+                        "age",
+                        "function-after[to_decimal(), "
+                        "union[int,constrained-str,function-plain[str()]]]",
+                    ],
                     "msg": "Input should be a valid decimal",
                     "input": "six",
                 },