| 1 |
from fastapi.testclient import TestClient |
| 2 |
from inline_snapshot import snapshot |
| 3 |
|
| 4 |
from docs_src.path_operation_advanced_configuration.tutorial002_py310 import app |
| 5 |
|
| 6 |
client = TestClient(app) |
| 7 |
|
| 8 |
|
| 9 |
def test_get(): |
| 10 |
response = client.get("/items/") |
| 11 |
assert response.status_code == 200, response.text |
| 12 |
assert response.json() == [{"item_id": "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": {"title": "FastAPI", "version": "0.1.0"}, |
| 22 |
"paths": { |
| 23 |
"/items/": { |
| 24 |
"get": { |
| 25 |
"responses": { |
| 26 |
"200": { |
| 27 |
"description": "Successful Response", |
| 28 |
"content": {"application/json": {"schema": {}}}, |
| 29 |
} |
| 30 |
}, |
| 31 |
"summary": "Read Items", |
| 32 |
"operationId": "read_items", |
| 33 |
} |
| 34 |
} |
| 35 |
}, |
| 36 |
} |
| 37 |
) |