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