|
@ -1,3 +1,4 @@ |
|
|
|
|
|
from fastapi._compat import PYDANTIC_VERSION_MINOR_TUPLE |
|
|
from fastapi.testclient import TestClient |
|
|
from fastapi.testclient import TestClient |
|
|
|
|
|
|
|
|
from docs_src.handling_errors.tutorial004 import app |
|
|
from docs_src.handling_errors.tutorial004 import app |
|
@ -8,18 +9,20 @@ 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 == 400, response.text |
|
|
assert response.status_code == 400, response.text |
|
|
# TODO: remove when deprecating Pydantic v1 |
|
|
if PYDANTIC_VERSION_MINOR_TUPLE < (2, 0): |
|
|
assert ( |
|
|
assert ( |
|
|
# TODO: remove when deprecating Pydantic v1 |
|
|
response.text |
|
|
"path -> item_id" in response.text |
|
|
== """1 validation error |
|
|
or "'loc': ('path', 'item_id')" in response.text |
|
|
path -> item_id |
|
|
) |
|
|
value is not a valid integer (type=type_error.integer)""" |
|
|
assert ( |
|
|
) |
|
|
# TODO: remove when deprecating Pydantic v1 |
|
|
else: |
|
|
"value is not a valid integer" in response.text |
|
|
assert ( |
|
|
or "Input should be a valid integer, unable to parse string as an integer" |
|
|
response.text |
|
|
in response.text |
|
|
== """1 validation error |
|
|
) |
|
|
path -> item_id |
|
|
|
|
|
Input should be a valid integer, unable to parse string as an integer (type=int_parsing)""" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_http_error(): |
|
|
def test_get_http_error(): |
|
|