lqs
d20566fe07
Some checks failed
Test / lint (push) Has been cancelled
Test / test (pydantic-v1, 3.10) (push) Has been cancelled
Test / test (pydantic-v1, 3.11) (push) Has been cancelled
Test / test (pydantic-v1, 3.12) (push) Has been cancelled
Test / test (pydantic-v1, 3.8) (push) Has been cancelled
Test / test (pydantic-v1, 3.9) (push) Has been cancelled
Test / test (pydantic-v2, 3.10) (push) Has been cancelled
Test / test (pydantic-v2, 3.11) (push) Has been cancelled
Test / test (pydantic-v2, 3.12) (push) Has been cancelled
Test / test (pydantic-v2, 3.8) (push) Has been cancelled
Test / test (pydantic-v2, 3.9) (push) Has been cancelled
Test / coverage-combine (push) Has been cancelled
Test / check (push) Has been cancelled
Issue Manager / issue-manager (push) Has been cancelled
Label Approved / label-approved (push) Has been cancelled
98 lines
3.5 KiB
Python
98 lines
3.5 KiB
Python
from dirty_equals import IsDict, IsOneOf
|
|
from fastapi.testclient import TestClient
|
|
|
|
from docs_src.dataclasses.tutorial002 import app
|
|
|
|
client = TestClient(app)
|
|
|
|
|
|
def test_get_item():
|
|
response = client.get("/items/next")
|
|
assert response.status_code == 200
|
|
assert response.json() == {
|
|
"name": "Island In The Moon",
|
|
"price": 12.99,
|
|
"description": "A place to be playin' and havin' fun",
|
|
"tags": ["breater"],
|
|
"tax": None,
|
|
}
|
|
|
|
|
|
def test_openapi_schema():
|
|
response = client.get("/openapi.json")
|
|
assert response.status_code == 200
|
|
assert response.json() == {
|
|
"openapi": "3.1.0",
|
|
"info": {"title": "FastAPI", "version": "0.1.0"},
|
|
"paths": {
|
|
"/items/next": {
|
|
"get": {
|
|
"summary": "Read Next Item",
|
|
"operationId": "read_next_item_items_next_get",
|
|
"responses": {
|
|
"200": {
|
|
"description": "Successful Response",
|
|
"content": {
|
|
"application/json": {
|
|
"schema": {"$ref": "#/components/schemas/Item"}
|
|
}
|
|
},
|
|
}
|
|
},
|
|
}
|
|
}
|
|
},
|
|
"components": {
|
|
"schemas": {
|
|
"Item": {
|
|
"title": "Item",
|
|
"required": IsOneOf(
|
|
["name", "price", "tags", "description", "tax"],
|
|
# TODO: remove when deprecating Pydantic v1
|
|
["name", "price"],
|
|
),
|
|
"type": "object",
|
|
"properties": {
|
|
"name": {"title": "Name", "type": "string"},
|
|
"price": {"title": "Price", "type": "number"},
|
|
"tags": IsDict(
|
|
{
|
|
"title": "Tags",
|
|
"type": "array",
|
|
"items": {"type": "string"},
|
|
}
|
|
)
|
|
| IsDict(
|
|
# TODO: remove when deprecating Pydantic v1
|
|
{
|
|
"title": "Tags",
|
|
"type": "array",
|
|
"items": {"type": "string"},
|
|
}
|
|
),
|
|
"description": IsDict(
|
|
{
|
|
"title": "Description",
|
|
"anyOf": [{"type": "string"}, {"type": "null"}],
|
|
}
|
|
)
|
|
| IsDict(
|
|
# TODO: remove when deprecating Pydantic v1
|
|
{"title": "Description", "type": "string"}
|
|
),
|
|
"tax": IsDict(
|
|
{
|
|
"title": "Tax",
|
|
"anyOf": [{"type": "number"}, {"type": "null"}],
|
|
}
|
|
)
|
|
| IsDict(
|
|
# TODO: remove when deprecating Pydantic v1
|
|
{"title": "Tax", "type": "number"}
|
|
),
|
|
},
|
|
}
|
|
}
|
|
},
|
|
}
|