Skip to content

Commit f2d5e63

Browse files
committed
Merge branch 'kinesis' of github.com:roger-zhangg/aws-lambda-powertools-python into kinesis
2 parents ef12496 + b20137a commit f2d5e63

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

aws_lambda_powertools/utilities/data_classes/kinesis_firehose_event.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import json
33
import warnings
44
from dataclasses import dataclass, field
5-
from typing import Any, Callable, Dict, Iterator, List, Optional
5+
from typing import Any, Callable, ClassVar, Dict, Iterator, List, Optional, Tuple
66

77
from typing_extensions import Literal
88

@@ -62,6 +62,8 @@ class KinesisFirehoseDataTransformationRecord:
6262
- https://docs.aws.amazon.com/firehose/latest/dev/data-transformation.html
6363
"""
6464

65+
_valid_result_types: ClassVar[Tuple[str, str, str]] = ("Ok", "Dropped", "ProcessingFailed")
66+
6567
record_id: str
6668
result: Literal["Ok", "Dropped", "ProcessingFailed"] = "Ok"
6769
data: str = ""
@@ -71,7 +73,7 @@ class KinesisFirehoseDataTransformationRecord:
7173
_json_data: Optional[Any] = None
7274

7375
def asdict(self) -> Dict:
74-
if self.result not in ["Ok", "Dropped", "ProcessingFailed"]:
76+
if self.result not in self._valid_result_types:
7577
warnings.warn(
7678
stacklevel=1,
7779
message=f'The result "{self.result}" is not valid, Choose from "Ok", "Dropped", "ProcessingFailed"',
@@ -132,7 +134,7 @@ def add_record(self, record: KinesisFirehoseDataTransformationRecord):
132134

133135
def asdict(self) -> Dict:
134136
if not self.records:
135-
raise ValueError("Kinesis Firehose doesn't accept empty response")
137+
raise ValueError("Amazon Kinesis Data Firehose doesn't accept empty response")
136138

137139
return {"records": [record.asdict() for record in self.records]}
138140

@@ -216,7 +218,8 @@ def build_data_transformation_response(
216218
data: str = "",
217219
metadata: Optional[KinesisFirehoseDataTransformationRecordMetadata] = None,
218220
) -> KinesisFirehoseDataTransformationRecord:
219-
"""create a KinesisFirehoseResponseRecord directly using the record_id and given values
221+
"""Create a KinesisFirehoseResponseRecord directly using the record_id and given values
222+
220223
Parameters
221224
----------
222225
result : Literal["Ok", "Dropped", "ProcessingFailed"]

tests/unit/data_classes/test_kinesis_firehose_response.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,27 @@ def test_kinesis_firehose_response():
5353

5454

5555
def test_kinesis_firehose_response_asdict():
56-
# Given the following example response provided by Firehose
56+
# GIVEN the following example response provided by Firehose
5757
sample_response = {
5858
"records": [
5959
{"recordId": "sample_record", "data": "", "result": "Ok", "metadata": {"partitionKeys": {"year": "2023"}}},
6060
],
6161
}
6262

63-
# Then asdict function should be able to return the same value
6463
response = KinesisFirehoseDataTransformationResponse()
6564
metadata_partition = KinesisFirehoseDataTransformationRecordMetadata(
6665
partition_keys=sample_response["records"][0]["metadata"]["partitionKeys"],
6766
)
67+
68+
# WHEN we create a transformation record with the exact same data
6869
processed_record = KinesisFirehoseDataTransformationRecord(
6970
record_id=sample_response["records"][0]["recordId"],
7071
data=sample_response["records"][0]["data"],
7172
result=sample_response["records"][0]["result"],
7273
metadata=metadata_partition,
7374
)
75+
76+
# THEN serialized response should return the same value
7477
response.add_record(record=processed_record)
7578
assert response.asdict() == sample_response
7679

0 commit comments

Comments
 (0)