|
74 | 74 | AttributeValueType,
|
75 | 75 | DynamoDBRecordEventName,
|
76 | 76 | DynamoDBStreamEvent,
|
| 77 | + StreamRecord, |
77 | 78 | StreamViewType,
|
78 | 79 | )
|
79 | 80 | from aws_lambda_powertools.utilities.data_classes.event_source import event_source
|
@@ -101,6 +102,19 @@ def message(self) -> str:
|
101 | 102 | assert DataClassSample(data1).raw_event is data1
|
102 | 103 |
|
103 | 104 |
|
| 105 | +def test_dict_wrapper_implements_mapping(): |
| 106 | + class DataClassSample(DictWrapper): |
| 107 | + pass |
| 108 | + |
| 109 | + data = {"message": "foo1"} |
| 110 | + event_source = DataClassSample(data) |
| 111 | + assert len(event_source) == len(data) |
| 112 | + assert list(event_source) == list(data) |
| 113 | + assert event_source.keys() == data.keys() |
| 114 | + assert list(event_source.values()) == list(data.values()) |
| 115 | + assert event_source.items() == data.items() |
| 116 | + |
| 117 | + |
104 | 118 | def test_cloud_watch_dashboard_event():
|
105 | 119 | event = CloudWatchDashboardCustomWidgetEvent(load_event("cloudWatchDashboardEvent.json"))
|
106 | 120 | assert event.describe is False
|
@@ -617,6 +631,23 @@ def test_dynamo_attribute_value_type_error():
|
617 | 631 | print(attribute_value.get_type)
|
618 | 632 |
|
619 | 633 |
|
| 634 | +def test_stream_record_keys_with_valid_keys(): |
| 635 | + attribute_value = {"Foo": "Bar"} |
| 636 | + record = StreamRecord({"Keys": {"Key1": attribute_value}}) |
| 637 | + assert record.keys == {"Key1": AttributeValue(attribute_value)} |
| 638 | + |
| 639 | + |
| 640 | +def test_stream_record_keys_with_no_keys(): |
| 641 | + record = StreamRecord({}) |
| 642 | + assert record.keys is None |
| 643 | + |
| 644 | + |
| 645 | +def test_stream_record_keys_overrides_dict_wrapper_keys(): |
| 646 | + data = {"Keys": {"key1": {"attr1": "value1"}}} |
| 647 | + record = StreamRecord(data) |
| 648 | + assert record.keys != data.keys() |
| 649 | + |
| 650 | + |
620 | 651 | def test_event_bridge_event():
|
621 | 652 | event = EventBridgeEvent(load_event("eventBridgeEvent.json"))
|
622 | 653 |
|
|
0 commit comments