Coverage for tests/test_tutorial/test_query_params_str_validations/test_tutorial013_an_py39.py: 100%
25 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 1eabcd
2from fastapi.testclient import TestClient 1eabcd
4from ...utils import needs_py39 1eabcd
7@pytest.fixture(name="client") 1eabcd
8def get_client(): 1eabcd
9 from docs_src.query_params_str_validations.tutorial013_an_py39 import app 1abcd
11 client = TestClient(app) 1abcd
12 return client 1abcd
15@needs_py39 1eabcd
16def test_multi_query_values(client: TestClient): 1eabcd
17 url = "/items/?q=foo&q=bar" 1abcd
18 response = client.get(url) 1abcd
19 assert response.status_code == 200, response.text 1abcd
20 assert response.json() == {"q": ["foo", "bar"]} 1abcd
23@needs_py39 1eabcd
24def test_query_no_values(client: TestClient): 1eabcd
25 url = "/items/" 1abcd
26 response = client.get(url) 1abcd
27 assert response.status_code == 200, response.text 1abcd
28 assert response.json() == {"q": []} 1abcd
31@needs_py39 1eabcd
32def test_openapi_schema(client: TestClient): 1eabcd
33 response = client.get("/openapi.json") 1abcd
34 assert response.status_code == 200, response.text 1abcd
35 assert response.json() == { 1abcd
36 "openapi": "3.1.0",
37 "info": {"title": "FastAPI", "version": "0.1.0"},
38 "paths": {
39 "/items/": {
40 "get": {
41 "responses": {
42 "200": {
43 "description": "Successful Response",
44 "content": {"application/json": {"schema": {}}},
45 },
46 "422": {
47 "description": "Validation Error",
48 "content": {
49 "application/json": {
50 "schema": {
51 "$ref": "#/components/schemas/HTTPValidationError"
52 }
53 }
54 },
55 },
56 },
57 "summary": "Read Items",
58 "operationId": "read_items_items__get",
59 "parameters": [
60 {
61 "required": False,
62 "schema": {
63 "title": "Q",
64 "type": "array",
65 "items": {},
66 "default": [],
67 },
68 "name": "q",
69 "in": "query",
70 }
71 ],
72 }
73 }
74 },
75 "components": {
76 "schemas": {
77 "ValidationError": {
78 "title": "ValidationError",
79 "required": ["loc", "msg", "type"],
80 "type": "object",
81 "properties": {
82 "loc": {
83 "title": "Location",
84 "type": "array",
85 "items": {
86 "anyOf": [{"type": "string"}, {"type": "integer"}]
87 },
88 },
89 "msg": {"title": "Message", "type": "string"},
90 "type": {"title": "Error Type", "type": "string"},
91 },
92 },
93 "HTTPValidationError": {
94 "title": "HTTPValidationError",
95 "type": "object",
96 "properties": {
97 "detail": {
98 "title": "Detail",
99 "type": "array",
100 "items": {"$ref": "#/components/schemas/ValidationError"},
101 }
102 },
103 },
104 }
105 },
106 }