| 1 |
from fastapi.testclient import TestClient |
| 2 |
from inline_snapshot import snapshot |
| 3 |
|
| 4 |
from docs_src.extending_openapi.tutorial001_py310 import app |
| 5 |
|
| 6 |
client = TestClient(app) |
| 7 |
|
| 8 |
|
| 9 |
def test(): |
| 10 |
response = client.get("/items/") |
| 11 |
assert response.status_code == 200, response.text |
| 12 |
assert response.json() == [{"name": "Foo"}] |
| 13 |
|
| 14 |
|
| 15 |
def test_openapi_schema(): |
| 16 |
response = client.get("/openapi.json") |
| 17 |
assert response.status_code == 200, response.text |
| 18 |
assert response.json() == snapshot( |
| 19 |
{ |
| 20 |
"openapi": "3.1.0", |
| 21 |
"info": { |
| 22 |
"title": "Custom title", |
| 23 |
"summary": "This is a very custom OpenAPI schema", |
| 24 |
"description": "Here's a longer description of the custom **OpenAPI** schema", |
| 25 |
"version": "2.5.0", |
| 26 |
"x-logo": { |
| 27 |
"url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png" |
| 28 |
}, |
| 29 |
}, |
| 30 |
"paths": { |
| 31 |
"/items/": { |
| 32 |
"get": { |
| 33 |
"responses": { |
| 34 |
"200": { |
| 35 |
"description": "Successful Response", |
| 36 |
"content": {"application/json": {"schema": {}}}, |
| 37 |
} |
| 38 |
}, |
| 39 |
"summary": "Read Items", |
| 40 |
"operationId": "read_items_items__get", |
| 41 |
} |
| 42 |
} |
| 43 |
}, |
| 44 |
} |
| 45 |
) |
| 46 |
openapi_schema = response.json() |
| 47 |
# Request again to test the custom cache |
| 48 |
response = client.get("/openapi.json") |
| 49 |
assert response.status_code == 200, response.text |
| 50 |
assert response.json() == openapi_schema |