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

21 statements  

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

1from fastapi.testclient import TestClient 1abcde

2 

3from docs_src.sub_applications.tutorial001 import app 1abcde

4 

5client = TestClient(app) 1abcde

6 

7openapi_schema_main = { 1abcde

8 "openapi": "3.1.0", 

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

10 "paths": { 

11 "/app": { 

12 "get": { 

13 "responses": { 

14 "200": { 

15 "description": "Successful Response", 

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

17 } 

18 }, 

19 "summary": "Read Main", 

20 "operationId": "read_main_app_get", 

21 } 

22 } 

23 }, 

24} 

25openapi_schema_sub = { 1abcde

26 "openapi": "3.1.0", 

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

28 "paths": { 

29 "/sub": { 

30 "get": { 

31 "responses": { 

32 "200": { 

33 "description": "Successful Response", 

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

35 } 

36 }, 

37 "summary": "Read Sub", 

38 "operationId": "read_sub_sub_get", 

39 } 

40 } 

41 }, 

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

43} 

44 

45 

46def test_openapi_schema_main(): 1abcde

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

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

49 assert response.json() == openapi_schema_main 1abcde

50 

51 

52def test_main(): 1abcde

53 response = client.get("/app") 1abcde

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

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

56 

57 

58def test_openapi_schema_sub(): 1abcde

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

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

61 assert response.json() == openapi_schema_sub 1abcde

62 

63 

64def test_sub(): 1abcde

65 response = client.get("/subapi/sub") 1abcde

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

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