Coverage for tests / test_tutorial / test_sub_applications / test_tutorial001.py: 100%

20 statements  

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

1from fastapi.testclient import TestClient 1abcd

2from inline_snapshot import snapshot 1abcd

3 

4from docs_src.sub_applications.tutorial001_py310 import app 1abcd

5 

6client = TestClient(app) 1abcd

7 

8 

9def test_main(): 1abcd

10 response = client.get("/app") 1efg

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

12 assert response.json() == {"message": "Hello World from main app"} 1efg

13 

14 

15def test_sub(): 1abcd

16 response = client.get("/subapi/sub") 1hij

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

18 assert response.json() == {"message": "Hello World from sub API"} 1hij

19 

20 

21def test_openapi_schema_main(): 1abcd

22 response = client.get("/openapi.json") 1klm

23 assert response.status_code == 200, response.text 1klm

24 assert response.json() == snapshot( 1klm

25 { 

26 "openapi": "3.1.0", 

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

28 "paths": { 

29 "/app": { 

30 "get": { 

31 "responses": { 

32 "200": { 

33 "description": "Successful Response", 

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

35 } 

36 }, 

37 "summary": "Read Main", 

38 "operationId": "read_main_app_get", 

39 } 

40 } 

41 }, 

42 } 

43 ) 

44 

45 

46def test_openapi_schema_sub(): 1abcd

47 response = client.get("/subapi/openapi.json") 1nop

48 assert response.status_code == 200, response.text 1nop

49 assert response.json() == snapshot( 1nop

50 { 

51 "openapi": "3.1.0", 

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

53 "paths": { 

54 "/sub": { 

55 "get": { 

56 "responses": { 

57 "200": { 

58 "description": "Successful Response", 

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

60 } 

61 }, 

62 "summary": "Read Sub", 

63 "operationId": "read_sub_sub_get", 

64 } 

65 } 

66 }, 

67 "servers": [{"url": "/subapi"}], 

68 } 

69 )