mirror of https://github.com/tiangolo/fastapi.git
✅ Fix tests for compatibility with pydantic 2.1.1 (#9943)
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>
This commit is contained in:
parent
94c48cfc8c
commit
25694f5ae1
|
|
@ -25,7 +25,7 @@ jobs:
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: ${{ env.pythonLocation }}
|
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
|
- name: Install Dependencies
|
||||||
if: steps.cache.outputs.cache-hit != 'true'
|
if: steps.cache.outputs.cache-hit != 'true'
|
||||||
run: pip install -r requirements-tests.txt
|
run: pip install -r requirements-tests.txt
|
||||||
|
|
@ -54,7 +54,7 @@ jobs:
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: ${{ env.pythonLocation }}
|
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
|
- name: Install Dependencies
|
||||||
if: steps.cache.outputs.cache-hit != 'true'
|
if: steps.cache.outputs.cache-hit != 'true'
|
||||||
run: pip install -r requirements-tests.txt
|
run: pip install -r requirements-tests.txt
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from dirty_equals import IsDict
|
from dirty_equals import HasRepr, IsDict
|
||||||
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
|
||||||
|
|
@ -66,7 +66,7 @@ def test_validator_is_cloned(client: TestClient):
|
||||||
"loc": ("response", "name"),
|
"loc": ("response", "name"),
|
||||||
"msg": "Value error, name must end in A",
|
"msg": "Value error, name must end in A",
|
||||||
"input": "modelX",
|
"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"),
|
"url": match_pydantic_error_url("value_error"),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ def test_jsonable_encoder_requiring_error():
|
||||||
"loc": ["body", 0, "age"],
|
"loc": ["body", 0, "age"],
|
||||||
"msg": "Input should be greater than 0",
|
"msg": "Input should be greater than 0",
|
||||||
"input": -1.0,
|
"input": -1.0,
|
||||||
"ctx": {"gt": 0.0},
|
"ctx": {"gt": "0"},
|
||||||
"url": match_pydantic_error_url("greater_than"),
|
"url": match_pydantic_error_url("greater_than"),
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -84,9 +84,23 @@ def test_put_incorrect_body_multiple():
|
||||||
"input": {"age": "five"},
|
"input": {"age": "five"},
|
||||||
"url": match_pydantic_error_url("missing"),
|
"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",
|
"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",
|
"msg": "Input should be a valid decimal",
|
||||||
"input": "five",
|
"input": "five",
|
||||||
},
|
},
|
||||||
|
|
@ -97,9 +111,23 @@ def test_put_incorrect_body_multiple():
|
||||||
"input": {"age": "six"},
|
"input": {"age": "six"},
|
||||||
"url": match_pydantic_error_url("missing"),
|
"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",
|
"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",
|
"msg": "Input should be a valid decimal",
|
||||||
"input": "six",
|
"input": "six",
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue