Coverage for tests / main.py: 100%

124 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-04-06 01:24 +0000

1import http 1abcd

2 

3from fastapi import FastAPI, Path, Query 1abcd

4 

5external_docs = { 1abcd

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

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

8} 

9 

10app = FastAPI(openapi_external_docs=external_docs) 1abcd

11 

12 

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

14def non_operation(): 1abcd

15 return {"message": "Hello World"} 1FGHI

16 

17 

18def non_decorated_route(): 1abcd

19 return {"message": "Hello World"} 1JKLM

20 

21 

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

23 

24 

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

26def get_text(): 1abcd

27 return "Hello World" 1NOPQ

28 

29 

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

31def get_id(item_id): 1abcd

32 return item_id 1RSTU

33 

34 

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

36def get_str_id(item_id: str): 1abcd

37 return item_id 1VWXYZ012345

38 

39 

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

41def get_int_id(item_id: int): 1abcd

42 return item_id 16789

43 

44 

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

46def get_float_id(item_id: float): 1abcd

47 return item_id 1!#$%'()

48 

49 

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

51def get_bool_id(item_id: bool): 1abcd

52 return item_id 1*+,-./:;=?@[]^_`{|}~

53 

54 

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

56def get_path_param_id(item_id: str | None = Path()): 1abcd

57 return item_id 2abbbcbdb

58 

59 

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

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

62 return item_id 2ebfbgbhb

63 

64 

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

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

67 return item_id 2ibjbkblb

68 

69 

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

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

72 return item_id 2mbnbobpb

73 

74 

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

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

77 return item_id 2qbrbsbtb

78 

79 

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

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

82 return item_id 2ubvbwbxb

83 

84 

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

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

87 return item_id 2ybzbAbBbCbDbEbFb

88 

89 

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

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

92 return item_id 2GbHbIbJb

93 

94 

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

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

97 return item_id 2KbLbMbNb

98 

99 

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

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

102 return item_id 2ObPbQbRbSbTbUbVb

103 

104 

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

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

107 return item_id 2WbXbYbZb

108 

109 

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

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

112 return item_id 20b1b2b3b4b5b6b7b8b9b!b

113 

114 

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

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

117 return item_id 2#b$b%b'b

118 

119 

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

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

122 return item_id 2(b)b*b+b

123 

124 

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

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

127 return item_id 2,b-b.b/b:b;b=b?b

128 

129 

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

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

132 return item_id 2@b[b]b^b_b`b{b|b

133 

134 

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

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

137 return item_id 2}b~bacbc

138 

139 

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

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

142 return item_id 2ccdcecfcgchcicjckclcmc

143 

144 

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

146def get_query(query): 1abcd

147 return f"foo bar {query}" 2ncocpcqc

148 

149 

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

151def get_query_optional(query=None): 1abcd

152 if query is None: 1efghijklmno

153 return "foo bar" 1egijlmo

154 return f"foo bar {query}" 1fhkn

155 

156 

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

158def get_query_type(query: int): 1abcd

159 return f"foo bar {query}" 2rcsctcuc

160 

161 

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

163def get_query_type_optional(query: int | None = None): 1abcd

164 if query is None: 1pqrstuvw

165 return "foo bar" 1qsuw

166 return f"foo bar {query}" 1prtv

167 

168 

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

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

171 return f"foo bar {query}" 2vcwcxcyczcAcBc

172 

173 

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

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

176 if query is None: 1xyzABCDE

177 return "foo bar" 1yACE

178 return f"foo bar {query}" 1xzBD

179 

180 

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

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

183 return f"foo bar {query}" 2CcDcEcFc

184 

185 

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

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

188 return f"foo bar {query}" 2GcHcIcJc

189 

190 

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

192def get_enum_status_code(): 1abcd

193 return "foo bar" 2KcLcMcNc

194 

195 

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

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

198 return ",".join(map(str, sorted(query))) 2OcPcQcRc

199 

200 

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

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

203 return device_ids 2ScTcUcVc

204 

205 

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

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

208 return device_ids 2WcXcYcZc0c1c2c3c