Coverage for tests/test_additional_response_extra.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1from fastapi import APIRouter, FastAPI 1abcde

2from fastapi.testclient import TestClient 1abcde

3 

4router = APIRouter() 1abcde

5 

6sub_router = APIRouter() 1abcde

7 

8app = FastAPI() 1abcde

9 

10 

11@sub_router.get("/") 1abcde

12def read_item(): 1abcde

13 return {"id": "foo"} 1abcde

14 

15 

16router.include_router(sub_router, prefix="/items") 1abcde

17 

18app.include_router(router) 1abcde

19 

20client = TestClient(app) 1abcde

21 

22 

23def test_path_operation(): 1abcde

24 response = client.get("/items/") 1abcde

25 assert response.status_code == 200, response.text 1abcde

26 assert response.json() == {"id": "foo"} 1abcde

27 

28 

29def test_openapi_schema(): 1abcde

30 response = client.get("/openapi.json") 1abcde

31 assert response.status_code == 200, response.text 1abcde

32 assert response.json() == { 1abcde

33 "openapi": "3.1.0", 

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

35 "paths": { 

36 "/items/": { 

37 "get": { 

38 "responses": { 

39 "200": { 

40 "description": "Successful Response", 

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

42 } 

43 }, 

44 "summary": "Read Item", 

45 "operationId": "read_item_items__get", 

46 } 

47 } 

48 }, 

49 }