@@ -323,15 +323,15 @@ def handler(event, context):
323
323
324
324
325
325
def test_cors ():
326
- # GIVEN a function with cors=True
326
+ # GIVEN a function
327
327
# AND http method set to GET
328
328
app = ApiGatewayResolver (cors = CORSConfig ("https://aws.amazon.com" , allow_credentials = True ))
329
329
330
- @app .get ("/my/path" , cors = True )
330
+ @app .get ("/my/path" )
331
331
def with_cors () -> Response :
332
332
return Response (200 , content_types .TEXT_HTML , "test" )
333
333
334
- @app .get ("/without-cors" )
334
+ @app .get ("/without-cors" , cors = False )
335
335
def without_cors () -> Response :
336
336
return Response (200 , content_types .TEXT_HTML , "test" )
337
337
@@ -350,17 +350,17 @@ def handler(event, context):
350
350
assert headers ["Access-Control-Allow-Headers" ] == ["," .join (sorted (CORSConfig ._REQUIRED_HEADERS ))]
351
351
352
352
# THEN for routes without cors flag return no cors headers
353
- mock_event = {"path" : "/my/request " , "httpMethod" : "GET" }
353
+ mock_event = {"path" : "/without-cors " , "httpMethod" : "GET" }
354
354
result = handler (mock_event , None )
355
355
assert "Access-Control-Allow-Origin" not in result ["multiValueHeaders" ]
356
356
357
357
358
358
def test_cors_no_request_origin ():
359
- # GIVEN a function with cors=True
359
+ # GIVEN a function
360
360
# AND http method set to GET
361
- app = ApiGatewayResolver ()
361
+ app = ApiGatewayResolver (cors = CORSConfig () )
362
362
363
- @app .get ("/my/path" , cors = True )
363
+ @app .get ("/my/path" )
364
364
def with_cors () -> Response :
365
365
return Response (200 , content_types .TEXT_HTML , "test" )
366
366
@@ -381,7 +381,7 @@ def handler(event, context):
381
381
382
382
383
383
def test_cors_allow_all_request_origins ():
384
- # GIVEN a function with cors=True
384
+ # GIVEN a function
385
385
# AND http method set to GET
386
386
app = ApiGatewayResolver (
387
387
cors = CORSConfig (
@@ -390,11 +390,11 @@ def test_cors_allow_all_request_origins():
390
390
),
391
391
)
392
392
393
- @app .get ("/my/path" , cors = True )
393
+ @app .get ("/my/path" )
394
394
def with_cors () -> Response :
395
395
return Response (200 , content_types .TEXT_HTML , "test" )
396
396
397
- @app .get ("/without-cors" )
397
+ @app .get ("/without-cors" , cors = False )
398
398
def without_cors () -> Response :
399
399
return Response (200 , content_types .TEXT_HTML , "test" )
400
400
@@ -413,7 +413,7 @@ def handler(event, context):
413
413
assert headers ["Access-Control-Allow-Headers" ] == ["," .join (sorted (CORSConfig ._REQUIRED_HEADERS ))]
414
414
415
415
# THEN for routes without cors flag return no cors headers
416
- mock_event = {"path" : "/my/request " , "httpMethod" : "GET" }
416
+ mock_event = {"path" : "/without-cors " , "httpMethod" : "GET" }
417
417
result = handler (mock_event , None )
418
418
assert "Access-Control-Allow-Origin" not in result ["multiValueHeaders" ]
419
419
@@ -811,7 +811,7 @@ def test_custom_preflight_response():
811
811
# AND the request matches this custom preflight route
812
812
app = ApiGatewayResolver (cors = CORSConfig ())
813
813
814
- @app .route (method = "OPTIONS" , rule = "/some-call" , cors = True )
814
+ @app .route (method = "OPTIONS" , rule = "/some-call" )
815
815
def custom_preflight ():
816
816
return Response (
817
817
status_code = 200 ,
@@ -820,7 +820,7 @@ def custom_preflight():
820
820
headers = {"Access-Control-Allow-Methods" : ["CUSTOM" ]},
821
821
)
822
822
823
- @app .route (method = "CUSTOM" , rule = "/some-call" , cors = True )
823
+ @app .route (method = "CUSTOM" , rule = "/some-call" )
824
824
def custom_method (): ...
825
825
826
826
# AND the request includes an origin
@@ -903,7 +903,7 @@ def internal_server_error():
903
903
assert result ["body" ] == json_dump (expected )
904
904
905
905
# GIVEN an ServiceError with a custom status code
906
- @app .get (rule = "/service-error" , cors = True )
906
+ @app .get (rule = "/service-error" )
907
907
def service_error ():
908
908
raise ServiceError (502 , "Something went wrong!" )
909
909
@@ -964,7 +964,8 @@ def raises_error():
964
964
def test_powertools_dev_sets_debug_mode (monkeypatch ):
965
965
# GIVEN a debug mode environment variable is set
966
966
monkeypatch .setenv (constants .POWERTOOLS_DEV_ENV , "true" )
967
- app = ApiGatewayResolver ()
967
+ with pytest .warns (UserWarning , match = "POWERTOOLS_DEV environment variable is enabled." ):
968
+ app = ApiGatewayResolver ()
968
969
969
970
# WHEN calling app._debug
970
971
# THEN the debug mode is enabled
@@ -1428,7 +1429,8 @@ def get_func():
1428
1429
def get_func_another_duplicate ():
1429
1430
raise RuntimeError ()
1430
1431
1431
- app .include_router (router )
1432
+ with pytest .warns (UserWarning , match = "A route like this was already registered" ):
1433
+ app .include_router (router )
1432
1434
1433
1435
# WHEN calling the handler
1434
1436
result = app (LOAD_GW_EVENT , None )
@@ -1707,7 +1709,12 @@ def my_path():
1707
1709
@event_source (data_class = APIGatewayProxyEventV2 )
1708
1710
def handler (event : APIGatewayProxyEventV2 , context ):
1709
1711
assert isinstance (event , APIGatewayProxyEventV2 )
1710
- return app .resolve (event , context )
1712
+
1713
+ with pytest .warns (
1714
+ UserWarning ,
1715
+ match = "You don't need to serialize event to Event Source Data Class when using Event Handler" ,
1716
+ ):
1717
+ return app .resolve (event , context )
1711
1718
1712
1719
# THEN
1713
1720
result = handler (load_event ("apiGatewayProxyV2Event.json" ), None )
0 commit comments