Coverage for tests/test_tutorial/test_query_params_str_validations/test_tutorial014_an.py: 100%
15 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.tutorial014_an import app 1abcde
5client = TestClient(app) 1abcde
8def test_hidden_query(): 1abcde
9 response = client.get("/items?hidden_query=somevalue") 1abcde
10 assert response.status_code == 200, response.text 1abcde
11 assert response.json() == {"hidden_query": "somevalue"} 1abcde
14def test_no_hidden_query(): 1abcde
15 response = client.get("/items") 1abcde
16 assert response.status_code == 200, response.text 1abcde
17 assert response.json() == {"hidden_query": "Not found"} 1abcde
20def test_openapi_schema(): 1abcde
21 response = client.get("/openapi.json") 1abcde
22 assert response.status_code == 200, response.text 1abcde
23 assert response.json() == { 1abcde
24 "openapi": "3.1.0",
25 "info": {"title": "FastAPI", "version": "0.1.0"},
26 "paths": {
27 "/items/": {
28 "get": {
29 "summary": "Read Items",
30 "operationId": "read_items_items__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 }
48 }
49 },
50 "components": {
51 "schemas": {
52 "HTTPValidationError": {
53 "title": "HTTPValidationError",
54 "type": "object",
55 "properties": {
56 "detail": {
57 "title": "Detail",
58 "type": "array",
59 "items": {"$ref": "#/components/schemas/ValidationError"},
60 }
61 },
62 },
63 "ValidationError": {
64 "title": "ValidationError",
65 "required": ["loc", "msg", "type"],
66 "type": "object",
67 "properties": {
68 "loc": {
69 "title": "Location",
70 "type": "array",
71 "items": {
72 "anyOf": [{"type": "string"}, {"type": "integer"}]
73 },
74 },
75 "msg": {"title": "Message", "type": "string"},
76 "type": {"title": "Error Type", "type": "string"},
77 },
78 },
79 }
80 },
81 }