Browse Source

Refactor test for compatibility with Pydantic v1 and v2

pull/14168/head
Sebastián Ramírez 9 months ago
parent
commit
25b51f22b6
  1. 135
      tests/test_pydantic_v1_v2_multifile/test_multifile.py

135
tests/test_pydantic_v1_v2_multifile/test_multifile.py

@ -339,9 +339,18 @@ def test_openapi_schema():
"requestBody": { "requestBody": {
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": pydantic_snapshot(
"$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2__Item-Input" v2=snapshot(
} {
"$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2__Item-Input"
}
),
v1=snapshot(
{
"$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2__Item"
}
),
),
} }
}, },
"required": True, "required": True,
@ -521,9 +530,18 @@ def test_openapi_schema():
"requestBody": { "requestBody": {
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": pydantic_snapshot(
"$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2__Item-Input" v2=snapshot(
} {
"$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2__Item-Input"
}
),
v1=snapshot(
{
"$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2__Item"
}
),
),
} }
}, },
"required": True, "required": True,
@ -564,9 +582,18 @@ def test_openapi_schema():
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"items": { "items": pydantic_snapshot(
"$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2__Item-Input" v2=snapshot(
}, {
"$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2__Item-Input"
}
),
v1=snapshot(
{
"$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2__Item"
}
),
),
"type": "array", "type": "array",
"title": "Data", "title": "Data",
} }
@ -610,9 +637,18 @@ def test_openapi_schema():
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"items": { "items": pydantic_snapshot(
"$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2__Item-Input" v2=snapshot(
}, {
"$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2__Item-Input"
}
),
v1=snapshot(
{
"$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2__Item"
}
),
),
"type": "array", "type": "array",
"title": "Data", "title": "Data",
} }
@ -750,9 +786,18 @@ def test_openapi_schema():
}, },
"Body_handle_v2_same_name_to_v1_v2_to_v1_same_name_post": { "Body_handle_v2_same_name_to_v1_v2_to_v1_same_name_post": {
"properties": { "properties": {
"item1": { "item1": pydantic_snapshot(
"$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2__Item-Input" v2=snapshot(
}, {
"$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2__Item-Input"
}
),
v1=snapshot(
{
"$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2__Item"
}
),
),
"item2": { "item2": {
"$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2b__Item" "$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2b__Item"
}, },
@ -774,14 +819,6 @@ def test_openapi_schema():
"type": "object", "type": "object",
"title": "HTTPValidationError", "title": "HTTPValidationError",
}, },
"SubItem-Output": {
"properties": {
"new_sub_name": {"type": "string", "title": "New Sub Name"}
},
"type": "object",
"required": ["new_sub_name"],
"title": "SubItem",
},
"ValidationError": { "ValidationError": {
"properties": { "properties": {
"loc": { "loc": {
@ -835,32 +872,17 @@ def test_openapi_schema():
"properties": { "properties": {
"new_title": {"type": "string", "title": "New Title"}, "new_title": {"type": "string", "title": "New Title"},
"new_size": {"type": "integer", "title": "New Size"}, "new_size": {"type": "integer", "title": "New Size"},
"new_description": { "new_description": pydantic_snapshot(
"anyOf": [{"type": "string"}, {"type": "null"}], v2=snapshot(
"title": "New Description", {
}, "anyOf": [{"type": "string"}, {"type": "null"}],
"new_sub": {"$ref": "#/components/schemas/SubItem-Output"}, "title": "New Description",
"new_multi": { }
"items": { ),
"$ref": "#/components/schemas/SubItem-Output" v1=snapshot(
}, {"type": "string", "title": "New Description"}
"type": "array", ),
"title": "New Multi", ),
"default": [],
},
},
"type": "object",
"required": ["new_title", "new_size", "new_sub"],
"title": "Item",
},
"tests__test_pydantic_v1_v2_multifile__modelsv2__Item-Input": {
"properties": {
"new_title": {"type": "string", "title": "New Title"},
"new_size": {"type": "integer", "title": "New Size"},
"new_description": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"title": "New Description",
},
"new_sub": { "new_sub": {
"$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2__SubItem" "$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2__SubItem"
}, },
@ -895,10 +917,17 @@ def test_openapi_schema():
"properties": { "properties": {
"dup_title": {"type": "string", "title": "Dup Title"}, "dup_title": {"type": "string", "title": "Dup Title"},
"dup_size": {"type": "integer", "title": "Dup Size"}, "dup_size": {"type": "integer", "title": "Dup Size"},
"dup_description": { "dup_description": pydantic_snapshot(
"anyOf": [{"type": "string"}, {"type": "null"}], v2=snapshot(
"title": "Dup Description", {
}, "anyOf": [{"type": "string"}, {"type": "null"}],
"title": "Dup Description",
}
),
v1=snapshot(
{"type": "string", "title": "Dup Description"}
),
),
"dup_sub": { "dup_sub": {
"$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2b__SubItem" "$ref": "#/components/schemas/tests__test_pydantic_v1_v2_multifile__modelsv2b__SubItem"
}, },

Loading…
Cancel
Save