Coverage for tests/test_tutorial/test_query_params_str_validations/test_tutorial011.py: 100%
18 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 dirty_equals import IsDict 1abcde
2from fastapi.testclient import TestClient 1abcde
4from docs_src.query_params_str_validations.tutorial011 import app 1abcde
6client = TestClient(app) 1abcde
9def test_multi_query_values(): 1abcde
10 url = "/items/?q=foo&q=bar" 1abcde
11 response = client.get(url) 1abcde
12 assert response.status_code == 200, response.text 1abcde
13 assert response.json() == {"q": ["foo", "bar"]} 1abcde
16def test_query_no_values(): 1abcde
17 url = "/items/" 1abcde
18 response = client.get(url) 1abcde
19 assert response.status_code == 200, response.text 1abcde
20 assert response.json() == {"q": None} 1abcde
23def test_openapi_schema(): 1abcde
24 response = client.get("/openapi.json") 1abcde
25 assert response.status_code == 200, response.text 1abcde
26 assert response.json() == { 1abcde
27 "openapi": "3.1.0",
28 "info": {"title": "FastAPI", "version": "0.1.0"},
29 "paths": {
30 "/items/": {
31 "get": {
32 "responses": {
33 "200": {
34 "description": "Successful Response",
35 "content": {"application/json": {"schema": {}}},
36 },
37 "422": {
38 "description": "Validation Error",
39 "content": {
40 "application/json": {
41 "schema": {
42 "$ref": "#/components/schemas/HTTPValidationError"
43 }
44 }
45 },
46 },
47 },
48 "summary": "Read Items",
49 "operationId": "read_items_items__get",
50 "parameters": [
51 {
52 "required": False,
53 "schema": IsDict(
54 {
55 "anyOf": [
56 {"type": "array", "items": {"type": "string"}},
57 {"type": "null"},
58 ],
59 "title": "Q",
60 }
61 )
62 | IsDict(
63 # TODO: remove when deprecating Pydantic v1
64 {
65 "title": "Q",
66 "type": "array",
67 "items": {"type": "string"},
68 }
69 ),
70 "name": "q",
71 "in": "query",
72 }
73 ],
74 }
75 }
76 },
77 "components": {
78 "schemas": {
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 },
94 },
95 "HTTPValidationError": {
96 "title": "HTTPValidationError",
97 "type": "object",
98 "properties": {
99 "detail": {
100 "title": "Detail",
101 "type": "array",
102 "items": {"$ref": "#/components/schemas/ValidationError"},
103 }
104 },
105 },
106 }
107 },
108 }