diff --git a/IMPLEMENTATION_COVERAGE.md b/IMPLEMENTATION_COVERAGE.md index 126d454c6..40daef880 100644 --- a/IMPLEMENTATION_COVERAGE.md +++ b/IMPLEMENTATION_COVERAGE.md @@ -6065,7 +6065,7 @@ - [X] untag_resource ## sqs -75% implemented +80% implemented - [X] add_permission - [X] change_message_visibility - [ ] change_message_visibility_batch @@ -6074,7 +6074,7 @@ - [ ] delete_message_batch - [X] delete_queue - [ ] get_queue_attributes -- [ ] get_queue_url +- [X] get_queue_url - [X] list_dead_letter_source_queues - [X] list_queue_tags - [X] list_queues diff --git a/moto/sqs/models.py b/moto/sqs/models.py index 9900846ac..64b376d60 100644 --- a/moto/sqs/models.py +++ b/moto/sqs/models.py @@ -466,6 +466,9 @@ class SQSBackend(BaseBackend): return queue + def get_queue_url(self, queue_name): + return self.get_queue(queue_name) + def list_queues(self, queue_name_prefix): re_str = '.*' if queue_name_prefix: diff --git a/moto/sqs/responses.py b/moto/sqs/responses.py index 52b237235..2997f924f 100644 --- a/moto/sqs/responses.py +++ b/moto/sqs/responses.py @@ -90,13 +90,10 @@ class SQSResponse(BaseResponse): request_url = urlparse(self.uri) queue_name = self._get_param("QueueName") - queue = self.sqs_backend.get_queue(queue_name) + queue = self.sqs_backend.get_queue_url(queue_name) - if queue: - template = self.response_template(GET_QUEUE_URL_RESPONSE) - return template.render(queue=queue, request_url=request_url) - else: - return "", dict(status=404) + template = self.response_template(GET_QUEUE_URL_RESPONSE) + return template.render(queue_url=queue.url(request_url)) def list_queues(self): request_url = urlparse(self.uri) @@ -420,7 +417,7 @@ CREATE_QUEUE_RESPONSE = """ GET_QUEUE_URL_RESPONSE = """ - {{ queue.url(request_url) }} + {{ queue_url }} diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index 1a9038aa5..7a067c316 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -144,18 +144,42 @@ def test_create_queue_kms(): def test_create_queue_with_tags(): client = boto3.client('sqs', region_name='us-east-1') response = client.create_queue( - QueueName = 'test-queue-with-tags', - tags = { + QueueName='test-queue-with-tags', + tags={ 'tag_key_1': 'tag_value_1' } ) queue_url = response['QueueUrl'] - client.list_queue_tags(QueueUrl = queue_url)['Tags'].should.equal({ + client.list_queue_tags(QueueUrl=queue_url)['Tags'].should.equal({ 'tag_key_1': 'tag_value_1' }) +@mock_sqs +def test_get_queue_url(): + client = boto3.client('sqs', region_name='us-east-1') + client.create_queue(QueueName='test-queue') + + response = client.get_queue_url(QueueName='test-queue') + + response['QueueUrl'].should.equal( + 'https://queue.amazonaws.com/123456789012/test-queue' + ) + + +@mock_sqs +def test_get_queue_url_errors(): + client = boto3.client('sqs', region_name='us-east-1') + + client.get_queue_url.when.called_with( + QueueName='non-existing-queue' + ).should.throw( + ClientError, + 'The specified queue does not exist for this wsdl version.' + ) + + @mock_sqs def test_get_nonexistent_queue(): sqs = boto3.resource('sqs', region_name='us-east-1')