Coverage for tests / test_deprecated_openapi_prefix.py: 100%
16 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1from fastapi import FastAPI, Request 1abcd
2from fastapi.testclient import TestClient 1abcd
3from inline_snapshot import snapshot 1abcd
5app = FastAPI(openapi_prefix="/api/v1") 1abcd
8@app.get("/app") 1abcd
9def read_main(request: Request): 1abcd
10 return {"message": "Hello World", "root_path": request.scope.get("root_path")} 1efg
13client = TestClient(app) 1abcd
16def test_main(): 1abcd
17 response = client.get("/app") 1efg
18 assert response.status_code == 200 1efg
19 assert response.json() == {"message": "Hello World", "root_path": "/api/v1"} 1efg
22def test_openapi(): 1abcd
23 response = client.get("/openapi.json") 1hij
24 assert response.status_code == 200 1hij
25 assert response.json() == snapshot( 1hij
26 {
27 "openapi": "3.1.0",
28 "info": {"title": "FastAPI", "version": "0.1.0"},
29 "paths": {
30 "/app": {
31 "get": {
32 "summary": "Read Main",
33 "operationId": "read_main_app_get",
34 "responses": {
35 "200": {
36 "description": "Successful Response",
37 "content": {"application/json": {"schema": {}}},
38 }
39 },
40 }
41 }
42 },
43 "servers": [{"url": "/api/v1"}],
44 }
45 )