From 64baad79b04aff41bd2674ca17ea398b30b25d9b Mon Sep 17 00:00:00 2001 From: "dilshod.tadjibaev" Date: Wed, 24 Apr 2013 00:41:45 -0700 Subject: [PATCH] Returning None in get_queue when not found. Closes spulec/moto#23 --- moto/sqs/models.py | 2 +- moto/sqs/responses.py | 8 ++++++-- tests/test_sqs/test_sqs.py | 3 +++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/moto/sqs/models.py b/moto/sqs/models.py index 49d004f36..afceaf9e5 100644 --- a/moto/sqs/models.py +++ b/moto/sqs/models.py @@ -53,7 +53,7 @@ class SQSBackend(BaseBackend): return self.queues.values() def get_queue(self, queue_name): - return self.queues[queue_name] + return self.queues.get(queue_name, None) def delete_queue(self, queue_name): if queue_name in self.queues: diff --git a/moto/sqs/responses.py b/moto/sqs/responses.py index 484fe681d..0f582cf85 100644 --- a/moto/sqs/responses.py +++ b/moto/sqs/responses.py @@ -20,8 +20,12 @@ class QueuesResponse(BaseResponse): def get_queue_url(self): queue_name = self.querystring.get("QueueName")[0] queue = sqs_backend.get_queue(queue_name) - template = Template(GET_QUEUE_URL_RESPONSE) - return template.render(queue=queue) + if queue: + template = Template(GET_QUEUE_URL_RESPONSE) + return template.render(queue=queue) + else: + return "", dict(status=404) + def list_queues(self): queues = sqs_backend.list_queues() diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index eeb22ec96..0fe25e2cd 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -27,6 +27,9 @@ def test_get_queue(): queue.name.should.equal("test-queue") queue.get_timeout().should.equal(60) + nonexisting_queue = conn.get_queue("nonexisting_queue") + nonexisting_queue.should.be.none + @mock_sqs def test_delete_queue():