escape json string when sending message from sns mock to sqs mock
This commit is contained in:
parent
8fd5855bc9
commit
ccf4cf28b1
@ -81,7 +81,8 @@ class Subscription(BaseModel):
|
|||||||
if self.protocol == 'sqs':
|
if self.protocol == 'sqs':
|
||||||
queue_name = self.endpoint.split(":")[-1]
|
queue_name = self.endpoint.split(":")[-1]
|
||||||
region = self.endpoint.split(":")[3]
|
region = self.endpoint.split(":")[3]
|
||||||
sqs_backends[region].send_message(queue_name, message)
|
escaped_message = message.replace('"', '\\"')
|
||||||
|
sqs_backends[region].send_message(queue_name, escaped_message)
|
||||||
elif self.protocol in ['http', 'https']:
|
elif self.protocol in ['http', 'https']:
|
||||||
post_data = self.get_post_data(message, message_id)
|
post_data = self.get_post_data(message, message_id)
|
||||||
requests.post(self.endpoint, json=post_data)
|
requests.post(self.endpoint, json=post_data)
|
||||||
|
@ -34,6 +34,37 @@ def test_publish_to_sqs():
|
|||||||
messages[0].body.should.equal('my message')
|
messages[0].body.should.equal('my message')
|
||||||
|
|
||||||
|
|
||||||
|
@mock_sqs
|
||||||
|
@mock_sns
|
||||||
|
def test_publish_to_sqs_dump_json():
|
||||||
|
conn = boto3.client('sns', region_name='us-east-1')
|
||||||
|
conn.create_topic(Name="some-topic")
|
||||||
|
response = conn.list_topics()
|
||||||
|
topic_arn = response["Topics"][0]['TopicArn']
|
||||||
|
|
||||||
|
sqs_conn = boto3.resource('sqs', region_name='us-east-1')
|
||||||
|
sqs_conn.create_queue(QueueName="test-queue")
|
||||||
|
|
||||||
|
conn.subscribe(TopicArn=topic_arn,
|
||||||
|
Protocol="sqs",
|
||||||
|
Endpoint="arn:aws:sqs:us-east-1:123456789012:test-queue")
|
||||||
|
|
||||||
|
message = json.dumps({
|
||||||
|
"Records": [{
|
||||||
|
"eventVersion": "2.0",
|
||||||
|
"eventSource": "aws:s3",
|
||||||
|
"s3": {
|
||||||
|
"s3SchemaVersion": "1.0"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
conn.publish(TopicArn=topic_arn, Message=message)
|
||||||
|
queue = sqs_conn.get_queue_by_name(QueueName="test-queue")
|
||||||
|
messages = queue.receive_messages(MaxNumberOfMessages=1)
|
||||||
|
expected = '{\\"Records\\": [{\\"eventVersion\\": \\"2.0\\", \\"eventSource\\": \\"aws:s3\\", \\"s3\\": {\\"s3SchemaVersion\\": \\"1.0\\"}}]}'
|
||||||
|
messages[0].body.should.equal(expected)
|
||||||
|
|
||||||
|
|
||||||
@mock_sqs
|
@mock_sqs
|
||||||
@mock_sns
|
@mock_sns
|
||||||
def test_publish_to_sqs_in_different_region():
|
def test_publish_to_sqs_in_different_region():
|
||||||
|
Loading…
Reference in New Issue
Block a user