Skip to content

Commit 793b55b

Browse files
leandrodamascenarafaelgsr
authored andcommitted
refactor(event_source): convert functional tests to unit tests (aws-powertools#2506)
1 parent 21d4bc4 commit 793b55b

33 files changed

+2684
-2446
lines changed

aws_lambda_powertools/utilities/data_classes/active_mq_event.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Iterator, Optional
1+
from typing import Any, Dict, Iterator, Optional
22

33
from aws_lambda_powertools.utilities.data_classes.common import DictWrapper
44
from aws_lambda_powertools.utilities.data_classes.shared_functions import base64_decode
@@ -112,6 +112,10 @@ class ActiveMQEvent(DictWrapper):
112112
- https://aws.amazon.com/blogs/compute/using-amazon-mq-as-an-event-source-for-aws-lambda/
113113
"""
114114

115+
def __init__(self, data: Dict[str, Any]):
116+
super().__init__(data)
117+
self._messages: Optional[Iterator[ActiveMQMessage]] = None
118+
115119
@property
116120
def event_source(self) -> str:
117121
return self["eventSource"]
@@ -128,4 +132,20 @@ def messages(self) -> Iterator[ActiveMQMessage]:
128132

129133
@property
130134
def message(self) -> ActiveMQMessage:
131-
return next(self.messages)
135+
"""
136+
Returns the next ActiveMQ message using an iterator
137+
138+
Returns
139+
-------
140+
ActiveMQMessage
141+
The next activemq message.
142+
143+
Raises
144+
------
145+
StopIteration
146+
If there are no more records available.
147+
148+
"""
149+
if self._messages is None:
150+
self._messages = self.messages
151+
return next(self._messages)

aws_lambda_powertools/utilities/data_classes/kafka_event.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ class KafkaEvent(DictWrapper):
8787
- https://docs.aws.amazon.com/lambda/latest/dg/with-msk.html
8888
"""
8989

90+
def __init__(self, data: Dict[str, Any]):
91+
super().__init__(data)
92+
self._records: Optional[Iterator[KafkaEventRecord]] = None
93+
9094
@property
9195
def event_source(self) -> str:
9296
"""The AWS service from which the Kafka event record originated."""
@@ -116,5 +120,20 @@ def records(self) -> Iterator[KafkaEventRecord]:
116120

117121
@property
118122
def record(self) -> KafkaEventRecord:
119-
"""The next Kafka record."""
120-
return next(self.records)
123+
"""
124+
Returns the next Kafka record using an iterator.
125+
126+
Returns
127+
-------
128+
KafkaEventRecord
129+
The next Kafka record.
130+
131+
Raises
132+
------
133+
StopIteration
134+
If there are no more records available.
135+
136+
"""
137+
if self._records is None:
138+
self._records = self.records
139+
return next(self._records)

tests/functional/data_classes/test_amazon_mq.py

-79
This file was deleted.

tests/functional/data_classes/test_lambda_function_url.py

-113
This file was deleted.

0 commit comments

Comments
 (0)