Coverage for tests / test_tutorial / test_query_params_str_validations / test_tutorial014.py: 100%
22 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1import importlib 1abdc
3import pytest 1abdc
4from fastapi.testclient import TestClient 1abdc
5from inline_snapshot import snapshot 1abdc
7from ...utils import needs_py310 1abdc
10@pytest.fixture( 1abdc
11 name="client",
12 params=[
13 pytest.param("tutorial014_py310", marks=needs_py310),
14 pytest.param("tutorial014_an_py310", marks=needs_py310),
15 ],
16)
17def get_client(request: pytest.FixtureRequest): 1abdc
18 mod = importlib.import_module( 1abc
19 f"docs_src.query_params_str_validations.{request.param}"
20 )
22 client = TestClient(mod.app) 1abc
23 return client 1abc
26def test_hidden_query(client: TestClient): 1abdc
27 response = client.get("/items?hidden_query=somevalue") 1efg
28 assert response.status_code == 200, response.text 1efg
29 assert response.json() == {"hidden_query": "somevalue"} 1efg
32def test_no_hidden_query(client: TestClient): 1abdc
33 response = client.get("/items") 1hij
34 assert response.status_code == 200, response.text 1hij
35 assert response.json() == {"hidden_query": "Not found"} 1hij
38def test_openapi_schema(client: TestClient): 1abdc
39 response = client.get("/openapi.json") 1klm
40 assert response.status_code == 200, response.text 1klm
41 assert response.json() == snapshot( 1klm
42 {
43 "openapi": "3.1.0",
44 "info": {"title": "FastAPI", "version": "0.1.0"},
45 "paths": {
46 "/items/": {
47 "get": {
48 "summary": "Read Items",
49 "operationId": "read_items_items__get",
50 "responses": {
51 "200": {
52 "description": "Successful Response",
53 "content": {"application/json": {"schema": {}}},
54 },
55 "422": {
56 "description": "Validation Error",
57 "content": {
58 "application/json": {
59 "schema": {
60 "$ref": "#/components/schemas/HTTPValidationError"
61 }
62 }
63 },
64 },
65 },
66 }
67 }
68 },
69 "components": {
70 "schemas": {
71 "HTTPValidationError": {
72 "title": "HTTPValidationError",
73 "type": "object",
74 "properties": {
75 "detail": {
76 "title": "Detail",
77 "type": "array",
78 "items": {
79 "$ref": "#/components/schemas/ValidationError"
80 },
81 }
82 },
83 },
84 "ValidationError": {
85 "title": "ValidationError",
86 "required": ["loc", "msg", "type"],
87 "type": "object",
88 "properties": {
89 "loc": {
90 "title": "Location",
91 "type": "array",
92 "items": {
93 "anyOf": [{"type": "string"}, {"type": "integer"}]
94 },
95 },
96 "msg": {"title": "Message", "type": "string"},
97 "type": {"title": "Error Type", "type": "string"},
98 "input": {"title": "Input"},
99 "ctx": {"title": "Context", "type": "object"},
100 },
101 },
102 }
103 },
104 }
105 )