Add SQS purge_queue action. Closes #349.

This commit is contained in:
Steve Pulec 2015-05-29 23:21:14 -04:00
parent 55f36a3a43
commit 6b44e41249
3 changed files with 32 additions and 0 deletions

View File

@ -274,6 +274,11 @@ class SQSBackend(BaseBackend):
return
raise ReceiptHandleIsInvalid
def purge_queue(self, queue_name):
queue = self.get_queue(queue_name)
queue._messages = []
sqs_backends = {}
for region in boto.sqs.regions():
sqs_backends[region.name] = SQSBackend()

View File

@ -200,6 +200,12 @@ class QueueResponse(BaseResponse):
template = self.response_template(DELETE_MESSAGE_BATCH_RESPONSE)
return template.render(message_ids=message_ids)
def purge_queue(self):
queue_name = self.path.split("/")[-1]
self.sqs_backend.purge_queue(queue_name)
template = self.response_template(PURGE_QUEUE_RESPONSE)
return template.render()
def receive_message(self):
queue_name = self.path.split("/")[-1]
message_count = int(self.querystring.get("MaxNumberOfMessages")[0])
@ -389,3 +395,11 @@ CHANGE_MESSAGE_VISIBILITY_RESPONSE = """<ChangeMessageVisibilityResponse>
</RequestId>
</ResponseMetadata>
</ChangeMessageVisibilityResponse>"""
PURGE_QUEUE_RESPONSE = """<PurgeQueueResponse>
<ResponseMetadata>
<RequestId>
6fde8d1e-52cd-4581-8cd9-c512f4c64223
</RequestId>
</ResponseMetadata>
</PurgeQueueResponse>"""

View File

@ -428,3 +428,16 @@ def test_change_message_visibility_on_visible_message():
queue.count().should.equal(1)
original_message.change_visibility.when.called_with(100).should.throw(SQSError)
@mock_sqs
def test_purge_action():
conn = boto.sqs.connect_to_region("us-east-1")
queue = conn.create_queue('new-queue')
queue.write(queue.new_message('this is another test message'))
queue.count().should.equal(1)
queue.purge()
queue.count().should.equal(0)