Coverage for tests / test_additional_response_extra.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1from fastapi import APIRouter, FastAPI 1abcd

2from fastapi.testclient import TestClient 1abcd

3from inline_snapshot import snapshot 1abcd

4 

5router = APIRouter() 1abcd

6 

7sub_router = APIRouter() 1abcd

8 

9app = FastAPI() 1abcd

10 

11 

12@sub_router.get("/") 1abcd

13def read_item(): 1abcd

14 return {"id": "foo"} 1efg

15 

16 

17router.include_router(sub_router, prefix="/items") 1abcd

18 

19app.include_router(router) 1abcd

20 

21client = TestClient(app) 1abcd

22 

23 

24def test_path_operation(): 1abcd

25 response = client.get("/items/") 1efg

26 assert response.status_code == 200, response.text 1efg

27 assert response.json() == {"id": "foo"} 1efg

28 

29 

30def test_openapi_schema(): 1abcd

31 response = client.get("/openapi.json") 1hij

32 assert response.status_code == 200, response.text 1hij

33 assert response.json() == snapshot( 1hij

34 { 

35 "openapi": "3.1.0", 

36 "info": {"title": "FastAPI", "version": "0.1.0"}, 

37 "paths": { 

38 "/items/": { 

39 "get": { 

40 "responses": { 

41 "200": { 

42 "description": "Successful Response", 

43 "content": {"application/json": {"schema": {}}}, 

44 } 

45 }, 

46 "summary": "Read Item", 

47 "operationId": "read_item_items__get", 

48 } 

49 } 

50 }, 

51 } 

52 )