fixes to sqs encoding. Closes #4.
This commit is contained in:
parent
a53f5c6730
commit
b03d48e6bc
@ -1,4 +1,3 @@
|
||||
import base64
|
||||
import md5
|
||||
|
||||
from moto.core import BaseBackend
|
||||
@ -9,7 +8,7 @@ from .utils import generate_receipt_handle
|
||||
class Message(object):
|
||||
def __init__(self, message_id, body):
|
||||
self.id = message_id
|
||||
self._body = body
|
||||
self.body = body
|
||||
self.receipt_handle = generate_receipt_handle()
|
||||
|
||||
@property
|
||||
@ -18,11 +17,6 @@ class Message(object):
|
||||
body_md5.update(self.body)
|
||||
return body_md5.hexdigest()
|
||||
|
||||
@property
|
||||
def body(self):
|
||||
# SQS Message bodies are base64 encoded by default
|
||||
return base64.b64encode(self._body)
|
||||
|
||||
|
||||
class Queue(object):
|
||||
camelcase_attributes = ['VisibilityTimeout', 'ApproximateNumberOfMessages']
|
||||
|
@ -1,4 +1,3 @@
|
||||
import base64
|
||||
import re
|
||||
import sure # flake8: noqa
|
||||
|
||||
@ -10,7 +9,7 @@ Test the different server responses
|
||||
server.configure_urls("sqs")
|
||||
|
||||
|
||||
def test_ses_list_identities():
|
||||
def test_sqs_list_identities():
|
||||
test_client = server.app.test_client()
|
||||
res = test_client.get('/?Action=ListQueues')
|
||||
res.data.should.contain("ListQueuesResponse")
|
||||
@ -23,4 +22,4 @@ def test_ses_list_identities():
|
||||
res = test_client.get(
|
||||
'/123/testqueue?Action=ReceiveMessage&MaxNumberOfMessages=1')
|
||||
message = re.search("<Body>(.*?)</Body>", res.data).groups()[0]
|
||||
base64.decodestring(message).should.equal('test-message')
|
||||
message.should.equal('test-message')
|
||||
|
@ -1,5 +1,6 @@
|
||||
import boto
|
||||
from boto.exception import SQSError
|
||||
from boto.sqs.message import RawMessage
|
||||
import requests
|
||||
import sure # flake8: noqa
|
||||
|
||||
@ -55,6 +56,15 @@ def test_send_message():
|
||||
messages[0].get_body().should.equal('this is a test message')
|
||||
|
||||
|
||||
@mock_sqs
|
||||
def test_read_message_from_queue():
|
||||
conn = boto.connect_sqs()
|
||||
queue = conn.create_queue('testqueue')
|
||||
queue.write(queue.new_message('foo bar baz'))
|
||||
message = queue.read(1)
|
||||
message.get_body().should.equal('foo bar baz')
|
||||
|
||||
|
||||
@mock_sqs
|
||||
def test_queue_length():
|
||||
conn = boto.connect_sqs('the_key', 'the_secret')
|
||||
@ -84,7 +94,10 @@ def test_send_batch_operation():
|
||||
conn = boto.connect_sqs('the_key', 'the_secret')
|
||||
queue = conn.create_queue("test-queue", visibility_timeout=60)
|
||||
|
||||
conn.send_message_batch(queue, [
|
||||
# See https://github.com/boto/boto/issues/831
|
||||
queue.set_message_class(RawMessage)
|
||||
|
||||
queue.write_batch([
|
||||
("my_first_message", 'test message 1', 0),
|
||||
("my_second_message", 'test message 2', 0),
|
||||
("my_third_message", 'test message 3', 0),
|
||||
|
Loading…
Reference in New Issue
Block a user