Skip to content

Commit 9633617

Browse files
committed
ISSUE-1503: add StreamRecord tests
1 parent d345979 commit 9633617

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

aws_lambda_powertools/utilities/data_classes/dynamo_db_stream_event.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,10 @@ def approximate_creation_date_time(self) -> Optional[int]:
182182
item = self.get("ApproximateCreationDateTime")
183183
return None if item is None else int(item)
184184

185+
# This override breaks the Mapping protocol of DictWrapper, it's left here for backwards compatibility with
186+
# a 'type: ignore' comment. This is currently the only subclass of DictWrapper that breaks this protocol.
185187
@property
186-
def keys(self) -> Optional[Dict[str, AttributeValue]]:
188+
def keys(self) -> Optional[Dict[str, AttributeValue]]: # type: ignore
187189
"""The primary key attribute(s) for the DynamoDB item that was modified."""
188190
return _attribute_value_dict(self._data, "Keys")
189191

tests/__init__.py

Whitespace-only changes.

tests/functional/test_data_classes.py

+18
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
AttributeValueType,
7575
DynamoDBRecordEventName,
7676
DynamoDBStreamEvent,
77+
StreamRecord,
7778
StreamViewType,
7879
)
7980
from aws_lambda_powertools.utilities.data_classes.event_source import event_source
@@ -630,6 +631,23 @@ def test_dynamo_attribute_value_type_error():
630631
print(attribute_value.get_type)
631632

632633

634+
def test_stream_record_keys_with_valid_keys():
635+
attribute_value = {"Foo": "Bar"}
636+
sr = StreamRecord({"Keys": {"Key1": attribute_value}})
637+
assert sr.keys == {"Key1": AttributeValue(attribute_value)}
638+
639+
640+
def test_stream_record_keys_with_no_keys():
641+
sr = StreamRecord({})
642+
assert sr.keys is None
643+
644+
645+
def test_stream_record_keys_overrides_dict_wrapper_keys():
646+
data = {"Keys": {"key1": {"attr1": "value1"}}}
647+
sr = StreamRecord(data)
648+
assert sr.keys != data.keys()
649+
650+
633651
def test_event_bridge_event():
634652
event = EventBridgeEvent(load_event("eventBridgeEvent.json"))
635653

0 commit comments

Comments
 (0)