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