use proper message encoding
This commit is contained in:
parent
a9ef2eaaf4
commit
ca6a9bad4f
@ -26,12 +26,6 @@ class Message(object):
|
||||
self.visible_at = 0
|
||||
self.delayed_until = 0
|
||||
|
||||
@property
|
||||
def body_base64(self):
|
||||
if len(self.body) >= 27:
|
||||
return base64.b64encode(self.body)
|
||||
return self.body
|
||||
|
||||
@property
|
||||
def md5(self):
|
||||
body_md5 = hashlib.md5()
|
||||
|
@ -269,7 +269,7 @@ RECEIVE_MESSAGE_RESPONSE = """<ReceiveMessageResponse>
|
||||
<MessageId>{{ message.id }}</MessageId>
|
||||
<ReceiptHandle>{{ message.receipt_handle }}</ReceiptHandle>
|
||||
<MD5OfBody>{{ message.md5 }}</MD5OfBody>
|
||||
<Body>{{ message.body_base64 }}</Body>
|
||||
<Body>{{ message.body }}</Body>
|
||||
<Attribute>
|
||||
<Name>SenderId</Name>
|
||||
<Value>{{ message.sender_id }}</Value>
|
||||
|
@ -77,29 +77,38 @@ def test_set_queue_attribute():
|
||||
def test_send_message():
|
||||
conn = boto.connect_sqs('the_key', 'the_secret')
|
||||
queue = conn.create_queue("test-queue", visibility_timeout=60)
|
||||
queue.set_message_class(RawMessage)
|
||||
|
||||
conn.send_message(queue, 'this is a test message')
|
||||
conn.send_message(queue, 'this is another test message')
|
||||
body_one = 'this is a test message'
|
||||
body_two = 'this is another test message'
|
||||
|
||||
queue.write(queue.new_message(body_one))
|
||||
queue.write(queue.new_message(body_two))
|
||||
|
||||
messages = conn.receive_message(queue, number_messages=2)
|
||||
messages[0].get_body().should.equal('this is a test message')
|
||||
messages[1].get_body().should.equal('this is another test message')
|
||||
|
||||
messages[0].get_body().should.equal(body_one)
|
||||
messages[1].get_body().should.equal(body_two)
|
||||
|
||||
|
||||
@mock_sqs
|
||||
def test_send_message_with_delay():
|
||||
conn = boto.connect_sqs('the_key', 'the_secret')
|
||||
queue = conn.create_queue("test-queue", visibility_timeout=60)
|
||||
queue.set_message_class(RawMessage)
|
||||
|
||||
conn.send_message(queue, 'this is a test message', delay_seconds=60)
|
||||
conn.send_message(queue, 'this is another test message')
|
||||
body_one = 'this is a test message'
|
||||
body_two = 'this is another test message'
|
||||
|
||||
queue.write(queue.new_message(body_one), delay_seconds=60)
|
||||
queue.write(queue.new_message(body_two))
|
||||
|
||||
queue.count().should.equal(1)
|
||||
|
||||
messages = conn.receive_message(queue, number_messages=2)
|
||||
assert len(messages) == 1
|
||||
message = messages[0]
|
||||
assert message.get_body().should.equal('this is another test message')
|
||||
assert message.get_body().should.equal(body_two)
|
||||
queue.count().should.equal(0)
|
||||
|
||||
|
||||
@ -107,8 +116,10 @@ def test_send_message_with_delay():
|
||||
def test_message_becomes_inflight_when_received():
|
||||
conn = boto.connect_sqs('the_key', 'the_secret')
|
||||
queue = conn.create_queue("test-queue", visibility_timeout=2)
|
||||
queue.set_message_class(RawMessage)
|
||||
|
||||
conn.send_message(queue, 'this is another test message')
|
||||
body_one = 'this is a test message'
|
||||
queue.write(queue.new_message(body_one))
|
||||
queue.count().should.equal(1)
|
||||
|
||||
messages = conn.receive_message(queue, number_messages=1)
|
||||
@ -126,8 +137,11 @@ def test_message_becomes_inflight_when_received():
|
||||
def test_change_message_visibility():
|
||||
conn = boto.connect_sqs('the_key', 'the_secret')
|
||||
queue = conn.create_queue("test-queue", visibility_timeout=2)
|
||||
queue.set_message_class(RawMessage)
|
||||
|
||||
body_one = 'this is another test message'
|
||||
queue.write(queue.new_message(body_one))
|
||||
|
||||
conn.send_message(queue, 'this is another test message')
|
||||
queue.count().should.equal(1)
|
||||
messages = conn.receive_message(queue, number_messages=1)
|
||||
|
||||
@ -157,8 +171,11 @@ def test_change_message_visibility():
|
||||
def test_message_attributes():
|
||||
conn = boto.connect_sqs('the_key', 'the_secret')
|
||||
queue = conn.create_queue("test-queue", visibility_timeout=2)
|
||||
queue.set_message_class(RawMessage)
|
||||
|
||||
body_one = 'this is another test message'
|
||||
queue.write(queue.new_message(body_one))
|
||||
|
||||
conn.send_message(queue, 'this is another test message')
|
||||
queue.count().should.equal(1)
|
||||
|
||||
messages = conn.receive_message(queue, number_messages=1)
|
||||
@ -178,18 +195,22 @@ def test_message_attributes():
|
||||
def test_read_message_from_queue():
|
||||
conn = boto.connect_sqs()
|
||||
queue = conn.create_queue('testqueue')
|
||||
queue.write(queue.new_message('foo bar baz'))
|
||||
queue.set_message_class(RawMessage)
|
||||
|
||||
body = 'foo bar baz'
|
||||
queue.write(queue.new_message(body))
|
||||
message = queue.read(1)
|
||||
message.get_body().should.equal('foo bar baz')
|
||||
message.get_body().should.equal(body)
|
||||
|
||||
|
||||
@mock_sqs
|
||||
def test_queue_length():
|
||||
conn = boto.connect_sqs('the_key', 'the_secret')
|
||||
queue = conn.create_queue("test-queue", visibility_timeout=60)
|
||||
queue.set_message_class(RawMessage)
|
||||
|
||||
conn.send_message(queue, 'this is a test message')
|
||||
conn.send_message(queue, 'this is another test message')
|
||||
queue.write(queue.new_message('this is a test message'))
|
||||
queue.write(queue.new_message('this is another test message'))
|
||||
queue.count().should.equal(2)
|
||||
|
||||
|
||||
@ -197,9 +218,10 @@ def test_queue_length():
|
||||
def test_delete_message():
|
||||
conn = boto.connect_sqs('the_key', 'the_secret')
|
||||
queue = conn.create_queue("test-queue", visibility_timeout=60)
|
||||
queue.set_message_class(RawMessage)
|
||||
|
||||
conn.send_message(queue, 'this is a test message')
|
||||
conn.send_message(queue, 'this is another test message')
|
||||
queue.write(queue.new_message('this is a test message'))
|
||||
queue.write(queue.new_message('this is another test message'))
|
||||
queue.count().should.equal(2)
|
||||
|
||||
messages = conn.receive_message(queue, number_messages=1)
|
||||
@ -290,8 +312,9 @@ def test_queue_attributes():
|
||||
def test_change_message_visibility_on_invalid_receipt():
|
||||
conn = boto.connect_sqs('the_key', 'the_secret')
|
||||
queue = conn.create_queue("test-queue", visibility_timeout=1)
|
||||
queue.set_message_class(RawMessage)
|
||||
|
||||
conn.send_message(queue, 'this is another test message')
|
||||
queue.write(queue.new_message('this is another test message'))
|
||||
queue.count().should.equal(1)
|
||||
messages = conn.receive_message(queue, number_messages=1)
|
||||
|
||||
@ -316,8 +339,9 @@ def test_change_message_visibility_on_invalid_receipt():
|
||||
def test_change_message_visibility_on_visible_message():
|
||||
conn = boto.connect_sqs('the_key', 'the_secret')
|
||||
queue = conn.create_queue("test-queue", visibility_timeout=1)
|
||||
queue.set_message_class(RawMessage)
|
||||
|
||||
conn.send_message(queue, 'this is another test message')
|
||||
queue.write(queue.new_message('this is another test message'))
|
||||
queue.count().should.equal(1)
|
||||
messages = conn.receive_message(queue, number_messages=1)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user