33import zlib
44from decimal import Decimal
55from pathlib import Path
6- from typing import Dict , Tuple
6+ from typing import Dict
77
88from aws_lambda_powertools .event_handler .api_gateway import (
99 ApiGatewayResolver ,
@@ -29,10 +29,10 @@ def read_media(file_name: str) -> bytes:
2929
3030def test_alb_event ():
3131 # GIVEN a Application Load Balancer proxy type event
32- app = ApiGatewayResolver (proxy_type = ProxyEventType .alb_event )
32+ app = ApiGatewayResolver (proxy_type = ProxyEventType .ALBEvent )
3333
3434 @app .get ("/lambda" )
35- def foo () -> Tuple [ int , str , str ] :
35+ def foo ():
3636 assert isinstance (app .current_event , ALBEvent )
3737 assert app .lambda_context == {}
3838 return 200 , TEXT_HTML , "foo"
@@ -49,13 +49,13 @@ def foo() -> Tuple[int, str, str]:
4949
5050def test_api_gateway_v1 ():
5151 # GIVEN a Http API V1 proxy type event
52- app = ApiGatewayResolver (proxy_type = ProxyEventType .http_api_v1 )
52+ app = ApiGatewayResolver (proxy_type = ProxyEventType .APIGatewayProxyEvent )
5353
5454 @app .get ("/my/path" )
55- def get_lambda () -> Tuple [ int , str , str ] :
55+ def get_lambda () -> Response :
5656 assert isinstance (app .current_event , APIGatewayProxyEvent )
5757 assert app .lambda_context == {}
58- return 200 , APPLICATION_JSON , json .dumps ({"foo" : "value" })
58+ return Response ( 200 , APPLICATION_JSON , json .dumps ({"foo" : "value" }) )
5959
6060 # WHEN calling the event handler
6161 result = app (LOAD_GW_EVENT , {})
@@ -68,12 +68,12 @@ def get_lambda() -> Tuple[int, str, str]:
6868
6969def test_api_gateway ():
7070 # GIVEN a Rest API Gateway proxy type event
71- app = ApiGatewayResolver (proxy_type = ProxyEventType .api_gateway )
71+ app = ApiGatewayResolver (proxy_type = ProxyEventType .APIGatewayProxyEvent )
7272
7373 @app .get ("/my/path" )
74- def get_lambda () -> Tuple [ int , str , str ] :
74+ def get_lambda () -> Response :
7575 assert isinstance (app .current_event , APIGatewayProxyEvent )
76- return 200 , TEXT_HTML , "foo"
76+ return Response ( 200 , TEXT_HTML , "foo" )
7777
7878 # WHEN calling the event handler
7979 result = app (LOAD_GW_EVENT , {})
@@ -87,13 +87,13 @@ def get_lambda() -> Tuple[int, str, str]:
8787
8888def test_api_gateway_v2 ():
8989 # GIVEN a Http API V2 proxy type event
90- app = ApiGatewayResolver (proxy_type = ProxyEventType .http_api_v2 )
90+ app = ApiGatewayResolver (proxy_type = ProxyEventType .APIGatewayProxyEventV2 )
9191
9292 @app .post ("/my/path" )
93- def my_path () -> Tuple [ int , str , str ] :
93+ def my_path () -> Response :
9494 assert isinstance (app .current_event , APIGatewayProxyEventV2 )
9595 post_data = app .current_event .json_body
96- return 200 , "plain/text" , post_data ["username" ]
96+ return Response ( 200 , "plain/text" , post_data ["username" ])
9797
9898 # WHEN calling the event handler
9999 result = app (load_event ("apiGatewayProxyV2Event.json" ), {})
@@ -110,9 +110,9 @@ def test_include_rule_matching():
110110 app = ApiGatewayResolver ()
111111
112112 @app .get ("/<name>/<my_id>" )
113- def get_lambda (my_id : str , name : str ) -> Tuple [ int , str , str ] :
113+ def get_lambda (my_id : str , name : str ) -> Response :
114114 assert name == "my"
115- return 200 , TEXT_HTML , my_id
115+ return Response ( 200 , TEXT_HTML , my_id )
116116
117117 # WHEN calling the event handler
118118 result = app (LOAD_GW_EVENT , {})
@@ -179,8 +179,8 @@ def test_cors():
179179 app = ApiGatewayResolver ()
180180
181181 @app .get ("/my/path" , cors = True )
182- def with_cors () -> Tuple [ int , str , str ] :
183- return 200 , TEXT_HTML , "test"
182+ def with_cors () -> Response :
183+ return Response ( 200 , TEXT_HTML , "test" )
184184
185185 def handler (event , context ):
186186 return app .resolve (event , context )
@@ -205,8 +205,8 @@ def test_compress():
205205 expected_value = '{"test": "value"}'
206206
207207 @app .get ("/my/request" , compress = True )
208- def with_compression () -> Tuple [ int , str , str ] :
209- return 200 , APPLICATION_JSON , expected_value
208+ def with_compression () -> Response :
209+ return Response ( 200 , APPLICATION_JSON , expected_value )
210210
211211 def handler (event , context ):
212212 return app .resolve (event , context )
@@ -230,8 +230,8 @@ def test_base64_encode():
230230 mock_event = {"path" : "/my/path" , "httpMethod" : "GET" , "headers" : {"Accept-Encoding" : "deflate, gzip" }}
231231
232232 @app .get ("/my/path" , compress = True )
233- def read_image () -> Tuple [ int , str , bytes ] :
234- return 200 , "image/png" , read_media ("idempotent_sequence_exception.png" )
233+ def read_image () -> Response :
234+ return Response ( 200 , "image/png" , read_media ("idempotent_sequence_exception.png" ) )
235235
236236 # WHEN calling the event handler
237237 result = app (mock_event , None )
@@ -251,8 +251,8 @@ def test_compress_no_accept_encoding():
251251 expected_value = "Foo"
252252
253253 @app .get ("/my/path" , compress = True )
254- def return_text () -> Tuple [ int , str , str ] :
255- return 200 , "text/plain" , expected_value
254+ def return_text () -> Response :
255+ return Response ( 200 , "text/plain" , expected_value )
256256
257257 # WHEN calling the event handler
258258 result = app ({"path" : "/my/path" , "httpMethod" : "GET" , "headers" : {}}, None )
@@ -267,8 +267,8 @@ def test_cache_control_200():
267267 app = ApiGatewayResolver ()
268268
269269 @app .get ("/success" , cache_control = "max-age=600" )
270- def with_cache_control () -> Tuple [ int , str , str ] :
271- return 200 , TEXT_HTML , "has 200 response"
270+ def with_cache_control () -> Response :
271+ return Response ( 200 , TEXT_HTML , "has 200 response" )
272272
273273 def handler (event , context ):
274274 return app .resolve (event , context )
@@ -288,8 +288,8 @@ def test_cache_control_non_200():
288288 app = ApiGatewayResolver ()
289289
290290 @app .delete ("/fails" , cache_control = "max-age=600" )
291- def with_cache_control_has_500 () -> Tuple [ int , str , str ] :
292- return 503 , TEXT_HTML , "has 503 response"
291+ def with_cache_control_has_500 () -> Response :
292+ return Response ( 503 , TEXT_HTML , "has 503 response" )
293293
294294 def handler (event , context ):
295295 return app .resolve (event , context )
@@ -306,7 +306,7 @@ def handler(event, context):
306306
307307def test_rest_api ():
308308 # GIVEN a function that returns a Dict
309- app = ApiGatewayResolver (proxy_type = ProxyEventType .http_api_v1 )
309+ app = ApiGatewayResolver (proxy_type = ProxyEventType .APIGatewayProxyEvent )
310310 expected_dict = {"foo" : "value" , "second" : Decimal ("100.01" )}
311311
312312 @app .get ("/my/path" )
@@ -325,7 +325,7 @@ def rest_func() -> Dict:
325325
326326def test_handling_response_type ():
327327 # GIVEN a function that returns Response
328- app = ApiGatewayResolver (proxy_type = ProxyEventType .http_api_v1 )
328+ app = ApiGatewayResolver (proxy_type = ProxyEventType .APIGatewayProxyEvent )
329329
330330 @app .get ("/my/path" )
331331 def rest_func () -> Response :
0 commit comments