Coverage for tests / test_tutorial / test_openapi_webhooks / test_tutorial001.py: 100%
14 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« 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
4from docs_src.openapi_webhooks.tutorial001_py310 import app 1abcd
6client = TestClient(app) 1abcd
9def test_get(): 1abcd
10 response = client.get("/users/") 1efg
11 assert response.status_code == 200, response.text 1efg
12 assert response.json() == ["Rick", "Morty"] 1efg
15def test_dummy_webhook(): 1abcd
16 # Just for coverage
17 app.webhooks.routes[0].endpoint({}) 1klm
20def test_openapi_schema(): 1abcd
21 response = client.get("/openapi.json") 1hij
22 assert response.status_code == 200, response.text 1hij
23 assert response.json() == snapshot( 1hij
24 {
25 "openapi": "3.1.0",
26 "info": {"title": "FastAPI", "version": "0.1.0"},
27 "paths": {
28 "/users/": {
29 "get": {
30 "summary": "Read Users",
31 "operationId": "read_users_users__get",
32 "responses": {
33 "200": {
34 "description": "Successful Response",
35 "content": {"application/json": {"schema": {}}},
36 }
37 },
38 }
39 }
40 },
41 "webhooks": {
42 "new-subscription": {
43 "post": {
44 "summary": "New Subscription",
45 "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.",
46 "operationId": "new_subscriptionnew_subscription_post",
47 "requestBody": {
48 "content": {
49 "application/json": {
50 "schema": {
51 "$ref": "#/components/schemas/Subscription"
52 }
53 }
54 },
55 "required": True,
56 },
57 "responses": {
58 "200": {
59 "description": "Successful Response",
60 "content": {"application/json": {"schema": {}}},
61 },
62 "422": {
63 "description": "Validation Error",
64 "content": {
65 "application/json": {
66 "schema": {
67 "$ref": "#/components/schemas/HTTPValidationError"
68 }
69 }
70 },
71 },
72 },
73 }
74 }
75 },
76 "components": {
77 "schemas": {
78 "HTTPValidationError": {
79 "properties": {
80 "detail": {
81 "items": {
82 "$ref": "#/components/schemas/ValidationError"
83 },
84 "type": "array",
85 "title": "Detail",
86 }
87 },
88 "type": "object",
89 "title": "HTTPValidationError",
90 },
91 "Subscription": {
92 "properties": {
93 "username": {"type": "string", "title": "Username"},
94 "monthly_fee": {"type": "number", "title": "Monthly Fee"},
95 "start_date": {
96 "type": "string",
97 "format": "date-time",
98 "title": "Start Date",
99 },
100 },
101 "type": "object",
102 "required": ["username", "monthly_fee", "start_date"],
103 "title": "Subscription",
104 },
105 "ValidationError": {
106 "properties": {
107 "ctx": {"title": "Context", "type": "object"},
108 "input": {"title": "Input"},
109 "loc": {
110 "items": {
111 "anyOf": [{"type": "string"}, {"type": "integer"}]
112 },
113 "type": "array",
114 "title": "Location",
115 },
116 "msg": {"type": "string", "title": "Message"},
117 "type": {"type": "string", "title": "Error Type"},
118 },
119 "type": "object",
120 "required": ["loc", "msg", "type"],
121 "title": "ValidationError",
122 },
123 }
124 },
125 }
126 )