Skip to content

Commit ff128fb

Browse files
feat: addin resolve async internal
1 parent 60d0684 commit ff128fb

2 files changed

Lines changed: 35 additions & 21 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import asyncio
2+
3+
from aws_lambda_powertools.event_handler.api_gateway import (
4+
APIGatewayHttpResolver,
5+
BaseRouter,
6+
)
7+
from tests.functional.utils import load_event
8+
9+
API_RESTV2_EVENT = load_event("apiGatewayProxyV2Event_GET.json")
10+
11+
12+
def _setup_app(app, event):
13+
BaseRouter.current_event = app._to_proxy_event(event)
14+
BaseRouter.lambda_context = {}
15+
16+
17+
class TestResolveAsyncValidation:
18+
def test_validation_middleware_created_and_used(self):
19+
# GIVEN a resolver with validation enabled and an async handler
20+
app = APIGatewayHttpResolver(enable_validation=True)
21+
22+
@app.get("/my/path")
23+
async def get_lambda() -> dict:
24+
await asyncio.sleep(0)
25+
return {"message": "validated"}
26+
27+
# WHEN calling _resolve_async
28+
_setup_app(app, API_RESTV2_EVENT)
29+
result = asyncio.run(app._resolve_async())
30+
31+
# THEN the validation middlewares are created and the response is valid
32+
response = result.build(app.current_event, app._cors)
33+
assert response["statusCode"] == 200
34+
assert hasattr(app, "_request_validation_middleware")
35+
assert hasattr(app, "_response_validation_middleware")

tests/functional/event_handler/required_dependencies/test_resolve_async.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -316,27 +316,6 @@ async def get_lambda():
316316
assert any("_registered_api_adapter_async" in frame for frame in app.processed_stack_frames)
317317

318318

319-
class TestResolveAsyncValidation:
320-
def test_validation_middleware_created_and_used(self):
321-
# GIVEN a resolver with validation enabled and an async handler
322-
app = APIGatewayHttpResolver(enable_validation=True)
323-
324-
@app.get("/my/path")
325-
async def get_lambda() -> dict:
326-
await asyncio.sleep(0)
327-
return {"message": "validated"}
328-
329-
# WHEN calling _resolve_async
330-
_setup_app(app, API_RESTV2_EVENT)
331-
result = asyncio.run(app._resolve_async())
332-
333-
# THEN the validation middlewares are created and the response is valid
334-
response = result.build(app.current_event, app._cors)
335-
assert response["statusCode"] == 200
336-
assert hasattr(app, "_request_validation_middleware")
337-
assert hasattr(app, "_response_validation_middleware")
338-
339-
340319
class TestResolveAsyncDebugMode:
341320
def test_debug_mode_prints_middleware_stack(self, capsys):
342321
# GIVEN a resolver with debug=True

0 commit comments

Comments
 (0)