| 1 |
from fastapi.testclient import TestClient |
| 2 |
from inline_snapshot import snapshot |
| 3 |
|
| 4 |
from docs_src.metadata.tutorial004_py310 import app |
| 5 |
|
| 6 |
client = TestClient(app) |
| 7 |
|
| 8 |
|
| 9 |
def test_path_operations(): |
| 10 |
response = client.get("/items/") |
| 11 |
assert response.status_code == 200, response.text |
| 12 |
response = client.get("/users/") |
| 13 |
assert response.status_code == 200, response.text |
| 14 |
|
| 15 |
|
| 16 |
def test_openapi_schema(): |
| 17 |
response = client.get("/openapi.json") |
| 18 |
assert response.status_code == 200, response.text |
| 19 |
assert response.json() == snapshot( |
| 20 |
{ |
| 21 |
"openapi": "3.1.0", |
| 22 |
"info": {"title": "FastAPI", "version": "0.1.0"}, |
| 23 |
"paths": { |
| 24 |
"/users/": { |
| 25 |
"get": { |
| 26 |
"tags": ["users"], |
| 27 |
"summary": "Get Users", |
| 28 |
"operationId": "get_users_users__get", |
| 29 |
"responses": { |
| 30 |
"200": { |
| 31 |
"description": "Successful Response", |
| 32 |
"content": {"application/json": {"schema": {}}}, |
| 33 |
} |
| 34 |
}, |
| 35 |
} |
| 36 |
}, |
| 37 |
"/items/": { |
| 38 |
"get": { |
| 39 |
"tags": ["items"], |
| 40 |
"summary": "Get Items", |
| 41 |
"operationId": "get_items_items__get", |
| 42 |
"responses": { |
| 43 |
"200": { |
| 44 |
"description": "Successful Response", |
| 45 |
"content": {"application/json": {"schema": {}}}, |
| 46 |
} |
| 47 |
}, |
| 48 |
} |
| 49 |
}, |
| 50 |
}, |
| 51 |
"tags": [ |
| 52 |
{ |
| 53 |
"name": "users", |
| 54 |
"description": "Operations with users. The **login** logic is also here.", |
| 55 |
}, |
| 56 |
{ |
| 57 |
"name": "items", |
| 58 |
"description": "Manage items. So _fancy_ they have their own docs.", |
| 59 |
"externalDocs": { |
| 60 |
"description": "Items external docs", |
| 61 |
"url": "https://fastapi.tiangolo.com/", |
| 62 |
}, |
| 63 |
}, |
| 64 |
], |
| 65 |
} |
| 66 |
) |