| Index: third_party/boto/tests/unit/sqs/test_connection.py
|
| ===================================================================
|
| --- third_party/boto/tests/unit/sqs/test_connection.py (revision 33376)
|
| +++ third_party/boto/tests/unit/sqs/test_connection.py (working copy)
|
| @@ -1,5 +1,6 @@
|
| #!/usr/bin/env python
|
| # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved
|
| +# Copyright (c) 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved
|
| #
|
| # Permission is hereby granted, free of charge, to any person obtaining a
|
| # copy of this software and associated documentation files (the
|
| @@ -26,6 +27,8 @@
|
|
|
| from boto.sqs.connection import SQSConnection
|
| from boto.sqs.regioninfo import SQSRegionInfo
|
| +from boto.sqs.message import RawMessage
|
| +from boto.sqs.queue import Queue
|
|
|
|
|
| class SQSAuthParams(AWSMockServiceTestCase):
|
| @@ -104,7 +107,172 @@
|
|
|
| assert 'QueueOwnerAWSAccountId' in self.actual_request.params.keys()
|
| self.assertEquals(self.actual_request.params['QueueOwnerAWSAccountId'], '599169622985')
|
| -
|
|
|
| +
|
| +class SQSMessageAttributesParsing(AWSMockServiceTestCase):
|
| + connection_class = SQSConnection
|
| +
|
| + def default_body(self):
|
| + return """<?xml version="1.0"?>
|
| +<ReceiveMessageResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/">
|
| + <ReceiveMessageResult>
|
| + <Message>
|
| + <Body>This is a test</Body>
|
| + <ReceiptHandle>+eXJYhj5rDql5hp2VwGkXvQVsefdjAlsQe5EGS57gyORPB48KwP1d/3Rfy4DrQXt+MgfRPHUCUH36xL9+Ol/UWD/ylKrrWhiXSY0Ip4EsI8jJNTo/aneEjKE/iZnz/nL8MFP5FmMj8PbDAy5dgvAqsdvX1rm8Ynn0bGnQLJGfH93cLXT65p6Z/FDyjeBN0M+9SWtTcuxOIcMdU8NsoFIwm/6mLWgWAV46OhlYujzvyopCvVwsj+Y8jLEpdSSvTQHNlQEaaY/V511DqAvUwru2p0ZbW7ZzcbhUTn6hHkUROo=</ReceiptHandle>
|
| + <MD5OfBody>ce114e4501d2f4e2dcea3e17b546f339</MD5OfBody>
|
| + <MessageAttribute>
|
| + <Name>Count</Name>
|
| + <Value>
|
| + <DataType>Number</DataType>
|
| + <StringValue>1</StringValue>
|
| + </Value>
|
| + </MessageAttribute>
|
| + <MessageAttribute>
|
| + <Name>Foo</Name>
|
| + <Value>
|
| + <DataType>String</DataType>
|
| + <StringValue>Bar</StringValue>
|
| + </Value>
|
| + </MessageAttribute>
|
| + <MessageId>7049431b-e5f6-430b-93c4-ded53864d02b</MessageId>
|
| + <MD5OfMessageAttributes>324758f82d026ac6ec5b31a3b192d1e3</MD5OfMessageAttributes>
|
| + </Message>
|
| + </ReceiveMessageResult>
|
| + <ResponseMetadata>
|
| + <RequestId>73f978f2-400b-5460-8d38-3316e39e79c6</RequestId>
|
| + </ResponseMetadata>
|
| +</ReceiveMessageResponse>"""
|
| +
|
| + def test_message_attribute_response(self):
|
| + self.set_http_response(status_code=200)
|
| +
|
| + queue = Queue(
|
| + url='http://sqs.us-east-1.amazonaws.com/123456789012/testQueue/',
|
| + message_class=RawMessage)
|
| + message = self.service_connection.receive_message(queue)[0]
|
| +
|
| + self.assertEqual(message.get_body(), 'This is a test')
|
| + self.assertEqual(message.id, '7049431b-e5f6-430b-93c4-ded53864d02b')
|
| + self.assertEqual(message.md5, 'ce114e4501d2f4e2dcea3e17b546f339')
|
| + self.assertEqual(message.md5_message_attributes,
|
| + '324758f82d026ac6ec5b31a3b192d1e3')
|
| +
|
| + mattributes = message.message_attributes
|
| + self.assertEqual(len(mattributes.keys()), 2)
|
| + self.assertEqual(mattributes['Count']['data_type'], 'Number')
|
| + self.assertEqual(mattributes['Foo']['string_value'], 'Bar')
|
| +
|
| +
|
| +class SQSSendMessageAttributes(AWSMockServiceTestCase):
|
| + connection_class = SQSConnection
|
| +
|
| + def default_body(self):
|
| + return """<SendMessageResponse>
|
| + <SendMessageResult>
|
| + <MD5OfMessageBody>
|
| + fafb00f5732ab283681e124bf8747ed1
|
| + </MD5OfMessageBody>
|
| + <MD5OfMessageAttributes>
|
| + 3ae8f24a165a8cedc005670c81a27295
|
| + </MD5OfMessageAttributes>
|
| + <MessageId>
|
| + 5fea7756-0ea4-451a-a703-a558b933e274
|
| + </MessageId>
|
| + </SendMessageResult>
|
| + <ResponseMetadata>
|
| + <RequestId>
|
| + 27daac76-34dd-47df-bd01-1f6e873584a0
|
| + </RequestId>
|
| + </ResponseMetadata>
|
| +</SendMessageResponse>
|
| +"""
|
| +
|
| + def test_send_message_attributes(self):
|
| + self.set_http_response(status_code=200)
|
| +
|
| + queue = Queue(
|
| + url='http://sqs.us-east-1.amazonaws.com/123456789012/testQueue/',
|
| + message_class=RawMessage)
|
| + self.service_connection.send_message(queue, 'Test message',
|
| + message_attributes={
|
| + 'name1': {
|
| + 'data_type': 'String',
|
| + 'string_value': 'Bob'
|
| + },
|
| + 'name2': {
|
| + 'data_type': 'Number',
|
| + 'string_value': '1'
|
| + }
|
| + })
|
| +
|
| + self.assert_request_parameters({
|
| + 'Action': 'SendMessage',
|
| + 'MessageAttribute.1.Name': 'name2',
|
| + 'MessageAttribute.1.Value.DataType': 'Number',
|
| + 'MessageAttribute.1.Value.StringValue': '1',
|
| + 'MessageAttribute.2.Name': 'name1',
|
| + 'MessageAttribute.2.Value.DataType': 'String',
|
| + 'MessageAttribute.2.Value.StringValue': 'Bob',
|
| + 'MessageBody': 'Test message',
|
| + 'Version': '2012-11-05'
|
| + })
|
| +
|
| +
|
| +class SQSSendBatchMessageAttributes(AWSMockServiceTestCase):
|
| + connection_class = SQSConnection
|
| +
|
| + def default_body(self):
|
| + return """<SendMessageBatchResponse>
|
| +<SendMessageBatchResult>
|
| + <SendMessageBatchResultEntry>
|
| + <Id>test_msg_001</Id>
|
| + <MessageId>0a5231c7-8bff-4955-be2e-8dc7c50a25fa</MessageId>
|
| + <MD5OfMessageBody>0e024d309850c78cba5eabbeff7cae71</MD5OfMessageBody>
|
| + </SendMessageBatchResultEntry>
|
| + <SendMessageBatchResultEntry>
|
| + <Id>test_msg_002</Id>
|
| + <MessageId>15ee1ed3-87e7-40c1-bdaa-2e49968ea7e9</MessageId>
|
| + <MD5OfMessageBody>7fb8146a82f95e0af155278f406862c2</MD5OfMessageBody>
|
| + <MD5OfMessageAttributes>295c5fa15a51aae6884d1d7c1d99ca50</MD5OfMessageAttributes>
|
| + </SendMessageBatchResultEntry>
|
| +</SendMessageBatchResult>
|
| +<ResponseMetadata>
|
| + <RequestId>ca1ad5d0-8271-408b-8d0f-1351bf547e74</RequestId>
|
| +</ResponseMetadata>
|
| +</SendMessageBatchResponse>
|
| +"""
|
| +
|
| + def test_send_message_attributes(self):
|
| + self.set_http_response(status_code=200)
|
| +
|
| + queue = Queue(
|
| + url='http://sqs.us-east-1.amazonaws.com/123456789012/testQueue/',
|
| + message_class=RawMessage)
|
| +
|
| + message1 = (1, 'Message 1', 0, {'name1': {'data_type': 'String',
|
| + 'string_value': 'foo'}})
|
| + message2 = (2, 'Message 2', 0, {'name2': {'data_type': 'Number',
|
| + 'string_value': '1'}})
|
| +
|
| + self.service_connection.send_message_batch(queue, (message1, message2))
|
| +
|
| + self.assert_request_parameters({
|
| + 'Action': 'SendMessageBatch',
|
| + 'SendMessageBatchRequestEntry.1.DelaySeconds': 0,
|
| + 'SendMessageBatchRequestEntry.1.Id': 1,
|
| + 'SendMessageBatchRequestEntry.1.MessageAttribute.1.DataType': 'String',
|
| + 'SendMessageBatchRequestEntry.1.MessageAttribute.1.Name': 'name1',
|
| + 'SendMessageBatchRequestEntry.1.MessageAttribute.1.StringValue': 'foo',
|
| + 'SendMessageBatchRequestEntry.1.MessageBody': 'Message 1',
|
| + 'SendMessageBatchRequestEntry.2.DelaySeconds': 0,
|
| + 'SendMessageBatchRequestEntry.2.Id': 2,
|
| + 'SendMessageBatchRequestEntry.2.MessageAttribute.1.DataType': 'Number',
|
| + 'SendMessageBatchRequestEntry.2.MessageAttribute.1.Name': 'name2',
|
| + 'SendMessageBatchRequestEntry.2.MessageAttribute.1.StringValue': '1',
|
| + 'SendMessageBatchRequestEntry.2.MessageBody': 'Message 2',
|
| + 'Version': '2012-11-05'
|
| + })
|
| +
|
| +
|
| if __name__ == '__main__':
|
| unittest.main()
|
|
|