mirror of https://github.com/tiangolo/fastapi.git
✅ Test for missing required body
This commit is contained in:
parent
7ee32ea197
commit
22dc7e9132
|
|
@ -124,6 +124,16 @@ name_price_missing = {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body_missing = {
|
||||||
|
"detail": [
|
||||||
|
{
|
||||||
|
"loc": ["body", "item"],
|
||||||
|
"msg": "field required",
|
||||||
|
"type": "value_error.missing",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path,body,expected_status,expected_response",
|
"path,body,expected_status,expected_response",
|
||||||
|
|
@ -155,6 +165,7 @@ name_price_missing = {
|
||||||
("/items/", {"name": "Foo"}, 422, price_missing),
|
("/items/", {"name": "Foo"}, 422, price_missing),
|
||||||
("/items/", {"name": "Foo", "price": "twenty"}, 422, price_not_float),
|
("/items/", {"name": "Foo", "price": "twenty"}, 422, price_not_float),
|
||||||
("/items/", {}, 422, name_price_missing),
|
("/items/", {}, 422, name_price_missing),
|
||||||
|
("/items/", None, 422, body_missing),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_post_body(path, body, expected_status, expected_response):
|
def test_post_body(path, body, expected_status, expected_response):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue