| 1 |
from fastapi.testclient import TestClient |
| 2 |
from inline_snapshot import snapshot |
| 3 |
|
| 4 |
from docs_src.sub_applications.tutorial001_py310 import app |
| 5 |
|
| 6 |
client = TestClient(app) |
| 7 |
|
| 8 |
|
| 9 |
def test_main(): |
| 10 |
response = client.get("/app") |
| 11 |
assert response.status_code == 200, response.text |
| 12 |
assert response.json() == {"message": "Hello World from main app"} |
| 13 |
|
| 14 |
|
| 15 |
def test_sub(): |
| 16 |
response = client.get("/subapi/sub") |
| 17 |
assert response.status_code == 200, response.text |
| 18 |
assert response.json() == {"message": "Hello World from sub API"} |
| 19 |
|
| 20 |
|
| 21 |
def test_openapi_schema_main(): |
| 22 |
response = client.get("/openapi.json") |
| 23 |
assert response.status_code == 200, response.text |
| 24 |
assert response.json() == snapshot( |
| 25 |
{ |
| 26 |
"openapi": "3.1.0", |
| 27 |
"info": {"title": "FastAPI", "version": "0.1.0"}, |
| 28 |
"paths": { |
| 29 |
"/app": { |
| 30 |
"get": { |
| 31 |
"responses": { |
| 32 |
"200": { |
| 33 |
"description": "Successful Response", |
| 34 |
"content": {"application/json": {"schema": {}}}, |
| 35 |
} |
| 36 |
}, |
| 37 |
"summary": "Read Main", |
| 38 |
"operationId": "read_main_app_get", |
| 39 |
} |
| 40 |
} |
| 41 |
}, |
| 42 |
} |
| 43 |
) |
| 44 |
|
| 45 |
|
| 46 |
def test_openapi_schema_sub(): |
| 47 |
response = client.get("/subapi/openapi.json") |
| 48 |
assert response.status_code == 200, response.text |
| 49 |
assert response.json() == snapshot( |
| 50 |
{ |
| 51 |
"openapi": "3.1.0", |
| 52 |
"info": {"title": "FastAPI", "version": "0.1.0"}, |
| 53 |
"paths": { |
| 54 |
"/sub": { |
| 55 |
"get": { |
| 56 |
"responses": { |
| 57 |
"200": { |
| 58 |
"description": "Successful Response", |
| 59 |
"content": {"application/json": {"schema": {}}}, |
| 60 |
} |
| 61 |
}, |
| 62 |
"summary": "Read Sub", |
| 63 |
"operationId": "read_sub_sub_get", |
| 64 |
} |
| 65 |
} |
| 66 |
}, |
| 67 |
"servers": [{"url": "/subapi"}], |
| 68 |
} |
| 69 |
) |