Skip to content

Commit 2fa40f4

Browse files
author
Amit Shah
committed
Add basic test for extracting results from s3
1 parent 2d1f691 commit 2fa40f4

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

kombu/transport/SQS.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,8 @@ def _message_to_python(self, message, queue_name, q_url):
514514

515515
# The message body is under a wrapper class called StreamingBody
516516
streaming_body = response["Body"]
517-
payload = json.loads(
518-
self._optional_b64_decode(streaming_body.read())
519-
)
517+
body = self._optional_b64_decode(streaming_body.read())
518+
payload = json.loads(body)
520519

521520
try:
522521
properties = payload['properties']

t/unit/transport/test_SQS.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77
from __future__ import annotations
88

99
import base64
10+
import json
1011
import os
1112
import random
1213
import string
1314
from datetime import datetime, timedelta
15+
from io import BytesIO
1416
from queue import Empty
1517
from unittest.mock import Mock, patch
1618

1719
import pytest
20+
import sqs_extended_client
1821

1922
from kombu import Connection, Exchange, Queue, messaging
2023

@@ -1007,3 +1010,30 @@ def test_message_attribute(self):
10071010
assert message == output_message.payload
10081011
# It's not propagated to the properties
10091012
assert 'message_attributes' not in output_message.properties
1013+
1014+
def test_message_to_python_with_sqs_extended_client(self):
1015+
message = [
1016+
sqs_extended_client.client.MESSAGE_POINTER_CLASS,
1017+
{'s3BucketName': 's3://large-payload-bucket', 's3Key': 'payload.json'}
1018+
]
1019+
1020+
# Get the messages now
1021+
with patch('kombu.transport.SQS.Channel.s3') as s3_mock:
1022+
s3_client = Mock(
1023+
get_object=Mock(
1024+
return_value={'Body': BytesIO(json.dumps({"my_key": "Hello, World!"}).encode()), })
1025+
)
1026+
s3_mock.return_value = s3_client
1027+
1028+
result = self.channel._message_to_python(
1029+
{'Body': json.dumps(message), 'ReceiptHandle': 'handle'}, self.queue_name,
1030+
'test',
1031+
)
1032+
1033+
assert s3_client.get_object.called
1034+
1035+
# Make sure they're payload-style objects
1036+
assert 'properties' in result
1037+
1038+
# Data from s3 is loaded into the return payload
1039+
assert 'my_key' in result

0 commit comments

Comments
 (0)