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

13 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.openapi_webhooks.tutorial001 import app 1abcde

4 

5client = TestClient(app) 1abcde

6 

7 

8def test_get(): 1abcde

9 response = client.get("/users/") 1abcde

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

11 assert response.json() == ["Rick", "Morty"] 1abcde

12 

13 

14def test_dummy_webhook(): 1abcde

15 # Just for coverage 

16 app.webhooks.routes[0].endpoint({}) 1abcde

17 

18 

19def test_openapi_schema(): 1abcde

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

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

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

23 "openapi": "3.1.0", 

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

25 "paths": { 

26 "/users/": { 

27 "get": { 

28 "summary": "Read Users", 

29 "operationId": "read_users_users__get", 

30 "responses": { 

31 "200": { 

32 "description": "Successful Response", 

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

34 } 

35 }, 

36 } 

37 } 

38 }, 

39 "webhooks": { 

40 "new-subscription": { 

41 "post": { 

42 "summary": "New Subscription", 

43 "description": "When a new user subscribes to your service we'll send you a POST request with this\ndata to the URL that you register for the event `new-subscription` in the dashboard.", 

44 "operationId": "new_subscriptionnew_subscription_post", 

45 "requestBody": { 

46 "content": { 

47 "application/json": { 

48 "schema": {"$ref": "#/components/schemas/Subscription"} 

49 } 

50 }, 

51 "required": True, 

52 }, 

53 "responses": { 

54 "200": { 

55 "description": "Successful Response", 

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

57 }, 

58 "422": { 

59 "description": "Validation Error", 

60 "content": { 

61 "application/json": { 

62 "schema": { 

63 "$ref": "#/components/schemas/HTTPValidationError" 

64 } 

65 } 

66 }, 

67 }, 

68 }, 

69 } 

70 } 

71 }, 

72 "components": { 

73 "schemas": { 

74 "HTTPValidationError": { 

75 "properties": { 

76 "detail": { 

77 "items": {"$ref": "#/components/schemas/ValidationError"}, 

78 "type": "array", 

79 "title": "Detail", 

80 } 

81 }, 

82 "type": "object", 

83 "title": "HTTPValidationError", 

84 }, 

85 "Subscription": { 

86 "properties": { 

87 "username": {"type": "string", "title": "Username"}, 

88 "monthly_fee": {"type": "number", "title": "Monthly Fee"}, 

89 "start_date": { 

90 "type": "string", 

91 "format": "date-time", 

92 "title": "Start Date", 

93 }, 

94 }, 

95 "type": "object", 

96 "required": ["username", "monthly_fee", "start_date"], 

97 "title": "Subscription", 

98 }, 

99 "ValidationError": { 

100 "properties": { 

101 "loc": { 

102 "items": { 

103 "anyOf": [{"type": "string"}, {"type": "integer"}] 

104 }, 

105 "type": "array", 

106 "title": "Location", 

107 }, 

108 "msg": {"type": "string", "title": "Message"}, 

109 "type": {"type": "string", "title": "Error Type"}, 

110 }, 

111 "type": "object", 

112 "required": ["loc", "msg", "type"], 

113 "title": "ValidationError", 

114 }, 

115 } 

116 }, 

117 }