From b382d9f89ce96cb8cca0fd46d28dba5ec537eb7c Mon Sep 17 00:00:00 2001 From: guacs Date: Sun, 12 Nov 2023 16:24:22 +0530 Subject: [PATCH] test: correct the examples for the pydantic tests --- .../test_pydantic/test_openapi.py | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/unit/test_contrib/test_pydantic/test_openapi.py b/tests/unit/test_contrib/test_pydantic/test_openapi.py index 7d952da9d2..60478a8e43 100644 --- a/tests/unit/test_contrib/test_pydantic/test_openapi.py +++ b/tests/unit/test_contrib/test_pydantic/test_openapi.py @@ -376,7 +376,7 @@ async def example_route() -> Lookup: assert response.status_code == HTTP_200_OK assert response.json()["components"]["schemas"]["Lookup"]["properties"]["id"] == { "description": "A unique identifier", - "examples": [{"value": "e4eaaaf2-d142-11e1-b3e4-080027620cdd"}], + "examples": {"id-example-1": {"value": "e4eaaaf2-d142-11e1-b3e4-080027620cdd"}}, "maxLength": 16, "minLength": 12, "type": "string", @@ -413,7 +413,7 @@ async def example_route() -> Lookup: assert response.status_code == HTTP_200_OK assert response.json()["components"]["schemas"]["Lookup"]["properties"]["id"] == { "description": "A unique identifier", - "examples": [{"value": "e4eaaaf2-d142-11e1-b3e4-080027620cdd"}], + "examples": {"id-example-1": {"value": "e4eaaaf2-d142-11e1-b3e4-080027620cdd"}}, "maxLength": 16, "minLength": 12, "type": "string", @@ -508,9 +508,14 @@ class Model(pydantic_v1.BaseModel): SchemaCreator(schemas=schemas, plugins=[PydanticSchemaPlugin()]).for_field_definition(field_definition) schema = schemas["Model"] - assert schema.properties["value"].description == "description" # type: ignore - assert schema.properties["value"].title == "title" # type: ignore - assert schema.properties["value"].examples == [Example(value="example")] # type: ignore + assert schema.properties + + value = schema.properties["value"] + + assert isinstance(value, Schema) + assert value.description == "description" + assert value.title == "title" + assert value.examples == {"value-example-1": Example(value="example")} def test_create_schema_for_field_v2() -> None: @@ -524,9 +529,14 @@ class Model(pydantic_v2.BaseModel): SchemaCreator(schemas=schemas, plugins=[PydanticSchemaPlugin()]).for_field_definition(field_definition) schema = schemas["Model"] - assert schema.properties["value"].description == "description" # type: ignore - assert schema.properties["value"].title == "title" # type: ignore - assert schema.properties["value"].examples == [Example(value="example")] # type: ignore + assert schema.properties + + value = schema.properties["value"] + + assert isinstance(value, Schema) + assert value.description == "description" + assert value.title == "title" + assert value.examples == {"value-example-1": Example(value="example")} @pytest.mark.parametrize("with_future_annotations", [True, False])