From 8ffd4e51ec415b13cde3423fecd06ad4b60d4a2c Mon Sep 17 00:00:00 2001 From: Nuno Santos Date: Wed, 1 Jun 2016 16:39:06 +0200 Subject: [PATCH] Fix retrieving inexistent queue errors when using boto3. Handle 404 errors when trying to retrieve a SQS queue that does not exist. Add get_queue and get_inexistent_queue tests for boto3. --- moto/sqs/responses.py | 16 ++++++++++++++++ tests/test_sqs/test_sqs.py | 21 +++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/moto/sqs/responses.py b/moto/sqs/responses.py index db163ef3e..8744b4008 100644 --- a/moto/sqs/responses.py +++ b/moto/sqs/responses.py @@ -50,6 +50,12 @@ class SQSResponse(BaseResponse): return visibility_timeout + def call_action(self): + status_code, headers, body = super(SQSResponse, self).call_action() + if status_code == 404: + return 404, headers, ERROR_INEXISTENT_QUEUE + return status_code, headers, body + def create_queue(self): queue_name = self.querystring.get("QueueName")[0] queue = self.sqs_backend.create_queue(queue_name, visibility_timeout=self.attribute.get('VisibilityTimeout'), @@ -438,3 +444,13 @@ ERROR_TOO_LONG_RESPONSE = """ + + Sender + AWS.SimpleQueueService.NonExistentQueue + The specified queue does not exist for this wsdl version. + + + b8bc806b-fa6b-53b5-8be8-cfa2f9836bc3 +""" diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index 77c28aaa8..f84717913 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals import boto import boto3 +import botocore.exceptions from boto.exception import SQSError from boto.sqs.message import RawMessage, Message @@ -500,6 +501,26 @@ boto3 """ +@mock_sqs +def test_boto3_get_queue(): + sqs = boto3.resource('sqs', region_name='us-east-1') + new_queue = sqs.create_queue(QueueName='test-queue') + new_queue.should_not.be.none + new_queue.should.have.property('url').should.contain('test-queue') + + queue = sqs.get_queue_by_name(QueueName='test-queue') + queue.attributes.get('QueueArn').should_not.be.none + queue.attributes.get('QueueArn').split(':')[-1].should.equal('test-queue') + queue.attributes.get('VisibilityTimeout').should_not.be.none + queue.attributes.get('VisibilityTimeout').should.equal('30') + + +@mock_sqs +def test_boto3_get_inexistent_queue(): + sqs = boto3.resource('sqs', region_name='us-east-1') + sqs.get_queue_by_name.when.called_with(QueueName='nonexisting-queue').should.throw(botocore.exceptions.ClientError) + + @mock_sqs def test_boto3_message_send(): sqs = boto3.resource('sqs', region_name='us-east-1')