| 1 |
from fastapi.testclient import TestClient |
| 2 |
from inline_snapshot import snapshot |
| 3 |
|
| 4 |
from docs_src.path_operation_advanced_configuration.tutorial006_py310 import app |
| 5 |
|
| 6 |
client = TestClient(app) |
| 7 |
|
| 8 |
|
| 9 |
def test_post(): |
| 10 |
response = client.post("/items/", content=b"this is actually not validated") |
| 11 |
assert response.status_code == 200, response.text |
| 12 |
assert response.json() == { |
| 13 |
"size": 30, |
| 14 |
"content": { |
| 15 |
"name": "Maaaagic", |
| 16 |
"price": 42, |
| 17 |
"description": "Just kiddin', no magic here. ✨", |
| 18 |
}, |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
def test_openapi_schema(): |
| 23 |
response = client.get("/openapi.json") |
| 24 |
assert response.status_code == 200, response.text |
| 25 |
assert response.json() == snapshot( |
| 26 |
{ |
| 27 |
"openapi": "3.1.0", |
| 28 |
"info": {"title": "FastAPI", "version": "0.1.0"}, |
| 29 |
"paths": { |
| 30 |
"/items/": { |
| 31 |
"post": { |
| 32 |
"summary": "Create Item", |
| 33 |
"operationId": "create_item_items__post", |
| 34 |
"requestBody": { |
| 35 |
"content": { |
| 36 |
"application/json": { |
| 37 |
"schema": { |
| 38 |
"required": ["name", "price"], |
| 39 |
"type": "object", |
| 40 |
"properties": { |
| 41 |
"name": {"type": "string"}, |
| 42 |
"price": {"type": "number"}, |
| 43 |
"description": {"type": "string"}, |
| 44 |
}, |
| 45 |
} |
| 46 |
} |
| 47 |
}, |
| 48 |
"required": True, |
| 49 |
}, |
| 50 |
"responses": { |
| 51 |
"200": { |
| 52 |
"description": "Successful Response", |
| 53 |
"content": {"application/json": {"schema": {}}}, |
| 54 |
} |
| 55 |
}, |
| 56 |
} |
| 57 |
} |
| 58 |
}, |
| 59 |
} |
| 60 |
) |