Add error handling for sqs.tag_queue

This commit is contained in:
gruebel 2019-10-17 22:36:37 +02:00
parent 65c5502a62
commit dbfb319def
2 changed files with 62 additions and 1 deletions

View File

@ -439,6 +439,20 @@ class SQSResponse(BaseResponse):
queue_name = self._get_queue_name()
tags = self._get_map_prefix('Tag', key_end='.Key', value_end='.Value')
try:
self.sqs_backend.get_queue(queue_name)
except QueueDoesNotExist as e:
return self._error('AWS.SimpleQueueService.NonExistentQueue',
e.description)
if len(tags) == 0:
return self._error('MissingParameter',
'The request must contain the parameter Tags.')
if len(tags) > 50:
return self._error('InvalidParameterValue',
'Too many tags added for queue {}.'.format(queue_name))
self.sqs_backend.tag_queue(queue_name, tags)
template = self.response_template(TAG_QUEUE_RESPONSE)

View File

@ -1108,6 +1108,53 @@ def test_tags():
})
@mock_sqs
def test_tag_queue_errors():
client = boto3.client('sqs', region_name='us-east-1')
response = client.create_queue(
QueueName='test-queue-with-tags',
tags={
'tag_key_1': 'tag_value_X'
}
)
queue_url = response['QueueUrl']
client.tag_queue.when.called_with(
QueueUrl=queue_url + '-not-existing',
Tags={
'tag_key_1': 'tag_value_1'
}
).should.throw(
ClientError,
'The specified queue does not exist for this wsdl version.'
)
client.tag_queue.when.called_with(
QueueUrl=queue_url,
Tags={}
).should.throw(
ClientError,
'The request must contain the parameter Tags.'
)
too_many_tags = {'tag_key_{}'.format(i): 'tag_value_{}'.format(i) for i in range(51)}
client.tag_queue.when.called_with(
QueueUrl=queue_url,
Tags=too_many_tags
).should.throw(
ClientError,
'Too many tags added for queue test-queue-with-tags.'
)
# when the request fails, the tags should not be updated
client.list_queue_tags(QueueUrl=queue_url)['Tags'].should.equal(
{
'tag_key_1': 'tag_value_X'
}
)
@mock_sqs
def test_untag_queue_errors():
client = boto3.client('sqs', region_name='us-east-1')
@ -1127,7 +1174,7 @@ def test_untag_queue_errors():
]
).should.throw(
ClientError,
"The specified queue does not exist for this wsdl version."
'The specified queue does not exist for this wsdl version.'
)
client.untag_queue.when.called_with(