Coverage for tests/test_param_in_path_and_dependency.py: 100%
16 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 import Depends, FastAPI 1abcde
2from fastapi.testclient import TestClient 1abcde
4app = FastAPI() 1abcde
7async def user_exists(user_id: int): 1abcde
8 return True 1abcde
11@app.get("/users/{user_id}", dependencies=[Depends(user_exists)]) 1abcde
12async def read_users(user_id: int): 1abcde
13 pass 1abcde
16client = TestClient(app) 1abcde
19def test_read_users(): 1abcde
20 response = client.get("/users/42") 1abcde
21 assert response.status_code == 200, response.text 1abcde
24def test_openapi_schema(): 1abcde
25 response = client.get("/openapi.json") 1abcde
26 data = response.json() 1abcde
27 assert data == { 1abcde
28 "openapi": "3.1.0",
29 "info": {"title": "FastAPI", "version": "0.1.0"},
30 "paths": {
31 "/users/{user_id}": {
32 "get": {
33 "summary": "Read Users",
34 "operationId": "read_users_users__user_id__get",
35 "parameters": [
36 {
37 "required": True,
38 "schema": {"title": "User Id", "type": "integer"},
39 "name": "user_id",
40 "in": "path",
41 },
42 ],
43 "responses": {
44 "200": {
45 "description": "Successful Response",
46 "content": {"application/json": {"schema": {}}},
47 },
48 "422": {
49 "description": "Validation Error",
50 "content": {
51 "application/json": {
52 "schema": {
53 "$ref": "#/components/schemas/HTTPValidationError"
54 }
55 }
56 },
57 },
58 },
59 }
60 }
61 },
62 "components": {
63 "schemas": {
64 "HTTPValidationError": {
65 "title": "HTTPValidationError",
66 "type": "object",
67 "properties": {
68 "detail": {
69 "title": "Detail",
70 "type": "array",
71 "items": {"$ref": "#/components/schemas/ValidationError"},
72 }
73 },
74 },
75 "ValidationError": {
76 "title": "ValidationError",
77 "required": ["loc", "msg", "type"],
78 "type": "object",
79 "properties": {
80 "loc": {
81 "title": "Location",
82 "type": "array",
83 "items": {
84 "anyOf": [{"type": "string"}, {"type": "integer"}]
85 },
86 },
87 "msg": {"title": "Message", "type": "string"},
88 "type": {"title": "Error Type", "type": "string"},
89 },
90 },
91 }
92 },
93 }