Coverage for tests / test_tutorial / test_response_model / test_tutorial003_02.py: 100%
16 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.response_model.tutorial003_02_py310 import app 1abcd
6client = TestClient(app) 1abcd
9def test_get_portal(): 1abcd
10 response = client.get("/portal") 1efg
11 assert response.status_code == 200, response.text 1efg
12 assert response.json() == {"message": "Here's your interdimensional portal."} 1efg
15def test_get_redirect(): 1abcd
16 response = client.get("/portal", params={"teleport": True}, follow_redirects=False) 1hij
17 assert response.status_code == 307, response.text 1hij
18 assert response.headers["location"] == "https://www.youtube.com/watch?v=dQw4w9WgXcQ" 1hij
21def test_openapi_schema(): 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 "/portal": {
30 "get": {
31 "summary": "Get Portal",
32 "operationId": "get_portal_portal_get",
33 "parameters": [
34 {
35 "required": False,
36 "schema": {
37 "title": "Teleport",
38 "type": "boolean",
39 "default": False,
40 },
41 "name": "teleport",
42 "in": "query",
43 }
44 ],
45 "responses": {
46 "200": {
47 "description": "Successful Response",
48 "content": {"application/json": {"schema": {}}},
49 },
50 "422": {
51 "description": "Validation Error",
52 "content": {
53 "application/json": {
54 "schema": {
55 "$ref": "#/components/schemas/HTTPValidationError"
56 }
57 }
58 },
59 },
60 },
61 }
62 }
63 },
64 "components": {
65 "schemas": {
66 "HTTPValidationError": {
67 "title": "HTTPValidationError",
68 "type": "object",
69 "properties": {
70 "detail": {
71 "title": "Detail",
72 "type": "array",
73 "items": {
74 "$ref": "#/components/schemas/ValidationError"
75 },
76 }
77 },
78 },
79 "ValidationError": {
80 "title": "ValidationError",
81 "required": ["loc", "msg", "type"],
82 "type": "object",
83 "properties": {
84 "loc": {
85 "title": "Location",
86 "type": "array",
87 "items": {
88 "anyOf": [{"type": "string"}, {"type": "integer"}]
89 },
90 },
91 "msg": {"title": "Message", "type": "string"},
92 "type": {"title": "Error Type", "type": "string"},
93 "input": {"title": "Input"},
94 "ctx": {"title": "Context", "type": "object"},
95 },
96 },
97 }
98 },
99 }
100 )