forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassert_transformation.py
More file actions
36 lines (28 loc) · 1020 Bytes
/
assert_transformation.py
File metadata and controls
36 lines (28 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import io
import boto3
from assert_transformation_module import UpperTransform
from botocore import stub
from aws_lambda_powertools.utilities.streaming import S3Object
from aws_lambda_powertools.utilities.streaming.compat import PowertoolsStreamingBody
def test_upper_transform():
# GIVEN
data_stream = io.BytesIO(b"hello world")
# WHEN
data_stream = UpperTransform().transform(data_stream)
# THEN
assert data_stream.read() == b"HELLO WORLD"
def test_s3_object_with_upper_transform():
# GIVEN
payload = b"hello world"
s3_client = boto3.client("s3")
s3_stub = stub.Stubber(s3_client)
s3_stub.add_response(
"get_object",
{"Body": PowertoolsStreamingBody(raw_stream=io.BytesIO(payload), content_length=len(payload))},
)
s3_stub.activate()
# WHEN
data_stream = S3Object(bucket="bucket", key="key", boto3_client=s3_client)
data_stream.transform(UpperTransform(), in_place=True)
# THEN
assert data_stream.read() == b"HELLO WORLD"