Refactor sqs.get_queue_url

This commit is contained in:
gruebel 2019-10-26 22:26:48 +02:00
parent 23978e644f
commit 6573f69087
4 changed files with 36 additions and 12 deletions

View File

@ -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

View File

@ -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:

View File

@ -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 = """<CreateQueueResponse>
GET_QUEUE_URL_RESPONSE = """<GetQueueUrlResponse>
<GetQueueUrlResult>
<QueueUrl>{{ queue.url(request_url) }}</QueueUrl>
<QueueUrl>{{ queue_url }}</QueueUrl>
</GetQueueUrlResult>
<ResponseMetadata>
<RequestId></RequestId>

View File

@ -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')