| 1 |
from fastapi.testclient import TestClient |
| 2 |
from inline_snapshot import snapshot |
| 3 |
|
| 4 |
from docs_src.custom_response.tutorial006c_py310 import app |
| 5 |
|
| 6 |
client = TestClient(app) |
| 7 |
|
| 8 |
|
| 9 |
def test_redirect_status_code(): |
| 10 |
response = client.get("/pydantic", follow_redirects=False) |
| 11 |
assert response.status_code == 302 |
| 12 |
assert response.headers["location"] == "https://docs.pydantic.dev/" |
| 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": {"title": "FastAPI", "version": "0.1.0"}, |
| 22 |
"paths": { |
| 23 |
"/pydantic": { |
| 24 |
"get": { |
| 25 |
"summary": "Redirect Pydantic", |
| 26 |
"operationId": "redirect_pydantic_pydantic_get", |
| 27 |
"responses": {"302": {"description": "Successful Response"}}, |
| 28 |
} |
| 29 |
} |
| 30 |
}, |
| 31 |
} |
| 32 |
) |