Coverage for tests / main.py: 100%

125 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1import http 1abcd

2from typing import Optional 1abcd

3 

4from fastapi import FastAPI, Path, Query 1abcd

5 

6external_docs = { 1abcd

7 "description": "External API documentation.", 

8 "url": "https://docs.example.com/api-general", 

9} 

10 

11app = FastAPI(openapi_external_docs=external_docs) 1abcd

12 

13 

14@app.api_route("/api_route") 1abcd

15def non_operation(): 1abcd

16 return {"message": "Hello World"} 1efg

17 

18 

19def non_decorated_route(): 1abcd

20 return {"message": "Hello World"} 1efg

21 

22 

23app.add_api_route("/non_decorated_route", non_decorated_route) 1abcd

24 

25 

26@app.get("/text") 1abcd

27def get_text(): 1abcd

28 return "Hello World" 1CDE

29 

30 

31@app.get("/path/{item_id}") 1abcd

32def get_id(item_id): 1abcd

33 return item_id 1FGH

34 

35 

36@app.get("/path/str/{item_id}") 1abcd

37def get_str_id(item_id: str): 1abcd

38 return item_id 1IJKLMNOPQ

39 

40 

41@app.get("/path/int/{item_id}") 1abcd

42def get_int_id(item_id: int): 1abcd

43 return item_id 1RST

44 

45 

46@app.get("/path/float/{item_id}") 1abcd

47def get_float_id(item_id: float): 1abcd

48 return item_id 1UVWXYZ

49 

50 

51@app.get("/path/bool/{item_id}") 1abcd

52def get_bool_id(item_id: bool): 1abcd

53 return item_id 10123456789!#$%'()*

54 

55 

56@app.get("/path/param/{item_id}") 1abcd

57def get_path_param_id(item_id: Optional[str] = Path()): 1abcd

58 return item_id 1+,-

59 

60 

61@app.get("/path/param-minlength/{item_id}") 1abcd

62def get_path_param_min_length(item_id: str = Path(min_length=3)): 1abcd

63 return item_id 1./:

64 

65 

66@app.get("/path/param-maxlength/{item_id}") 1abcd

67def get_path_param_max_length(item_id: str = Path(max_length=3)): 1abcd

68 return item_id 1;=?

69 

70 

71@app.get("/path/param-min_maxlength/{item_id}") 1abcd

72def get_path_param_min_max_length(item_id: str = Path(max_length=3, min_length=2)): 1abcd

73 return item_id 1@[]

74 

75 

76@app.get("/path/param-gt/{item_id}") 1abcd

77def get_path_param_gt(item_id: float = Path(gt=3)): 1abcd

