Coverage for tests/main.py: 100%

124 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-01-13 13:38 +0000

1import http 1abcde

2from typing import FrozenSet, List, Optional 1abcde

3 

4from fastapi import FastAPI, Path, Query 1abcde

5 

6app = FastAPI() 1abcde

7 

8 

9@app.api_route("/api_route") 1abcde

10def non_operation(): 1abcde

11 return {"message": "Hello World"} 1fghij

12 

13 

14def non_decorated_route(): 1abcde

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

16 

17 

18app.add_api_route("/non_decorated_route", non_decorated_route) 1abcde

19 

20 

21@app.get("/text") 1abcde

22def get_text(): 1abcde

23 return "Hello World" 1TUVWX

24 

25 

26@app.get("/path/{item_id}") 1abcde

27def get_id(item_id): 1abcde

28 return item_id 1YZ012

29 

30 

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

32def get_str_id(item_id: str): 1abcde

33 return item_id 13456789!#$%'()*

34 

35 

36@app.get("/path/int/{item_id}") 1abcde

37def get_int_id(item_id: int): 1abcde

38 return item_id 1+,-./

39 

40 

41@app.get("/path/float/{item_id}") 1abcde

42def get_float_id(item_id: float): 1abcde

43 return item_id 1:;=?@[]^_`

44 

45 

46@app.get("/path/bool/{item_id}") 1abcde

47def get_bool_id(item_id: bool): 1abcde

48 return item_id 2{ | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwbxbybzb

49 

50 

51@app.get("/path/param/{item_id}") 1abcde

52def get_path_param_id(item_id: Optional[str] = Path()): 1abcde

53 return item_id 2AbBbCbDbEb

54 

55 

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 2FbGbHbIbJb

59 

60 

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 2KbLbMbNbOb

64 

65 

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 2PbQbRbSbTb

69 

70 

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 2UbVbWbXbYb

74 

75 

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 2Zb0b1b2b3b

79 

80 

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 24b5b6b7b8b9b!b#b$b%b

84 

85 

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 2'b(b)b*b+b

89 

90 

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 2,b-b.b/b:b

94 

95 

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 2;b=b?b@b[b]b^b_b`b{b

99 

100 

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 2|b}b~bacbc

104 

105 

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 2ccdcecfcgchcicjckclcmcncocpcqc

109 

110 

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 2rcsctcucvc

114 

115 

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 2wcxcyczcAc

119 

120 

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 2BcCcDcEcFcGcHcIcJcKc

124 

125 

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 2LcMcNcOcPcQcRcScTcUc

129 

130 

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 2VcWcXcYcZc

134 

135 

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 20c1c2c3c4c5c6c7c8c9c!c#c$c%c'c

139 

140 

141@app.get("/query") 1abcde

142def get_query(query): 1abcde

143 return f"foo bar {query}" 2(c)c*c+c,c

144 

145 

146@app.get("/query/optional") 1abcde

147def get_query_optional(query=None): 1abcde

148 if query is None: 1klmnopqrstuvwxy

149 return "foo bar" 1klnoqrtuwx

150 return f"foo bar {query}" 1mpsvy

151 

152 

153@app.get("/query/int") 1abcde

154def get_query_type(query: int): 1abcde

155 return f"foo bar {query}" 2-c.c/c:c;c

156 

157 

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

159def get_query_type_optional(query: Optional[int] = None): 1abcde

160 if query is None: 1zABCDEFGHI

161 return "foo bar" 1zBDFH

162 return f"foo bar {query}" 1ACEGI

163 

164 

165@app.get("/query/int/default") 1abcde

166def get_query_type_int_default(query: int = 10): 1abcde

167 return f"foo bar {query}" 2=c?c@c[c]c^c_c`c{c|c

168 

169 

170@app.get("/query/param") 1abcde

171def get_query_param(query=Query(default=None)): 1abcde

172 if query is None: 1JKLMNOPQRS

173 return "foo bar" 1JLNPR

174 return f"foo bar {query}" 1KMOQS

175 

176 

177@app.get("/query/param-required") 1abcde

178def get_query_param_required(query=Query()): 1abcde

179 return f"foo bar {query}" 2}c~cadbdcd

180 

181 

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

183def get_query_param_required_type(query: int = Query()): 1abcde

184 return f"foo bar {query}" 2ddedfdgdhd

185 

186 

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

188def get_enum_status_code(): 1abcde

189 return "foo bar" 2idjdkdldmd

190 

191 

192@app.get("/query/frozenset") 1abcde

193def get_query_type_frozenset(query: FrozenSet[int] = Query(...)): 1abcde

194 return ",".join(map(str, sorted(query))) 2ndodpdqdrd

195 

196 

197@app.get("/query/list") 1abcde

198def get_query_list(device_ids: List[int] = Query()) -> List[int]: 1abcde

199 return device_ids 2sdtdudvdwd

200 

201 

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 2xdydzdAdBdCdDdEdFdGd