Browse Source

Add snapshots for Pydantic v2 tests

pull/14168/head
Sebastián Ramírez 10 months ago
parent
commit
ab242c6e34
  1. 44
      tests/test_pydantic_v1_v2_01.py
  2. 22
      tests/test_pydantic_v1_v2_list.py
  3. 98
      tests/test_pydantic_v1_v2_mixed.py
  4. 88
      tests/test_pydantic_v1_v2_noneable.py

44
tests/test_pydantic_v1_v2_01.py

@ -222,7 +222,16 @@ def test_openapi_schema():
"content": {
"application/json": {
"schema": pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
{
"allOf": [
{
"$ref": "#/components/schemas/SubItem"
}
],
"title": "Data",
}
),
v1=snapshot(
{"$ref": "#/components/schemas/SubItem"}
),
@ -263,7 +272,16 @@ def test_openapi_schema():
"content": {
"application/json": {
"schema": pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
{
"allOf": [
{
"$ref": "#/components/schemas/SubItem"
}
],
"title": "Data",
}
),
v1=snapshot(
{"$ref": "#/components/schemas/SubItem"}
),
@ -304,7 +322,16 @@ def test_openapi_schema():
"content": {
"application/json": {
"schema": pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
{
"allOf": [
{
"$ref": "#/components/schemas/Item"
}
],
"title": "Data",
}
),
v1=snapshot(
{"$ref": "#/components/schemas/Item"}
),
@ -343,7 +370,16 @@ def test_openapi_schema():
"content": {
"application/json": {
"schema": pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
{
"allOf": [
{
"$ref": "#/components/schemas/Item"
}
],
"title": "Data",
}
),
v1=snapshot(
{"$ref": "#/components/schemas/Item"}
),

22
tests/test_pydantic_v1_v2_list.py

@ -351,7 +351,16 @@ def test_openapi_schema():
"content": {
"application/json": {
"schema": pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
{
"allOf": [
{
"$ref": "#/components/schemas/Item"
}
],
"title": "Data",
}
),
v1=snapshot(
{"$ref": "#/components/schemas/Item"}
),
@ -396,7 +405,16 @@ def test_openapi_schema():
"content": {
"application/json": {
"schema": pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
{
"allOf": [
{
"$ref": "#/components/schemas/Item"
}
],
"title": "Data",
}
),
v1=snapshot(
{"$ref": "#/components/schemas/Item"}
),

98
tests/test_pydantic_v1_v2_mixed.py

@ -665,7 +665,22 @@ def test_v2_to_v1_validation_error():
assert response.json() == snapshot(
{
"detail": pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
[
{
"type": "missing",
"loc": ["body", "new_size"],
"msg": "Field required",
"input": {"new_title": "Missing fields"},
},
{
"type": "missing",
"loc": ["body", "new_sub"],
"msg": "Field required",
"input": {"new_title": "Missing fields"},
},
]
),
v1=snapshot(
[
{
@ -699,7 +714,14 @@ def test_v2_to_v1_nested_validation_error():
{
"detail": [
pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
{
"type": "missing",
"loc": ["body", "new_sub", "new_sub_name"],
"msg": "Field required",
"input": {"wrong_field": "value"},
}
),
v1=snapshot(
{
"loc": ["body", "new_sub", "new_sub_name"],
@ -752,7 +774,22 @@ def test_v2_list_validation_error():
assert response.json() == snapshot(
{
"detail": pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
[
{
"type": "missing",
"loc": ["body", 1, "new_size"],
"msg": "Field required",
"input": {"new_title": "Invalid"},
},
{
"type": "missing",
"loc": ["body", 1, "new_sub"],
"msg": "Field required",
"input": {"new_title": "Invalid"},
},
]
),
v1=snapshot(
[
{
@ -804,7 +841,20 @@ def test_invalid_list_structure_v2():
assert response.json() == snapshot(
{
"detail": pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
[
{
"type": "list_type",
"loc": ["body"],
"msg": "Input should be a valid list",
"input": {
"new_title": "Not a list",
"new_size": 100,
"new_sub": {"new_sub_name": "Sub"},
},
}
]
),
v1=snapshot(
[
{
@ -835,7 +885,16 @@ def test_openapi_schema():
"content": {
"application/json": {
"schema": pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
{
"allOf": [
{
"$ref": "#/components/schemas/Item"
}
],
"title": "Data",
}
),
v1=snapshot(
{"$ref": "#/components/schemas/Item"}
),
@ -876,7 +935,16 @@ def test_openapi_schema():
"content": {
"application/json": {
"schema": pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
{
"allOf": [
{
"$ref": "#/components/schemas/Item"
}
],
"title": "Data",
}
),
v1=snapshot(
{"$ref": "#/components/schemas/Item"}
),
@ -985,7 +1053,16 @@ def test_openapi_schema():
"content": {
"application/json": {
"schema": pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
{
"allOf": [
{
"$ref": "#/components/schemas/Item"
}
],
"title": "Data",
}
),
v1=snapshot(
{"$ref": "#/components/schemas/Item"}
),
@ -1360,7 +1437,12 @@ def test_openapi_schema():
"new_title": {"type": "string", "title": "New Title"},
"new_size": {"type": "integer", "title": "New Size"},
"new_description": pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
{
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "New Description",
}
),
v1=snapshot(
{"type": "string", "title": "New Description"}
),

88
tests/test_pydantic_v1_v2_noneable.py

@ -309,7 +309,22 @@ def test_v2_to_v1_validation_error():
assert response.json() == snapshot(
{
"detail": pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
[
{
"type": "missing",
"loc": ["body", "new_size"],
"msg": "Field required",
"input": {"new_title": "Missing fields"},
},
{
"type": "missing",
"loc": ["body", "new_sub"],
"msg": "Field required",
"input": {"new_title": "Missing fields"},
},
]
),
v1=snapshot(
[
{
@ -343,7 +358,14 @@ def test_v2_to_v1_nested_validation_error():
{
"detail": [
pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
{
"type": "missing",
"loc": ["body", "new_sub", "new_sub_name"],
"msg": "Field required",
"input": {"wrong_field": "value"},
}
),
v1=snapshot(
{
"loc": ["body", "new_sub", "new_sub_name"],
@ -371,7 +393,14 @@ def test_v2_to_v1_type_validation_error():
{
"detail": [
pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
{
"type": "int_parsing",
"loc": ["body", "new_size"],
"msg": "Input should be a valid integer, unable to parse string as an integer",
"input": "not_a_number",
}
),
v1=snapshot(
{
"loc": ["body", "new_size"],
@ -451,7 +480,16 @@ def test_openapi_schema():
"content": {
"application/json": {
"schema": pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
{
"allOf": [
{
"$ref": "#/components/schemas/Item"
}
],
"title": "Data",
}
),
v1=snapshot(
{"$ref": "#/components/schemas/Item"}
),
@ -466,7 +504,17 @@ def test_openapi_schema():
"content": {
"application/json": {
"schema": pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
{
"anyOf": [
{
"$ref": "#/components/schemas/NewItem"
},
{"type": "null"},
],
"title": "Response Handle V1 Item To V2 V1 To V2 Post",
}
),
v1=snapshot(
{"$ref": "#/components/schemas/NewItem"}
),
@ -495,7 +543,16 @@ def test_openapi_schema():
"content": {
"application/json": {
"schema": pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
{
"allOf": [
{
"$ref": "#/components/schemas/Item"
}
],
"title": "Data",
}
),
v1=snapshot(
{"$ref": "#/components/schemas/Item"}
),
@ -510,7 +567,17 @@ def test_openapi_schema():
"content": {
"application/json": {
"schema": pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
{
"anyOf": [
{
"$ref": "#/components/schemas/NewItem"
},
{"type": "null"},
],
"title": "Response Handle V1 Item To V2 Filter V1 To V2 Item Filter Post",
}
),
v1=snapshot(
{"$ref": "#/components/schemas/NewItem"}
),
@ -637,7 +704,12 @@ def test_openapi_schema():
"new_title": {"type": "string", "title": "New Title"},
"new_size": {"type": "integer", "title": "New Size"},
"new_description": pydantic_snapshot(
v2=snapshot(),
v2=snapshot(
{
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "New Description",
}
),
v1=snapshot(
{"type": "string", "title": "New Description"}
),

Loading…
Cancel
Save