Coverage for tests/test_tutorial/test_response_model/test_tutorial003_05_py310.py: 100%
23 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
1import pytest 1deabc
2from fastapi.testclient import TestClient 1deabc
4from ...utils import needs_py310 1deabc
7@pytest.fixture(name="client") 1deabc
8def get_client(): 1deabc
9 from docs_src.response_model.tutorial003_05_py310 import app 1abc
11 client = TestClient(app) 1abc
12 return client 1abc
15@needs_py310 1deabc
16def test_get_portal(client: TestClient): 1deabc
17 response = client.get("/portal") 1abc
18 assert response.status_code == 200, response.text 1abc
19 assert response.json() == {"message": "Here's your interdimensional portal."} 1abc
22@needs_py310 1deabc
23def test_get_redirect(client: TestClient): 1deabc
24 response = client.get("/portal", params={"teleport": True}, follow_redirects=False) 1abc
25 assert response.status_code == 307, response.text 1abc
26 assert response.headers["location"] == "https://www.youtube.com/watch?v=dQw4w9WgXcQ" 1abc
29@needs_py310 1deabc
30def test_openapi_schema(client: TestClient): 1deabc
31 response = client.get("/openapi.json") 1abc
32 assert response.status_code == 200, response.text 1abc
33 assert response.json() == { 1abc
34 "openapi": "3.1.0",
35 "info": {"title": "FastAPI", "version": "0.1.0"},
36 "paths": {
37 "/portal": {
38 "get": {
39 "summary": "Get Portal",
40 "operationId": "get_portal_portal_get",
41 "parameters": [
42 {
43 "required": False,
44 "schema": {
45 "title": "Teleport",
46 "type": "boolean",
47 "default": False,
48 },
49 "name": "teleport",
50 "in": "query",
51 }
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 "title": "HTTPValidationError",
76 "type": "object",
77 "properties": {
78 "detail": {
79 "title": "Detail",
80 "type": "array",
81 "items": {"$ref": "#/components/schemas/ValidationError"},
82 }
83 },
84 },
85 "ValidationError": {
86 "title": "ValidationError",
87 "required": ["loc", "msg", "type"],
88 "type": "object",
89 "properties": {
90 "loc": {
91 "title": "Location",
92 "type": "array",
93 "items": {
94 "anyOf": [{"type": "string"}, {"type": "integer"}]
95 },
96 },
97 "msg": {"title": "Message", "type": "string"},
98 "type": {"title": "Error Type", "type": "string"},
99 },
100 },
101 }
102 },
103 }