Coverage for tests/main.py: 100%
124 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
1import http 1abcde
2from typing import FrozenSet, List, Optional 1abcde
4from fastapi import FastAPI, Path, Query 1abcde
6app = FastAPI() 1abcde
9@app.api_route("/api_route") 1abcde
10def non_operation(): 1abcde
11 return {"message": "Hello World"} 1abcde
14def non_decorated_route(): 1abcde
15 return {"message": "Hello World"} 1abcde
18app.add_api_route("/non_decorated_route", non_decorated_route) 1abcde
21@app.get("/text") 1abcde
22def get_text(): 1abcde
23 return "Hello World" 1abcde
26@app.get("/path/{item_id}") 1abcde
27def get_id(item_id): 1abcde
28 return item_id 1abcde
31@app.get("/path/str/{item_id}") 1abcde
32def get_str_id(item_id: str): 1abcde
33 return item_id 1abcde
36@app.get("/path/int/{item_id}") 1abcde
37def get_int_id(item_id: int): 1abcde
38 return item_id 1abcde
41@app.get("/path/float/{item_id}") 1abcde
42def get_float_id(item_id: float): 1abcde
43 return item_id 1abcde
46@app.get("/path/bool/{item_id}") 1abcde
47def get_bool_id(item_id: bool): 1abcde
48 return item_id 1abcde
51@app.get("/path/param/{item_id}") 1abcde
52def get_path_param_id(item_id: Optional[str] = Path()): 1abcde
53 return item_id 1abcde
56@app.get("/path/param-minlength/{item_id}") 1abcde
57def get_path_param_min_length(item_id: str = Path(min_length=3)): 1abcde
58 return item_id 1abcde
61@app.get("/path/param-maxlength/{item_id}") 1abcde
62def get_path_param_max_length(item_id: str = Path(max_length=3)): 1abcde
63 return item_id 1abcde
66@app.get("/path/param-min_maxlength/{item_id}") 1abcde
67def get_path_param_min_max_length(item_id: str = Path(max_length=3, min_length=2)): 1abcde
68 return item_id 1abcde
71@app.get("/path/param-gt/{item_id}") 1abcde
72def get_path_param_gt(item_id: float = Path(gt=3)): 1abcde
73 return item_id 1abcde
76@app.get("/path/param-gt0/{item_id}") 1abcde
77def get_path_param_gt0(item_id: float = Path(gt=0)): 1abcde
78 return item_id 1abcde
81@app.get("/path/param-ge/{item_id}") 1abcde
82def get_path_param_ge(item_id: float = Path(ge=3)): 1abcde
83 return item_id 1abcde
86@app.get("/path/param-lt/{item_id}") 1abcde
87def get_path_param_lt(item_id: float = Path(lt=3)): 1abcde
88 return item_id 1abcde
91@app.get("/path/param-lt0/{item_id}") 1abcde
92def get_path_param_lt0(item_id: float = Path(lt=0)): 1abcde
93 return item_id 1abcde
96@app.get("/path/param-le/{item_id}") 1abcde
97def get_path_param_le(item_id: float = Path(le=3)): 1abcde
98 return item_id 1abcde
101@app.get("/path/param-lt-gt/{item_id}") 1abcde
102def get_path_param_lt_gt(item_id: float = Path(lt=3, gt=1)): 1abcde
103 return item_id 1abcde
106@app.get("/path/param-le-ge/{item_id}") 1abcde
107def get_path_param_le_ge(item_id: float = Path(le=3, ge=1)): 1abcde
108 return item_id 1abcde
111@app.get("/path/param-lt-int/{item_id}") 1abcde
112def get_path_param_lt_int(item_id: int = Path(lt=3)): 1abcde
113 return item_id 1abcde
116@app.get("/path/param-gt-int/{item_id}") 1abcde
117def get_path_param_gt_int(item_id: int = Path(gt=3)): 1abcde
118 return item_id 1abcde
121@app.get("/path/param-le-int/{item_id}") 1abcde
122def get_path_param_le_int(item_id: int = Path(le=3)): 1abcde
123 return item_id 1abcde
126@app.get("/path/param-ge-int/{item_id}") 1abcde
127def get_path_param_ge_int(item_id: int = Path(ge=3)): 1abcde
128 return item_id 1abcde
131@app.get("/path/param-lt-gt-int/{item_id}") 1abcde
132def get_path_param_lt_gt_int(item_id: int = Path(lt=3, gt=1)): 1abcde
133 return item_id 1abcde
136@app.get("/path/param-le-ge-int/{item_id}") 1abcde
137def get_path_param_le_ge_int(item_id: int = Path(le=3, ge=1)): 1abcde
138 return item_id 1abcde
141@app.get("/query") 1abcde
142def get_query(query): 1abcde
143 return f"foo bar {query}" 1abcde
146@app.get("/query/optional") 1abcde
147def get_query_optional(query=None): 1abcde
148 if query is None: 1abcde
149 return "foo bar" 1abcde
150 return f"foo bar {query}" 1abcde
153@app.get("/query/int") 1abcde
154def get_query_type(query: int): 1abcde
155 return f"foo bar {query}" 1abcde
158@app.get("/query/int/optional") 1abcde
159def get_query_type_optional(query: Optional[int] = None): 1abcde
160 if query is None: 1abcde
161 return "foo bar" 1abcde
162 return f"foo bar {query}" 1abcde
165@app.get("/query/int/default") 1abcde
166def get_query_type_int_default(query: int = 10): 1abcde
167 return f"foo bar {query}" 1abcde
170@app.get("/query/param") 1abcde
171def get_query_param(query=Query(default=None)): 1abcde
172 if query is None: 1abcde
173 return "foo bar" 1abcde
174 return f"foo bar {query}" 1abcde
177@app.get("/query/param-required") 1abcde
178def get_query_param_required(query=Query()): 1abcde
179 return f"foo bar {query}" 1abcde
182@app.get("/query/param-required/int") 1abcde
183def get_query_param_required_type(query: int = Query()): 1abcde
184 return f"foo bar {query}" 1abcde
187@app.get("/enum-status-code", status_code=http.HTTPStatus.CREATED) 1abcde
188def get_enum_status_code(): 1abcde
189 return "foo bar" 1abcde
192@app.get("/query/frozenset") 1abcde
193def get_query_type_frozenset(query: FrozenSet[int] = Query(...)): 1abcde
194 return ",".join(map(str, sorted(query))) 1abcde
197@app.get("/query/list") 1abcde
198def get_query_list(device_ids: List[int] = Query()) -> List[int]: 1abcde
199 return device_ids 1abcde
202@app.get("/query/list-default") 1abcde
203def get_query_list_default(device_ids: List[int] = Query(default=[])) -> List[int]: 1abcde
204 return device_ids 1abcde