|
2 | 2 | from typing import Any, Dict
|
3 | 3 |
|
4 | 4 | from aws_lambda_powertools.event_handler import BedrockAgentResolver, Response, content_types
|
| 5 | +from aws_lambda_powertools.event_handler.openapi.params import Body |
5 | 6 | from aws_lambda_powertools.event_handler.openapi.pydantic_loader import PYDANTIC_V2
|
| 7 | +from aws_lambda_powertools.shared.types import Annotated |
6 | 8 | from aws_lambda_powertools.utilities.data_classes import BedrockAgentEvent
|
7 | 9 | from tests.functional.utils import load_event
|
8 | 10 |
|
@@ -157,3 +159,28 @@ def claims():
|
157 | 159 |
|
158 | 160 | body = result["response"]["responseBody"]["text/plain"]["body"]
|
159 | 161 | assert body == "Something went wrong"
|
| 162 | + |
| 163 | + |
| 164 | +def test_bedrock_agent_with_post(): |
| 165 | + # GIVEN a Bedrock Agent resolver with a POST method |
| 166 | + app = BedrockAgentResolver() |
| 167 | + |
| 168 | + @app.post("/send-reminders", description="Sends reminders") |
| 169 | + def send_reminders( |
| 170 | + _claim_id: Annotated[int, Body(description="Claim ID", alias="claimId")], |
| 171 | + _pending_documents: Annotated[str, Body(description="Social number and VAT", alias="pendingDocuments")], |
| 172 | + ) -> Annotated[bool, Body(description="returns true if I like the email")]: |
| 173 | + return True |
| 174 | + |
| 175 | + # WHEN calling the event handler |
| 176 | + result = app(load_event("bedrockAgentPostEvent.json"), {}) |
| 177 | + |
| 178 | + # THEN process the event correctly |
| 179 | + assert result["messageVersion"] == "1.0" |
| 180 | + assert result["response"]["apiPath"] == "/send-reminders" |
| 181 | + assert result["response"]["httpMethod"] == "POST" |
| 182 | + assert result["response"]["httpStatusCode"] == 200 |
| 183 | + |
| 184 | + # THEN return the correct result |
| 185 | + body = result["response"]["responseBody"]["application/json"]["body"] |
| 186 | + assert json.loads(body) is True |
0 commit comments