Skip to content

Commit

Permalink
test: correct the examples for the pydantic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guacs committed Nov 12, 2023
1 parent 287e00e commit b382d9f
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions tests/unit/test_contrib/test_pydantic/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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:
Expand All @@ -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])
Expand Down

0 comments on commit b382d9f

Please sign in to comment.