Merge pull request #97 from ossareh/master

support QueueNamePrefix in the SQS Backend
This commit is contained in:
Steve Pulec 2014-02-21 09:15:26 -05:00
commit f98d011c4f
4 changed files with 31 additions and 3 deletions

View File

@ -1,5 +1,6 @@
import hashlib
import time
import re
from moto.core import BaseBackend
from moto.core.utils import camelcase_to_underscores, get_random_message_id
@ -73,8 +74,16 @@ class SQSBackend(BaseBackend):
self.queues[name] = queue
return queue
def list_queues(self):
return self.queues.values()
def list_queues(self, queue_name_prefix):
re_str = '.*'
if queue_name_prefix:
re_str = '^{0}.*'.format(queue_name_prefix)
prefix_re = re.compile(re_str)
qs = []
for name, q in self.queues.items():
if prefix_re.search(name):
qs.append(q)
return qs
def get_queue(self, queue_name):
return self.queues.get(queue_name, None)

View File

@ -27,7 +27,8 @@ class QueuesResponse(BaseResponse):
return "", dict(status=404)
def list_queues(self):
queues = sqs_backend.list_queues()
queue_name_prefix = self.querystring.get("QueueNamePrefix", [None])[0]
queues = sqs_backend.list_queues(queue_name_prefix)
template = Template(LIST_QUEUES_RESPONSE)
return template.render(queues=queues)

View File

@ -16,6 +16,10 @@ def test_sqs_list_identities():
res.data.should.contain("ListQueuesResponse")
res = test_client.put('/?Action=CreateQueue&QueueName=testqueue')
res = test_client.put('/?Action=CreateQueue&QueueName=otherqueue')
res = test_client.get('/?Action=ListQueues&QueueNamePrefix=other')
res.data.should_not.contain('testqueue')
res = test_client.put(
'/123/testqueue?MessageBody=test-message&Action=SendMessage')

View File

@ -31,6 +31,20 @@ def test_get_queue():
nonexisting_queue.should.be.none
@mock_sqs
def test_get_queue_with_prefix():
conn = boto.connect_sqs('the_key', 'the_secret')
conn.create_queue("prefixa-queue")
conn.create_queue("prefixb-queue")
conn.create_queue("test-queue")
conn.get_all_queues().should.have.length_of(3)
queue = conn.get_all_queues("test-")
queue.should.have.length_of(1)
queue[0].name.should.equal("test-queue")
@mock_sqs
def test_delete_queue():
conn = boto.connect_sqs('the_key', 'the_secret')