Coverage for tests/test_tutorial/test_response_model/test_tutorial003_05.py: 100%
15 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1from fastapi.testclient import TestClient 1abcde
3from docs_src.response_model.tutorial003_05 import app 1abcde
5client = TestClient(app) 1abcde
8def test_get_portal(): 1abcde
9 response = client.get("/portal") 1abcde
10 assert response.status_code == 200, response.text 1abcde
11 assert response.json() == {"message": "Here's your interdimensional portal."} 1abcde
14def test_get_redirect(): 1abcde
15 response = client.get("/portal", params={"teleport": True}, follow_redirects=False) 1abcde
16 assert response.status_code == 307, response.text 1abcde
17 assert response.headers["location"] == "https://www.youtube.com/watch?v=dQw4w9WgXcQ" 1abcde
20def test_openapi_schema(): 1abcde
21 response = client.get("/openapi.json") 1abcde
22 assert response.status_code == 200, response.text 1abcde
23 assert response.json() == { 1abcde
24 "openapi": "3.1.0",
25 "info": {"title": "FastAPI", "version": "0.1.0"},
26 "paths": {
27 "/portal": {
28 "get": {
29 "summary": "Get Portal",
30 "operationId": "get_portal_portal_get",
31 "parameters": [
32 {
33 "required": False,
34 "schema": {
35 "title": "Teleport",
36 "type": "boolean",
37 "default": False,
38 },
39 "name": "teleport",
40 "in": "query",
41 }
42 ],
43 "responses": {
44 "200": {
45 "description": "Successful Response",
46 "content": {"application/json": {"schema": {}}},
47 },
48 "422": {
49 "description": "Validation Error",
50 "content": {
51 "application/json": {
52 "schema": {
53 "$ref": "#/components/schemas/HTTPValidationError"
54 }
55 }
56 },
57 },
58 },
59 }
60 }
61 },
62 "components": {
63 "schemas": {
64 "HTTPValidationError": {
65 "title": "HTTPValidationError",
66 "type": "object",
67 "properties": {
68 "detail": {
69 "title": "Detail",
70 "type": "array",
71 "items": {"$ref": "#/components/schemas/ValidationError"},
72 }
73 },
74 },
75 "ValidationError": {
76 "title": "ValidationError",
77 "required": ["loc", "msg", "type"],
78 "type": "object",
79 "properties": {
80 "loc": {
81 "title": "Location",
82 "type": "array",
83 "items": {
84 "anyOf": [{"type": "string"}, {"type": "integer"}]
85 },
86 },
87 "msg": {"title": "Message", "type": "string"},
88 "type": {"title": "Error Type", "type": "string"},
89 },
90 },
91 }
92 },
93 }