Skip to content

Commit 021f6c6

Browse files
committed
fix: tests
1 parent 3b6f070 commit 021f6c6

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

aws_lambda_powertools/event_handler/api_gateway.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def __init__(
210210
self,
211211
status_code: int,
212212
content_type: Optional[str] = None,
213-
body: Union[str, bytes, None] = None,
213+
body: Union[Any, None] = None,
214214
headers: Optional[Dict[str, Union[str, List[str]]]] = None,
215215
cookies: Optional[List[Cookie]] = None,
216216
compress: Optional[bool] = None,
@@ -1317,7 +1317,7 @@ def __init__(
13171317
self._strip_prefixes = strip_prefixes
13181318
self.context: Dict = {} # early init as customers might add context before event resolution
13191319
self.processed_stack_frames = []
1320-
self.response_builder_class = ResponseBuilder
1320+
self._response_builder_class = ResponseBuilder
13211321

13221322
# Allow for a custom serializer or a concise json serialization
13231323
self._serializer = serializer or partial(json.dumps, separators=(",", ":"), cls=Encoder)
@@ -1875,9 +1875,9 @@ def _not_found(self, method: str) -> ResponseBuilder:
18751875

18761876
handler = self._lookup_exception_handler(NotFoundError)
18771877
if handler:
1878-
return self.response_builder_class(handler(NotFoundError()))
1878+
return self._response_builder_class(handler(NotFoundError()))
18791879

1880-
return self.response_builder_class(
1880+
return self._response_builder_class(
18811881
Response(
18821882
status_code=HTTPStatus.NOT_FOUND.value,
18831883
content_type=content_types.APPLICATION_JSON,
@@ -1892,7 +1892,7 @@ def _call_route(self, route: Route, route_arguments: Dict[str, str]) -> Response
18921892
# Reset Processed stack for Middleware (for debugging purposes)
18931893
self._reset_processed_stack()
18941894

1895-
return self.response_builder_class(
1895+
return self._response_builder_class(
18961896
self._to_response(
18971897
route(router_middlewares=self._router_middlewares, app=self, route_arguments=route_arguments),
18981898
),
@@ -1909,7 +1909,7 @@ def _call_route(self, route: Route, route_arguments: Dict[str, str]) -> Response
19091909
# If the user has turned on debug mode,
19101910
# we'll let the original exception propagate, so
19111911
# they get more information about what went wrong.
1912-
return self.response_builder_class(
1912+
return self._response_builder_class(
19131913
Response(
19141914
status_code=500,
19151915
content_type=content_types.TEXT_PLAIN,
@@ -1948,12 +1948,12 @@ def _call_exception_handler(self, exp: Exception, route: Route) -> Optional[Resp
19481948
handler = self._lookup_exception_handler(type(exp))
19491949
if handler:
19501950
try:
1951-
return self.response_builder_class(handler(exp), route)
1951+
return self._response_builder_class(handler(exp), route)
19521952
except ServiceError as service_error:
19531953
exp = service_error
19541954

19551955
if isinstance(exp, ServiceError):
1956-
return self.response_builder_class(
1956+
return self._response_builder_class(
19571957
Response(
19581958
status_code=exp.status_code,
19591959
content_type=content_types.APPLICATION_JSON,

aws_lambda_powertools/event_handler/bedrock_agent.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
22
from typing import Any, Dict, Optional, cast
33

4+
from typing_extensions import override
5+
46
from aws_lambda_powertools.event_handler import ApiGatewayResolver
57
from aws_lambda_powertools.event_handler.api_gateway import CORSConfig, ProxyEventType, ResponseBuilder
68
from aws_lambda_powertools.utilities.data_classes import BedrockAgentEvent
@@ -10,6 +12,7 @@
1012

1113

1214
class BedrockResponseBuilder(ResponseBuilder):
15+
@override
1316
def build(self, event: BaseProxyEvent, cors: Optional[CORSConfig] = None) -> Dict[str, Any]:
1417
"""Build the full response dict to be returned by the lambda"""
1518
self._route(event, cors)
@@ -68,4 +71,4 @@ def __init__(self, debug: bool = False, enable_validation: bool = True):
6871
None,
6972
enable_validation,
7073
)
71-
self.response_builder_class = BedrockResponseBuilder
74+
self._response_builder_class = BedrockResponseBuilder

tests/functional/event_handler/test_bedrock_agent.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ def claims() -> Dict[str, Any]:
3030
assert result["response"]["httpStatusCode"] == 200
3131

3232
body = result["response"]["responseBody"]["application/json"]["body"]
33-
assert body == {"output": claims_response}
33+
assert body == json.dumps({"output": claims_response})
3434

3535

3636
def test_bedrock_agent_event_with_response():
3737
# GIVEN a Bedrock Agent event
3838
app = BedrockAgentResolver()
39-
output = json.dumps({"output": claims_response})
39+
output = {"output": claims_response}
4040

4141
@app.get("/claims")
4242
def claims():
@@ -56,7 +56,7 @@ def claims():
5656
assert result["response"]["httpStatusCode"] == 200
5757

5858
body = result["response"]["responseBody"]["application/json"]["body"]
59-
assert body == output
59+
assert body == json.dumps(output)
6060

6161

6262
def test_bedrock_agent_event_with_no_matches():

0 commit comments

Comments
 (0)