|
| 1 | +from aws_lambda_powertools.event_handler import ( |
| 2 | + ALBResolver, |
| 3 | + APIGatewayHttpResolver, |
| 4 | + APIGatewayRestResolver, |
| 5 | + LambdaFunctionUrlResolver, |
| 6 | + VPCLatticeResolver, |
| 7 | + VPCLatticeV2Resolver, |
| 8 | +) |
| 9 | +from tests.functional.utils import load_event |
| 10 | + |
| 11 | + |
| 12 | +def test_base_path_api_gateway_rest(): |
| 13 | + app = APIGatewayRestResolver(enable_validation=True) |
| 14 | + |
| 15 | + @app.get("/") |
| 16 | + def handle(): |
| 17 | + return app._get_base_path() |
| 18 | + |
| 19 | + event = load_event("apiGatewayProxyEvent.json") |
| 20 | + event["path"] = "/" |
| 21 | + |
| 22 | + result = app(event, {}) |
| 23 | + assert result["statusCode"] == 200 |
| 24 | + assert result["body"] == "" |
| 25 | + |
| 26 | + |
| 27 | +def test_base_path_api_gateway_http(): |
| 28 | + app = APIGatewayHttpResolver(enable_validation=True) |
| 29 | + |
| 30 | + @app.get("/") |
| 31 | + def handle(): |
| 32 | + return app._get_base_path() |
| 33 | + |
| 34 | + event = load_event("apiGatewayProxyV2Event.json") |
| 35 | + event["rawPath"] = "/" |
| 36 | + event["requestContext"]["http"]["path"] = "/" |
| 37 | + event["requestContext"]["http"]["method"] = "GET" |
| 38 | + |
| 39 | + result = app(event, {}) |
| 40 | + assert result["statusCode"] == 200 |
| 41 | + assert result["body"] == "" |
| 42 | + |
| 43 | + |
| 44 | +def test_base_path_alb(): |
| 45 | + app = ALBResolver(enable_validation=True) |
| 46 | + |
| 47 | + @app.get("/") |
| 48 | + def handle(): |
| 49 | + return app._get_base_path() |
| 50 | + |
| 51 | + event = load_event("albEvent.json") |
| 52 | + event["path"] = "/" |
| 53 | + |
| 54 | + result = app(event, {}) |
| 55 | + assert result["statusCode"] == 200 |
| 56 | + assert result["body"] == "" |
| 57 | + |
| 58 | + |
| 59 | +def test_base_path_lambda_function_url(): |
| 60 | + app = LambdaFunctionUrlResolver(enable_validation=True) |
| 61 | + |
| 62 | + @app.get("/") |
| 63 | + def handle(): |
| 64 | + return app._get_base_path() |
| 65 | + |
| 66 | + event = load_event("lambdaFunctionUrlIAMEvent.json") |
| 67 | + event["rawPath"] = "/" |
| 68 | + event["requestContext"]["http"]["path"] = "/" |
| 69 | + event["requestContext"]["http"]["method"] = "GET" |
| 70 | + |
| 71 | + result = app(event, {}) |
| 72 | + assert result["statusCode"] == 200 |
| 73 | + assert result["body"] == "" |
| 74 | + |
| 75 | + |
| 76 | +def test_vpc_lattice(): |
| 77 | + app = VPCLatticeResolver(enable_validation=True) |
| 78 | + |
| 79 | + @app.get("/") |
| 80 | + def handle(): |
| 81 | + return app._get_base_path() |
| 82 | + |
| 83 | + event = load_event("vpcLatticeEvent.json") |
| 84 | + event["raw_path"] = "/" |
| 85 | + |
| 86 | + result = app(event, {}) |
| 87 | + assert result["statusCode"] == 200 |
| 88 | + assert result["body"] == "" |
| 89 | + |
| 90 | + |
| 91 | +def test_vpc_latticev2(): |
| 92 | + app = VPCLatticeV2Resolver(enable_validation=True) |
| 93 | + |
| 94 | + @app.get("/") |
| 95 | + def handle(): |
| 96 | + return app._get_base_path() |
| 97 | + |
| 98 | + event = load_event("vpcLatticeV2Event.json") |
| 99 | + event["path"] = "/" |
| 100 | + |
| 101 | + result = app(event, {}) |
| 102 | + assert result["statusCode"] == 200 |
| 103 | + assert result["body"] == "" |
0 commit comments