78 return item_id 1^_`

79 

80 

81@app.get("/path/param-gt0/{item_id}") 1abcd

82def get_path_param_gt0(item_id: float = Path(gt=0)): 1abcd

83 return item_id 1{|}

84 

85 

86@app.get("/path/param-ge/{item_id}") 1abcd

87def get_path_param_ge(item_id: float = Path(ge=3)): 1abcd

88 return item_id 2~ abbbcbdbeb

89 

90 

91@app.get("/path/param-lt/{item_id}") 1abcd

92def get_path_param_lt(item_id: float = Path(lt=3)): 1abcd

93 return item_id 2fbgbhb

94 

95 

96@app.get("/path/param-lt0/{item_id}") 1abcd

97def get_path_param_lt0(item_id: float = Path(lt=0)): 1abcd

98 return item_id 2ibjbkb

99 

100 

101@app.get("/path/param-le/{item_id}") 1abcd

102def get_path_param_le(item_id: float = Path(le=3)): 1abcd

103 return item_id 2lbmbnbobpbqb

104 

105 

106@app.get("/path/param-lt-gt/{item_id}") 1abcd

107def get_path_param_lt_gt(item_id: float = Path(lt=3, gt=1)): 1abcd

108 return item_id 2rbsbtb

109 

110 

111@app.get("/path/param-le-ge/{item_id}") 1abcd

112def get_path_param_le_ge(item_id: float = Path(le=3, ge=1)): 1abcd

113 return item_id 2ubvbwbxbybzbAbBbCb

114 

115 

116@app.get("/path/param-lt-int/{item_id}") 1abcd

117def get_path_param_lt_int(item_id: int = Path(lt=3)): 1abcd

118 return item_id 2DbEbFb

119 

120 

121@app.get("/path/param-gt-int/{item_id}") 1abcd

122def get_path_param_gt_int(item_id: int = Path(gt=3)): 1abcd

123 return item_id 2GbHbIb

124 

125 

126@app.get("/path/param-le-int/{item_id}") 1abcd

127def get_path_param_le_int(item_id: int = Path(le=3)): 1abcd

128 return item_id 2JbKbLbMbNbOb

129 

130 

131@app.get("/path/param-ge-int/{item_id}") 1abcd

132def get_path_param_ge_int(item_id: int = Path(ge=3)): 1abcd

133 return item_id 2PbQbRbSbTbUb

134 

135 

136@app.get("/path/param-lt-gt-int/{item_id}") 1abcd

137def get_path_param_lt_gt_int(item_id: int = Path(lt=3, gt=1)): 1abcd

138 return item_id 2VbWbXb

139 

140 

141@app.get("/path/param-le-ge-int/{item_id}") 1abcd

142def get_path_param_le_ge_int(item_id: int = Path(le=3, ge=1)): 1abcd

143 return item_id 2YbZb0b1b2b3b4b5b6b

144 

145 

146@app.get("/query") 1abcd

147def get_query(query): 1abcd

148 return f"foo bar {query}" 27b8b9b

149 

150 

151@app.get("/query/optional") 1abcd

152def get_query_optional(query=None): 1abcd

153 if query is None: 1hijklmnop

154 return "foo bar" 1hiklno

155 return f"foo bar {query}" 1jmp

156 

157 

158@app.get("/query/int") 1abcd

159def get_query_type(query: int): 1abcd

160 return f"foo bar {query}" 2!b#b$b

161 

162 

163@app.get("/query/int/optional") 1abcd

164def get_query_type_optional(query: Optional[int] = None): 1abcd

165 if query is None: 1qrstuv

166 return "foo bar" 1qsu

167 return f"foo bar {query}" 1rtv

168 

169 

170@app.get("/query/int/default") 1abcd

171def get_query_type_int_default(query: int = 10): 1abcd

172 return f"foo bar {query}" 2%b'b(b)b*b+b

173 

174 

175@app.get("/query/param") 1abcd

176def get_query_param(query=Query(default=None)): 1abcd

177 if query is None: 1wxyzAB

178 return "foo bar" 1wyA

179 return f"foo bar {query}" 1xzB

180 

181 

182@app.get("/query/param-required") 1abcd

183def get_query_param_required(query=Query()): 1abcd

184 return f"foo bar {query}" 2,b-b.b

185 

186 

187@app.get("/query/param-required/int") 1abcd

188def get_query_param_required_type(query: int = Query()): 1abcd

189 return f"foo bar {query}" 2/b:b;b

190 

191 

192@app.get("/enum-status-code", status_code=http.HTTPStatus.CREATED) 1abcd

193def get_enum_status_code(): 1abcd

194 return "foo bar" 2=b?b@b

195 

196 

197@app.get("/query/frozenset") 1abcd

198def get_query_type_frozenset(query: frozenset[int] = Query(...)): 1abcd

199 return ",".join(map(str, sorted(query))) 2[b]b^b

200 

201 

202@app.get("/query/list") 1abcd

203def get_query_list(device_ids: list[int] = Query()) -> list[int]: 1abcd

204 return device_ids 2_b`b{b

205 

206 

207@app.get("/query/list-default") 1abcd

208def get_query_list_default(device_ids: list[int] = Query(default=[])) -> list[int]: 1abcd

209 return device_ids 2|b}b~bacbccc