@@ -1128,76 +1128,3 @@ def handler(user_id: int = 123):
1128
1128
# THEN the handler should be invoked and return 200
1129
1129
result = app (minimal_event , {})
1130
1130
assert result ["statusCode" ] == 200
1131
-
1132
-
1133
- def test_validation_error_none_returned_non_optional_type (gw_event ):
1134
- # GIVEN an APIGatewayRestResolver with validation enabled
1135
- app = APIGatewayRestResolver (enable_validation = True )
1136
-
1137
- class Model (BaseModel ):
1138
- name : str
1139
- age : int
1140
-
1141
- @app .get ("/none_not_allowed" )
1142
- def handler_none_not_allowed () -> Model :
1143
- return None # type: ignore
1144
-
1145
- # WHEN returning None for a non-Optional type
1146
- gw_event ["path" ] = "/none_not_allowed"
1147
- result = app (gw_event , {})
1148
-
1149
- # THEN it should return a validation error
1150
- assert result ["statusCode" ] == 422
1151
- body = json .loads (result ["body" ])
1152
- assert "model_attributes_type" in body ["detail" ][0 ]["type" ]
1153
-
1154
-
1155
- def test_none_returned_for_optional_type (gw_event ):
1156
- # GIVEN an APIGatewayRestResolver with validation enabled
1157
- app = APIGatewayRestResolver (enable_validation = True )
1158
-
1159
- class Model (BaseModel ):
1160
- name : str
1161
- age : int
1162
-
1163
- @app .get ("/none_allowed" )
1164
- def handler_none_allowed () -> Optional [Model ]:
1165
- return None
1166
-
1167
- # WHEN returning None for an Optional type
1168
- gw_event ["path" ] = "/none_allowed"
1169
- result = app (gw_event , {})
1170
-
1171
- # THEN it should succeed
1172
- assert result ["statusCode" ] == 200
1173
- assert result ["body" ] == "null"
1174
-
1175
-
1176
- @pytest .mark .parametrize (
1177
- "path, body" ,
1178
- [
1179
- ("/empty_dict" , {}),
1180
- ("/empty_list" , []),
1181
- ("/none" , "null" ),
1182
- ("/empty_string" , "" ),
1183
- ],
1184
- ids = ["empty_dict" , "empty_list" , "none" , "empty_string" ],
1185
- )
1186
- def test_none_returned_for_falsy_return (gw_event , path , body ):
1187
- # GIVEN an APIGatewayRestResolver with validation enabled
1188
- app = APIGatewayRestResolver (enable_validation = True )
1189
-
1190
- class Model (BaseModel ):
1191
- name : str
1192
- age : int
1193
-
1194
- @app .get (path )
1195
- def handler_none_allowed () -> Model :
1196
- return body
1197
-
1198
- # WHEN returning None for an Optional type
1199
- gw_event ["path" ] = path
1200
- result = app (gw_event , {})
1201
-
1202
- # THEN it should succeed
1203
- assert result ["statusCode" ] == 422
0 commit comments