| 1 |
from fastapi.testclient import TestClient |
| 2 |
|
| 3 |
from docs_src.configure_swagger_ui.tutorial002_py310 import app |
| 4 |
|
| 5 |
client = TestClient(app) |
| 6 |
|
| 7 |
|
| 8 |
def test_swagger_ui(): |
| 9 |
response = client.get("/docs") |
| 10 |
assert response.status_code == 200, response.text |
| 11 |
assert '"syntaxHighlight": false' not in response.text, ( |
| 12 |
"not used parameters should not be included" |
| 13 |
) |
| 14 |
assert '"syntaxHighlight": {"theme": "obsidian"}' in response.text, ( |
| 15 |
"parameters with middle dots should be included in a JSON compatible way" |
| 16 |
) |
| 17 |
assert '"dom_id": "#swagger-ui"' in response.text, ( |
| 18 |
"default configs should be preserved" |
| 19 |
) |
| 20 |
assert "presets: [" in response.text, "default configs should be preserved" |
| 21 |
assert "SwaggerUIBundle.presets.apis," in response.text, ( |
| 22 |
"default configs should be preserved" |
| 23 |
) |
| 24 |
assert "SwaggerUIBundle.SwaggerUIStandalonePreset" in response.text, ( |
| 25 |
"default configs should be preserved" |
| 26 |
) |
| 27 |
assert '"layout": "BaseLayout",' in response.text, ( |
| 28 |
"default configs should be preserved" |
| 29 |
) |
| 30 |
assert '"deepLinking": true,' in response.text, ( |
| 31 |
"default configs should be preserved" |
| 32 |
) |
| 33 |
assert '"showExtensions": true,' in response.text, ( |
| 34 |
"default configs should be preserved" |
| 35 |
) |
| 36 |
assert '"showCommonExtensions": true,' in response.text, ( |
| 37 |
"default configs should be preserved" |
| 38 |
) |
| 39 |
|
| 40 |
|
| 41 |
def test_get_users(): |
| 42 |
response = client.get("/users/foo") |
| 43 |
assert response.status_code == 200, response.text |
| 44 |
assert response.json() == {"message": "Hello foo"} |