Merge pull request #1574 from wblackconv/add-msg-attributes
Include SNS message attributes with message body when delivering to SQS.
This commit is contained in:
commit
f37bae5b57
4 changed files with 132 additions and 13 deletions
|
|
@ -2,8 +2,6 @@ from __future__ import unicode_literals
|
|||
|
||||
import json
|
||||
|
||||
from six.moves.urllib.parse import parse_qs
|
||||
|
||||
import boto3
|
||||
import re
|
||||
from freezegun import freeze_time
|
||||
|
|
@ -12,7 +10,6 @@ import sure # noqa
|
|||
import responses
|
||||
from botocore.exceptions import ClientError
|
||||
from moto import mock_sns, mock_sqs
|
||||
from freezegun import freeze_time
|
||||
|
||||
|
||||
MESSAGE_FROM_SQS_TEMPLATE = '{\n "Message": "%s",\n "MessageId": "%s",\n "Signature": "EXAMPLElDMXvB8r9R83tGoNn0ecwd5UjllzsvSvbItzfaMpN2nk5HVSw7XnOn/49IkxDKz8YrlH2qJXj2iZB0Zo2O71c4qQk1fMUDi3LGpij7RCW7AW9vYYsSqIKRnFS94ilu7NFhUzLiieYr4BKHpdTmdD6c0esKEYBpabxDSc=",\n "SignatureVersion": "1",\n "SigningCertURL": "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem",\n "Subject": "my subject",\n "Timestamp": "2015-01-01T12:00:00.000Z",\n "TopicArn": "arn:aws:sns:%s:123456789012:some-topic",\n "Type": "Notification",\n "UnsubscribeURL": "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:123456789012:some-topic:2bcfbf39-05c3-41de-beaa-fcfcc21c8f55"\n}'
|
||||
|
|
@ -176,7 +173,6 @@ def test_publish_to_http():
|
|||
|
||||
response = conn.publish(
|
||||
TopicArn=topic_arn, Message="my message", Subject="my subject")
|
||||
message_id = response['MessageId']
|
||||
|
||||
|
||||
@mock_sqs
|
||||
|
|
@ -239,6 +235,11 @@ def test_filtering_exact_string():
|
|||
messages = queue.receive_messages(MaxNumberOfMessages=5)
|
||||
message_bodies = [json.loads(m.body)['Message'] for m in messages]
|
||||
message_bodies.should.equal(['match'])
|
||||
message_attributes = [
|
||||
json.loads(m.body)['MessageAttributes'] for m in messages]
|
||||
message_attributes.should.equal(
|
||||
[{'store': {'Type': 'String', 'Value': 'example_corp'}}])
|
||||
|
||||
|
||||
@mock_sqs
|
||||
@mock_sns
|
||||
|
|
@ -256,6 +257,11 @@ def test_filtering_exact_string_multiple_message_attributes():
|
|||
messages = queue.receive_messages(MaxNumberOfMessages=5)
|
||||
message_bodies = [json.loads(m.body)['Message'] for m in messages]
|
||||
message_bodies.should.equal(['match'])
|
||||
message_attributes = [
|
||||
json.loads(m.body)['MessageAttributes'] for m in messages]
|
||||
message_attributes.should.equal([{
|
||||
'store': {'Type': 'String', 'Value': 'example_corp'},
|
||||
'event': {'Type': 'String', 'Value': 'order_cancelled'}}])
|
||||
|
||||
@mock_sqs
|
||||
@mock_sns
|
||||
|
|
@ -275,6 +281,11 @@ def test_filtering_exact_string_OR_matching():
|
|||
message_bodies = [json.loads(m.body)['Message'] for m in messages]
|
||||
message_bodies.should.equal(
|
||||
['match example_corp', 'match different_corp'])
|
||||
message_attributes = [
|
||||
json.loads(m.body)['MessageAttributes'] for m in messages]
|
||||
message_attributes.should.equal([
|
||||
{'store': {'Type': 'String', 'Value': 'example_corp'}},
|
||||
{'store': {'Type': 'String', 'Value': 'different_corp'}}])
|
||||
|
||||
@mock_sqs
|
||||
@mock_sns
|
||||
|
|
@ -294,6 +305,11 @@ def test_filtering_exact_string_AND_matching_positive():
|
|||
message_bodies = [json.loads(m.body)['Message'] for m in messages]
|
||||
message_bodies.should.equal(
|
||||
['match example_corp order_cancelled'])
|
||||
message_attributes = [
|
||||
json.loads(m.body)['MessageAttributes'] for m in messages]
|
||||
message_attributes.should.equal([{
|
||||
'store': {'Type': 'String', 'Value': 'example_corp'},
|
||||
'event': {'Type': 'String', 'Value': 'order_cancelled'}}])
|
||||
|
||||
@mock_sqs
|
||||
@mock_sns
|
||||
|
|
@ -312,7 +328,9 @@ def test_filtering_exact_string_AND_matching_no_match():
|
|||
messages = queue.receive_messages(MaxNumberOfMessages=5)
|
||||
message_bodies = [json.loads(m.body)['Message'] for m in messages]
|
||||
message_bodies.should.equal([])
|
||||
|
||||
message_attributes = [
|
||||
json.loads(m.body)['MessageAttributes'] for m in messages]
|
||||
message_attributes.should.equal([])
|
||||
|
||||
@mock_sqs
|
||||
@mock_sns
|
||||
|
|
@ -328,6 +346,9 @@ def test_filtering_exact_string_no_match():
|
|||
messages = queue.receive_messages(MaxNumberOfMessages=5)
|
||||
message_bodies = [json.loads(m.body)['Message'] for m in messages]
|
||||
message_bodies.should.equal([])
|
||||
message_attributes = [
|
||||
json.loads(m.body)['MessageAttributes'] for m in messages]
|
||||
message_attributes.should.equal([])
|
||||
|
||||
@mock_sqs
|
||||
@mock_sns
|
||||
|
|
@ -340,3 +361,6 @@ def test_filtering_exact_string_no_attributes_no_match():
|
|||
messages = queue.receive_messages(MaxNumberOfMessages=5)
|
||||
message_bodies = [json.loads(m.body)['Message'] for m in messages]
|
||||
message_bodies.should.equal([])
|
||||
message_attributes = [
|
||||
json.loads(m.body)['MessageAttributes'] for m in messages]
|
||||
message_attributes.should.equal([])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue