From 4b1ca3e9a1d3ca9d66b7320f7cd7036250f6f18f Mon Sep 17 00:00:00 2001 From: merlinz01 <158784988+merlinz01@users.noreply.github.com> Date: Fri, 6 Sep 2024 06:57:14 -0400 Subject: [PATCH] update required field test for Pydantic v1 Signed-off-by: merlinz01 <158784988+merlinz01@users.noreply.github.com> --- tests/test_none_passed_when_null_received.py | 33 ++++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/tests/test_none_passed_when_null_received.py b/tests/test_none_passed_when_null_received.py index 1a0be42fd..868dd3350 100644 --- a/tests/test_none_passed_when_null_received.py +++ b/tests/test_none_passed_when_null_received.py @@ -2,6 +2,7 @@ import sys from typing import Optional, Union import pytest +from dirty_equals import IsDict from fastapi import Body, FastAPI from fastapi.testclient import TestClient @@ -72,13 +73,25 @@ def test_apis(api): def test_required_field(): response = client.post("/api5", json={"integer": None}) assert response.status_code == 422, response.text - assert response.json() == { - "detail": [ - { - "loc": ["body", "integer"], - "msg": "Field required", - "type": "missing", - "input": None, - } - ] - } + assert response.json() == IsDict( + { + "detail": [ + { + "loc": ["body", "integer"], + "msg": "Field required", + "type": "missing", + "input": None, + } + ] + } + ) | IsDict( + { + "detail": [ + { + "loc": ["body", "integer"], + "msg": "field required", + "type": "value_error.missing", + } + ] + } + )