Browse Source

update required field test for Pydantic v1

Signed-off-by: merlinz01 <na@notaccessible.xyz>
pull/12135/head
merlinz01 8 months ago
parent
commit
85fc35cd5a
  1. 33
      tests/test_none_passed_when_null_received.py

33
tests/test_none_passed_when_null_received.py

@ -2,6 +2,7 @@ import sys
from typing import Optional, Union from typing import Optional, Union
import pytest import pytest
from dirty_equals import IsDict
from fastapi import Body, FastAPI from fastapi import Body, FastAPI
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -72,13 +73,25 @@ def test_apis(api):
def test_required_field(): def test_required_field():
response = client.post("/api5", json={"integer": None}) response = client.post("/api5", json={"integer": None})
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == { assert response.json() == IsDict(
"detail": [ {
{ "detail": [
"loc": ["body", "integer"], {
"msg": "Field required", "loc": ["body", "integer"],
"type": "missing", "msg": "Field required",
"input": None, "type": "missing",
} "input": None,
] }
} ]
}
) | IsDict(
{
"detail": [
{
"loc": ["body", "integer"],
"msg": "field required",
"type": "value_error.missing",
}
]
}
)

Loading…
Cancel
Save