| 1 |
from fastapi.testclient import TestClient |
| 2 |
from inline_snapshot import snapshot |
| 3 |
|
| 4 |
from docs_src.behind_a_proxy.tutorial001_py310 import app |
| 5 |
|
| 6 |
client = TestClient(app, root_path="/api/v1") |
| 7 |
|
| 8 |
|
| 9 |
def test_main(): |
| 10 |
response = client.get("/app") |
| 11 |
assert response.status_code == 200 |
| 12 |
assert response.json() == {"message": "Hello World", "root_path": "/api/v1"} |
| 13 |
|
| 14 |
|
| 15 |
def test_openapi(): |
| 16 |
response = client.get("/openapi.json") |
| 17 |
assert response.status_code == 200 |
| 18 |
assert response.json() == snapshot( |
| 19 |
{ |
| 20 |
"openapi": "3.1.0", |
| 21 |
"info": {"title": "FastAPI", "version": "0.1.0"}, |
| 22 |
"paths": { |
| 23 |
"/app": { |
| 24 |
"get": { |
| 25 |
"summary": "Read Main", |
| 26 |
"operationId": "read_main_app_get", |
| 27 |
"responses": { |
| 28 |
"200": { |
| 29 |
"description": "Successful Response", |
| 30 |
"content": {"application/json": {"schema": {}}}, |
| 31 |
} |
| 32 |
}, |
| 33 |
} |
| 34 |
} |
| 35 |
}, |
| 36 |
"servers": [{"url": "/api/v1"}], |
| 37 |
} |
| 38 |
) |