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