Browse Source

Use inline snapshots in assertions

pull/14829/head
Yurii Motov 5 months ago
parent
commit
1a251c63c2
  1. 47
      tests/test_request_params/test_body/test_nullable_and_defaults.py
  2. 17
      tests/test_request_params/test_cookie/test_nullable_and_defaults.py
  3. 45
      tests/test_request_params/test_file/test_nullable_and_defaults.py
  4. 37
      tests/test_request_params/test_form/test_nullable_and_defaults.py
  5. 17
      tests/test_request_params/test_header/test_nullable_and_defaults.py
  6. 17
      tests/test_request_params/test_query/test_nullable_and_defaults.py

47
tests/test_request_params/test_body/test_nullable_and_defaults.py

@ -5,6 +5,7 @@ import pytest
from dirty_equals import IsList, IsOneOf, IsPartialDict from dirty_equals import IsList, IsOneOf, IsPartialDict
from fastapi import Body, FastAPI from fastapi import Body, FastAPI
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import Is, snapshot
from pydantic import BaseModel, BeforeValidator, field_validator from pydantic import BaseModel, BeforeValidator, field_validator
from .utils import get_body_model_name from .utils import get_body_model_name
@ -92,7 +93,8 @@ def test_nullable_required_schema(path: str):
openapi = app.openapi() openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path) body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == { assert openapi["components"]["schemas"][body_model_name] == snapshot(
{
"properties": { "properties": {
"int_val": { "int_val": {
"title": "Int Val", "title": "Int Val",
@ -111,9 +113,10 @@ def test_nullable_required_schema(path: str):
}, },
}, },
"required": ["int_val", "str_val", "list_val"], "required": ["int_val", "str_val", "list_val"],
"title": body_model_name, "title": Is(body_model_name),
"type": "object", "type": "object",
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -165,7 +168,8 @@ def test_nullable_required_missing(path: str):
client = TestClient(app) client = TestClient(app)
response = client.post(path, json={}) response = client.post(path, json={})
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == { assert response.json() == snapshot(
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -187,6 +191,7 @@ def test_nullable_required_missing(path: str):
}, },
] ]
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -205,7 +210,8 @@ def test_nullable_required_no_body(path: str):
client = TestClient(app) client = TestClient(app)
response = client.post(path) response = client.post(path)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == { assert response.json() == snapshot(
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -215,6 +221,7 @@ def test_nullable_required_no_body(path: str):
}, },
] ]
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -229,7 +236,8 @@ def test_nullable_required_no_embed_missing(path: str):
client = TestClient(app) client = TestClient(app)
response = client.post(path) response = client.post(path)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == { assert response.json() == snapshot(
{
"detail": [ "detail": [
{ {
"input": None, "input": None,
@ -239,6 +247,7 @@ def test_nullable_required_no_embed_missing(path: str):
} }
] ]
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -267,16 +276,18 @@ def test_nullable_required_no_embed_pass_empty_dict(
client = TestClient(app) client = TestClient(app)
response = client.post(path, json={}) response = client.post(path, json={})
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == { assert response.json() == snapshot(
{
"detail": [ "detail": [
{ {
"input": {}, "input": {},
"loc": ["body"], "loc": ["body"],
"msg": msg, "msg": Is(msg),
"type": error_type, "type": Is(error_type),
} }
] ]
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -487,7 +498,8 @@ def test_nullable_non_required_schema(path: str):
openapi = app.openapi() openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path) body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == { assert openapi["components"]["schemas"][body_model_name] == snapshot(
{
"properties": { "properties": {
"int_val": { "int_val": {
"title": "Int Val", "title": "Int Val",
@ -508,9 +520,10 @@ def test_nullable_non_required_schema(path: str):
# "default": None, # `None` values are omitted in OpenAPI schema # "default": None, # `None` values are omitted in OpenAPI schema
}, },
}, },
"title": body_model_name, "title": Is(body_model_name),
"type": "object", "type": "object",
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -595,7 +608,8 @@ def test_nullable_non_required_no_body(path: str):
client = TestClient(app) client = TestClient(app)
response = client.post(path) response = client.post(path)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == { assert response.json() == snapshot(
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -605,6 +619,7 @@ def test_nullable_non_required_no_body(path: str):
}, },
] ]
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -836,7 +851,8 @@ def test_nullable_with_non_null_default_schema(path: str):
body_model_name = get_body_model_name(openapi, path) body_model_name = get_body_model_name(openapi, path)
body_model = app.openapi()["components"]["schemas"][body_model_name] body_model = app.openapi()["components"]["schemas"][body_model_name]
assert body_model == { assert body_model == snapshot(
{
"properties": { "properties": {
"int_val": { "int_val": {
"title": "Int Val", "title": "Int Val",
@ -858,9 +874,10 @@ def test_nullable_with_non_null_default_schema(path: str):
}, },
), ),
}, },
"title": body_model_name, "title": Is(body_model_name),
"type": "object", "type": "object",
} }
)
if path == "/model-nullable-with-non-null-default": if path == "/model-nullable-with-non-null-default":
# Check default value for list_val param for model-based parameters only. # Check default value for list_val param for model-based parameters only.
@ -949,7 +966,8 @@ def test_nullable_with_non_null_default_no_body(path: str):
client = TestClient(app) client = TestClient(app)
response = client.post(path) response = client.post(path)
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == { assert response.json() == snapshot(
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -959,6 +977,7 @@ def test_nullable_with_non_null_default_no_body(path: str):
}, },
] ]
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(

17
tests/test_request_params/test_cookie/test_nullable_and_defaults.py

@ -5,6 +5,7 @@ import pytest
from dirty_equals import IsList, IsOneOf from dirty_equals import IsList, IsOneOf
from fastapi import Cookie, FastAPI from fastapi import Cookie, FastAPI
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from pydantic import BaseModel, BeforeValidator, field_validator from pydantic import BaseModel, BeforeValidator, field_validator
app = FastAPI() app = FastAPI()
@ -67,7 +68,8 @@ async def read_model_nullable_required(
], ],
) )
def test_nullable_required_schema(path: str): def test_nullable_required_schema(path: str):
assert app.openapi()["paths"][path]["get"]["parameters"] == [ assert app.openapi()["paths"][path]["get"]["parameters"] == snapshot(
[
{ {
"required": True, "required": True,
"schema": { "schema": {
@ -87,6 +89,7 @@ def test_nullable_required_schema(path: str):
"in": "cookie", "in": "cookie",
}, },
] ]
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -105,7 +108,8 @@ def test_nullable_required_missing(path: str):
"Validator should not be called if the value is missing" "Validator should not be called if the value is missing"
) )
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == { assert response.json() == snapshot(
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -121,6 +125,7 @@ def test_nullable_required_missing(path: str):
}, },
] ]
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -206,7 +211,8 @@ async def read_model_nullable_non_required(
], ],
) )
def test_nullable_non_required_schema(path: str): def test_nullable_non_required_schema(path: str):
assert app.openapi()["paths"][path]["get"]["parameters"] == [ assert app.openapi()["paths"][path]["get"]["parameters"] == snapshot(
[
{ {
"required": False, "required": False,
"schema": { "schema": {
@ -228,6 +234,7 @@ def test_nullable_non_required_schema(path: str):
"in": "cookie", "in": "cookie",
}, },
] ]
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -339,7 +346,8 @@ async def read_model_nullable_with_non_null_default(
], ],
) )
def test_nullable_with_non_null_default_schema(path: str): def test_nullable_with_non_null_default_schema(path: str):
assert app.openapi()["paths"][path]["get"]["parameters"] == [ assert app.openapi()["paths"][path]["get"]["parameters"] == snapshot(
[
{ {
"required": False, "required": False,
"schema": { "schema": {
@ -361,6 +369,7 @@ def test_nullable_with_non_null_default_schema(path: str):
"in": "cookie", "in": "cookie",
}, },
] ]
)
@pytest.mark.parametrize( @pytest.mark.parametrize(

45
tests/test_request_params/test_file/test_nullable_and_defaults.py

@ -5,6 +5,7 @@ import pytest
from dirty_equals import IsOneOf from dirty_equals import IsOneOf
from fastapi import FastAPI, File, UploadFile from fastapi import FastAPI, File, UploadFile
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import Is, snapshot
from pydantic import BeforeValidator from pydantic import BeforeValidator
from starlette.datastructures import UploadFile as StarletteUploadFile from starlette.datastructures import UploadFile as StarletteUploadFile
@ -70,7 +71,8 @@ def test_nullable_required_schema(path: str):
openapi = app.openapi() openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path) body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == { assert openapi["components"]["schemas"][body_model_name] == snapshot(
{
"properties": { "properties": {
"file": { "file": {
"title": "File", "title": "File",
@ -79,15 +81,19 @@ def test_nullable_required_schema(path: str):
"files": { "files": {
"title": "Files", "title": "Files",
"anyOf": [ "anyOf": [
{"type": "array", "items": {"type": "string", "format": "binary"}}, {
"type": "array",
"items": {"type": "string", "format": "binary"},
},
{"type": "null"}, {"type": "null"},
], ],
}, },
}, },
"required": ["file", "files"], "required": ["file", "files"],
"title": body_model_name, "title": Is(body_model_name),
"type": "object", "type": "object",
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -107,7 +113,8 @@ def test_nullable_required_missing(path: str):
"Validator should not be called if the value is missing" "Validator should not be called if the value is missing"
) )
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == { assert response.json() == snapshot(
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -123,6 +130,7 @@ def test_nullable_required_missing(path: str):
}, },
] ]
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -242,7 +250,8 @@ def test_nullable_non_required_schema(path: str):
openapi = app.openapi() openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path) body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == { assert openapi["components"]["schemas"][body_model_name] == snapshot(
{
"properties": { "properties": {
"file": { "file": {
"title": "File", "title": "File",
@ -252,15 +261,19 @@ def test_nullable_non_required_schema(path: str):
"files": { "files": {
"title": "Files", "title": "Files",
"anyOf": [ "anyOf": [
{"type": "array", "items": {"type": "string", "format": "binary"}}, {
"type": "array",
"items": {"type": "string", "format": "binary"},
},
{"type": "null"}, {"type": "null"},
], ],
# "default": None, # `None` values are omitted in OpenAPI schema # "default": None, # `None` values are omitted in OpenAPI schema
}, },
}, },
"title": body_model_name, "title": Is(body_model_name),
"type": "object", "type": "object",
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -380,24 +393,32 @@ def test_nullable_with_non_null_default_schema(path: str):
openapi = app.openapi() openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path) body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == { assert openapi["components"]["schemas"][body_model_name] == snapshot(
{
"properties": { "properties": {
"file": { "file": {
"title": "File", "title": "File",
"anyOf": [{"type": "string", "format": "binary"}, {"type": "null"}], "anyOf": [
"default": "default", # <= Default value for file looks strange to me {"type": "string", "format": "binary"},
{"type": "null"},
],
"default": "default", # <= Default value here looks strange to me
}, },
"files": { "files": {
"title": "Files", "title": "Files",
"anyOf": [ "anyOf": [
{"type": "array", "items": {"type": "string", "format": "binary"}}, {
"type": "array",
"items": {"type": "string", "format": "binary"},
},
{"type": "null"}, {"type": "null"},
], ],
}, },
}, },
"title": body_model_name, "title": Is(body_model_name),
"type": "object", "type": "object",
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(

37
tests/test_request_params/test_form/test_nullable_and_defaults.py

@ -5,6 +5,7 @@ import pytest
from dirty_equals import IsList, IsOneOf, IsPartialDict from dirty_equals import IsList, IsOneOf, IsPartialDict
from fastapi import FastAPI, Form from fastapi import FastAPI, Form
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import Is, snapshot
from pydantic import BaseModel, BeforeValidator, field_validator from pydantic import BaseModel, BeforeValidator, field_validator
from .utils import get_body_model_name from .utils import get_body_model_name
@ -79,7 +80,8 @@ def test_nullable_required_schema(path: str):
openapi = app.openapi() openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path) body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == { assert openapi["components"]["schemas"][body_model_name] == snapshot(
{
"properties": { "properties": {
"int_val": { "int_val": {
"title": "Int Val", "title": "Int Val",
@ -98,9 +100,10 @@ def test_nullable_required_schema(path: str):
}, },
}, },
"required": ["int_val", "str_val", "list_val"], "required": ["int_val", "str_val", "list_val"],
"title": body_model_name, "title": Is(body_model_name),
"type": "object", "type": "object",
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -120,7 +123,8 @@ def test_nullable_required_missing(path: str):
"Validator should not be called if the value is missing" "Validator should not be called if the value is missing"
) )
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == { assert response.json() == snapshot(
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -142,6 +146,7 @@ def test_nullable_required_missing(path: str):
}, },
] ]
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -218,7 +223,8 @@ def test_nullable_required_pass_empty_str_to_int_val_and_list_val(path: str):
call([""]), # list_val call([""]), # list_val
] ]
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == { assert response.json() == snapshot(
{
"detail": [ "detail": [
{ {
"input": "", "input": "",
@ -234,6 +240,7 @@ def test_nullable_required_pass_empty_str_to_int_val_and_list_val(path: str):
}, },
] ]
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -326,7 +333,8 @@ def test_nullable_non_required_schema(path: str):
openapi = app.openapi() openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path) body_model_name = get_body_model_name(openapi, path)
assert app.openapi()["components"]["schemas"][body_model_name] == { assert openapi["components"]["schemas"][body_model_name] == snapshot(
{
"properties": { "properties": {
"int_val": { "int_val": {
"title": "Int Val", "title": "Int Val",
@ -347,9 +355,10 @@ def test_nullable_non_required_schema(path: str):
# "default": None, # `None` values are omitted in OpenAPI schema # "default": None, # `None` values are omitted in OpenAPI schema
}, },
}, },
"title": body_model_name, "title": Is(body_model_name),
"type": "object", "type": "object",
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -445,7 +454,8 @@ def test_nullable_non_required_pass_empty_str_to_all(path: str):
call([""]), # list_val call([""]), # list_val
] ]
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
assert response.json() == { assert response.json() == snapshot(
{
"detail": [ "detail": [
{ {
"input": "", "input": "",
@ -455,6 +465,7 @@ def test_nullable_non_required_pass_empty_str_to_all(path: str):
}, },
] ]
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -547,9 +558,10 @@ async def read_model_nullable_with_non_null_default(
def test_nullable_with_non_null_default_schema(path: str): def test_nullable_with_non_null_default_schema(path: str):
openapi = app.openapi() openapi = app.openapi()
body_model_name = get_body_model_name(openapi, path) body_model_name = get_body_model_name(openapi, path)
body_model = app.openapi()["components"]["schemas"][body_model_name] body_model = openapi["components"]["schemas"][body_model_name]
assert body_model == { assert body_model == snapshot(
{
"properties": { "properties": {
"int_val": { "int_val": {
"title": "Int Val", "title": "Int Val",
@ -571,9 +583,10 @@ def test_nullable_with_non_null_default_schema(path: str):
} }
), ),
}, },
"title": body_model_name, "title": Is(body_model_name),
"type": "object", "type": "object",
} }
)
if path == "/model-nullable-with-non-null-default": if path == "/model-nullable-with-non-null-default":
# Check default value for list_val param for model-based parameters only. # Check default value for list_val param for model-based parameters only.
@ -691,7 +704,8 @@ def test_nullable_with_non_null_default_pass_empty_str_to_all(path: str):
call([""]), # list_val call([""]), # list_val
] ]
assert response.status_code == 422, response.text # pragma: no cover assert response.status_code == 422, response.text # pragma: no cover
assert response.json() == { # pragma: no cover assert response.json() == snapshot( # pragma: no cover
{
"detail": [ "detail": [
{ {
"input": "", "input": "",
@ -701,6 +715,7 @@ def test_nullable_with_non_null_default_pass_empty_str_to_all(path: str):
}, },
] ]
} }
)
# TODO: Remove 'no cover' when the issue is fixed # TODO: Remove 'no cover' when the issue is fixed

17
tests/test_request_params/test_header/test_nullable_and_defaults.py

@ -5,6 +5,7 @@ import pytest
from dirty_equals import AnyThing, IsList, IsOneOf, IsPartialDict from dirty_equals import AnyThing, IsList, IsOneOf, IsPartialDict
from fastapi import FastAPI, Header from fastapi import FastAPI, Header
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from pydantic import BaseModel, BeforeValidator, field_validator from pydantic import BaseModel, BeforeValidator, field_validator
app = FastAPI() app = FastAPI()
@ -80,7 +81,8 @@ async def read_model_nullable_required(
], ],
) )
def test_nullable_required_schema(path: str): def test_nullable_required_schema(path: str):
assert app.openapi()["paths"][path]["get"]["parameters"] == [ assert app.openapi()["paths"][path]["get"]["parameters"] == snapshot(
[
{ {
"required": True, "required": True,
"schema": { "schema": {
@ -112,6 +114,7 @@ def test_nullable_required_schema(path: str):
"in": "header", "in": "header",
}, },
] ]
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -138,7 +141,8 @@ def test_nullable_required_missing(path: str):
"Validator should not be called if the value is missing" "Validator should not be called if the value is missing"
) )
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == { assert response.json() == snapshot(
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -160,6 +164,7 @@ def test_nullable_required_missing(path: str):
}, },
] ]
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -293,7 +298,8 @@ async def read_model_nullable_non_required(
], ],
) )
def test_nullable_non_required_schema(path: str): def test_nullable_non_required_schema(path: str):
assert app.openapi()["paths"][path]["get"]["parameters"] == [ assert app.openapi()["paths"][path]["get"]["parameters"] == snapshot(
[
{ {
"required": False, "required": False,
"schema": { "schema": {
@ -328,6 +334,7 @@ def test_nullable_non_required_schema(path: str):
"in": "header", "in": "header",
}, },
] ]
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -488,7 +495,8 @@ async def read_model_nullable_with_non_null_default(
) )
def test_nullable_with_non_null_default_schema(path: str): def test_nullable_with_non_null_default_schema(path: str):
parameters = app.openapi()["paths"][path]["get"]["parameters"] parameters = app.openapi()["paths"][path]["get"]["parameters"]
assert parameters == [ assert parameters == snapshot(
[
{ {
"required": False, "required": False,
"schema": { "schema": {
@ -524,6 +532,7 @@ def test_nullable_with_non_null_default_schema(path: str):
"in": "header", "in": "header",
}, },
] ]
)
if path == "/model-nullable-with-non-null-default": if path == "/model-nullable-with-non-null-default":
# Check default value for list_val param for model-based parameters only. # Check default value for list_val param for model-based parameters only.

17
tests/test_request_params/test_query/test_nullable_and_defaults.py

@ -5,6 +5,7 @@ import pytest
from dirty_equals import IsList, IsOneOf, IsPartialDict from dirty_equals import IsList, IsOneOf, IsPartialDict
from fastapi import FastAPI, Query from fastapi import FastAPI, Query
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from pydantic import BaseModel, BeforeValidator, field_validator from pydantic import BaseModel, BeforeValidator, field_validator
app = FastAPI() app = FastAPI()
@ -73,7 +74,8 @@ async def read_model_nullable_required(
], ],
) )
def test_nullable_required_schema(path: str): def test_nullable_required_schema(path: str):
assert app.openapi()["paths"][path]["get"]["parameters"] == [ assert app.openapi()["paths"][path]["get"]["parameters"] == snapshot(
[
{ {
"required": True, "required": True,
"schema": { "schema": {
@ -105,6 +107,7 @@ def test_nullable_required_schema(path: str):
}, },
}, },
] ]
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -124,7 +127,8 @@ def test_nullable_required_missing(path: str):
"Validator should not be called if the value is missing" "Validator should not be called if the value is missing"
) )
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == { assert response.json() == snapshot(
{
"detail": [ "detail": [
{ {
"type": "missing", "type": "missing",
@ -146,6 +150,7 @@ def test_nullable_required_missing(path: str):
}, },
] ]
} }
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -239,7 +244,8 @@ async def read_model_nullable_non_required(
], ],
) )
def test_nullable_non_required_schema(path: str): def test_nullable_non_required_schema(path: str):
assert app.openapi()["paths"][path]["get"]["parameters"] == [ assert app.openapi()["paths"][path]["get"]["parameters"] == snapshot(
[
{ {
"required": False, "required": False,
"schema": { "schema": {
@ -274,6 +280,7 @@ def test_nullable_non_required_schema(path: str):
}, },
}, },
] ]
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -394,7 +401,8 @@ async def read_model_nullable_with_non_null_default(
) )
def test_nullable_with_non_null_default_schema(path: str): def test_nullable_with_non_null_default_schema(path: str):
parameters = app.openapi()["paths"][path]["get"]["parameters"] parameters = app.openapi()["paths"][path]["get"]["parameters"]
assert parameters == [ assert parameters == snapshot(
[
{ {
"required": False, "required": False,
"schema": { "schema": {
@ -430,6 +438,7 @@ def test_nullable_with_non_null_default_schema(path: str):
), ),
}, },
] ]
)
if path == "/model-nullable-with-non-null-default": if path == "/model-nullable-with-non-null-default":
# Check default value for list_val param for model-based parameters only. # Check default value for list_val param for model-based parameters only.

Loading…
Cancel
Save