diff --git a/moto/sqs/models.py b/moto/sqs/models.py index 11d91cfb8..48cc2a773 100644 --- a/moto/sqs/models.py +++ b/moto/sqs/models.py @@ -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() diff --git a/moto/sqs/responses.py b/moto/sqs/responses.py index 3a22f43fb..b5947c639 100644 --- a/moto/sqs/responses.py +++ b/moto/sqs/responses.py @@ -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 = """ """ + +PURGE_QUEUE_RESPONSE = """ + + + 6fde8d1e-52cd-4581-8cd9-c512f4c64223 + + +""" diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index fcad635d1..393725619 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -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)