| 1 |
from fastapi.testclient import TestClient |
| 2 |
from inline_snapshot import snapshot |
| 3 |
|
| 4 |
from docs_src.metadata.tutorial003_py310 import app |
| 5 |
|
| 6 |
client = TestClient(app) |
| 7 |
|
| 8 |
|
| 9 |
def test_items(): |
| 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": "FastAPI", |
| 23 |
"version": "0.1.0", |
| 24 |
}, |
| 25 |
"paths": { |
| 26 |
"/items/": { |
| 27 |
"get": { |
| 28 |
"summary": "Read Items", |
| 29 |
"operationId": "read_items_items__get", |
| 30 |
"responses": { |
| 31 |
"200": { |
| 32 |
"description": "Successful Response", |
| 33 |
"content": {"application/json": {"schema": {}}}, |
| 34 |
} |
| 35 |
}, |
| 36 |
} |
| 37 |
} |
| 38 |
}, |
| 39 |
} |
| 40 |
) |
| 41 |
|
| 42 |
|
| 43 |
def test_swagger_ui_default_url(): |
| 44 |
response = client.get("/docs") |
| 45 |
assert response.status_code == 404, response.text |
| 46 |
|
| 47 |
|
| 48 |
def test_swagger_ui_custom_url(): |
| 49 |
response = client.get("/documentation") |
| 50 |
assert response.status_code == 200, response.text |
| 51 |
assert "<title>FastAPI - Swagger UI</title>" in response.text |
| 52 |
|
| 53 |
|
| 54 |
def test_redoc_ui_default_url(): |
| 55 |
response = client.get("/redoc") |
| 56 |
assert response.status_code == 404, response.text |