Strip extra whitespace and newlines from SQS response templates.

Fixes #623
This commit is contained in:
Nuno Santos 2016-06-02 11:18:40 +02:00
parent 4372c346d9
commit 68eeb5948b
3 changed files with 18 additions and 31 deletions

View File

@ -81,7 +81,8 @@ class _TemplateEnvironmentMixin(object):
template_id = id(source) template_id = id(source)
if not self.contains_template(template_id): if not self.contains_template(template_id):
self.loader.update({template_id: source}) self.loader.update({template_id: source})
self.environment = Environment(loader=self.loader, autoescape=self.should_autoescape) self.environment = Environment(loader=self.loader, autoescape=self.should_autoescape, trim_blocks=True,
lstrip_blocks=True)
return self.environment.get_template(template_id) return self.environment.get_template(template_id)

View File

@ -245,9 +245,7 @@ CREATE_QUEUE_RESPONSE = """<CreateQueueResponse>
<VisibilityTimeout>{{ queue.visibility_timeout }}</VisibilityTimeout> <VisibilityTimeout>{{ queue.visibility_timeout }}</VisibilityTimeout>
</CreateQueueResult> </CreateQueueResult>
<ResponseMetadata> <ResponseMetadata>
<RequestId> <RequestId>7a62c49f-347e-4fc4-9331-6e8e7a96aa73</RequestId>
7a62c49f-347e-4fc4-9331-6e8e7a96aa73
</RequestId>
</ResponseMetadata> </ResponseMetadata>
</CreateQueueResponse>""" </CreateQueueResponse>"""
@ -267,17 +265,13 @@ LIST_QUEUES_RESPONSE = """<ListQueuesResponse>
{% endfor %} {% endfor %}
</ListQueuesResult> </ListQueuesResult>
<ResponseMetadata> <ResponseMetadata>
<RequestId> <RequestId>725275ae-0b9b-4762-b238-436d7c65a1ac</RequestId>
725275ae-0b9b-4762-b238-436d7c65a1ac
</RequestId>
</ResponseMetadata> </ResponseMetadata>
</ListQueuesResponse>""" </ListQueuesResponse>"""
DELETE_QUEUE_RESPONSE = """<DeleteQueueResponse> DELETE_QUEUE_RESPONSE = """<DeleteQueueResponse>
<ResponseMetadata> <ResponseMetadata>
<RequestId> <RequestId>6fde8d1e-52cd-4581-8cd9-c512f4c64223</RequestId>
6fde8d1e-52cd-4581-8cd9-c512f4c64223
</RequestId>
</ResponseMetadata> </ResponseMetadata>
</DeleteQueueResponse>""" </DeleteQueueResponse>"""
@ -297,28 +291,24 @@ GET_QUEUE_ATTRIBUTES_RESPONSE = """<GetQueueAttributesResponse>
SET_QUEUE_ATTRIBUTE_RESPONSE = """<SetQueueAttributesResponse> SET_QUEUE_ATTRIBUTE_RESPONSE = """<SetQueueAttributesResponse>
<ResponseMetadata> <ResponseMetadata>
<RequestId> <RequestId>e5cca473-4fc0-4198-a451-8abb94d02c75</RequestId>
e5cca473-4fc0-4198-a451-8abb94d02c75
</RequestId>
</ResponseMetadata> </ResponseMetadata>
</SetQueueAttributesResponse>""" </SetQueueAttributesResponse>"""
SEND_MESSAGE_RESPONSE = """<SendMessageResponse> SEND_MESSAGE_RESPONSE = """<SendMessageResponse>
<SendMessageResult> <SendMessageResult>
<MD5OfMessageBody> <MD5OfMessageBody>
{{ message.md5 }} {{- message.md5 -}}
</MD5OfMessageBody> </MD5OfMessageBody>
{% if message.message_attributes.items()|count > 0 %} {% if message.message_attributes.items()|count > 0 %}
<MD5OfMessageAttributes>324758f82d026ac6ec5b31a3b192d1e3</MD5OfMessageAttributes> <MD5OfMessageAttributes>324758f82d026ac6ec5b31a3b192d1e3</MD5OfMessageAttributes>
{% endif %} {% endif %}
<MessageId> <MessageId>
{{ message.id }} {{- message.id -}}
</MessageId> </MessageId>
</SendMessageResult> </SendMessageResult>
<ResponseMetadata> <ResponseMetadata>
<RequestId> <RequestId>27daac76-34dd-47df-bd01-1f6e873584a0</RequestId>
27daac76-34dd-47df-bd01-1f6e873584a0
</RequestId>
</ResponseMetadata> </ResponseMetadata>
</SendMessageResponse>""" </SendMessageResponse>"""
@ -366,9 +356,7 @@ RECEIVE_MESSAGE_RESPONSE = """<ReceiveMessageResponse>
{% endfor %} {% endfor %}
</ReceiveMessageResult> </ReceiveMessageResult>
<ResponseMetadata> <ResponseMetadata>
<RequestId> <RequestId>b6633655-283d-45b4-aee4-4e84e0ae6afa</RequestId>
b6633655-283d-45b4-aee4-4e84e0ae6afa
</RequestId>
</ResponseMetadata> </ResponseMetadata>
</ReceiveMessageResponse>""" </ReceiveMessageResponse>"""
@ -392,9 +380,7 @@ SEND_MESSAGE_BATCH_RESPONSE = """<SendMessageBatchResponse>
DELETE_MESSAGE_RESPONSE = """<DeleteMessageResponse> DELETE_MESSAGE_RESPONSE = """<DeleteMessageResponse>
<ResponseMetadata> <ResponseMetadata>
<RequestId> <RequestId>b5293cb5-d306-4a17-9048-b263635abe42</RequestId>
b5293cb5-d306-4a17-9048-b263635abe42
</RequestId>
</ResponseMetadata> </ResponseMetadata>
</DeleteMessageResponse>""" </DeleteMessageResponse>"""
@ -413,17 +399,13 @@ DELETE_MESSAGE_BATCH_RESPONSE = """<DeleteMessageBatchResponse>
CHANGE_MESSAGE_VISIBILITY_RESPONSE = """<ChangeMessageVisibilityResponse> CHANGE_MESSAGE_VISIBILITY_RESPONSE = """<ChangeMessageVisibilityResponse>
<ResponseMetadata> <ResponseMetadata>
<RequestId> <RequestId>6a7a282a-d013-4a59-aba9-335b0fa48bed</RequestId>
6a7a282a-d013-4a59-aba9-335b0fa48bed
</RequestId>
</ResponseMetadata> </ResponseMetadata>
</ChangeMessageVisibilityResponse>""" </ChangeMessageVisibilityResponse>"""
PURGE_QUEUE_RESPONSE = """<PurgeQueueResponse> PURGE_QUEUE_RESPONSE = """<PurgeQueueResponse>
<ResponseMetadata> <ResponseMetadata>
<RequestId> <RequestId>6fde8d1e-52cd-4581-8cd9-c512f4c64223</RequestId>
6fde8d1e-52cd-4581-8cd9-c512f4c64223
</RequestId>
</ResponseMetadata> </ResponseMetadata>
</PurgeQueueResponse>""" </PurgeQueueResponse>"""

View File

@ -487,7 +487,11 @@ boto3
def test_boto3_message_send(): def test_boto3_message_send():
sqs = boto3.resource('sqs', region_name='us-east-1') sqs = boto3.resource('sqs', region_name='us-east-1')
queue = sqs.create_queue(QueueName="blah") queue = sqs.create_queue(QueueName="blah")
queue.send_message(MessageBody="derp") msg = queue.send_message(MessageBody="derp")
msg.get('MD5OfMessageBody').should.equal('58fd9edd83341c29f1aebba81c31e257')
msg.get('ResponseMetadata', {}).get('RequestId').should.equal('27daac76-34dd-47df-bd01-1f6e873584a0')
msg.get('MessageId').should_not.contain(' \n')
messages = queue.receive_messages() messages = queue.receive_messages()
messages.should.have.length_of(1) messages.should.have.length_of(1)