Add error handling for sqs.send_message_batch
This commit is contained in:
parent
36a8a4ad00
commit
65c5502a62
2 changed files with 176 additions and 13 deletions
|
|
@ -882,6 +882,127 @@ def test_delete_message_after_visibility_timeout():
|
|||
assert new_queue.count() == 0
|
||||
|
||||
|
||||
@mock_sqs
|
||||
def test_send_message_batch_errors():
|
||||
client = boto3.client('sqs', region_name = 'us-east-1')
|
||||
|
||||
response = client.create_queue(QueueName='test-queue-with-tags')
|
||||
queue_url = response['QueueUrl']
|
||||
|
||||
client.send_message_batch.when.called_with(
|
||||
QueueUrl=queue_url + '-not-existing',
|
||||
Entries=[
|
||||
{
|
||||
'Id': 'id_1',
|
||||
'MessageBody': 'body_1'
|
||||
}
|
||||
]
|
||||
).should.throw(
|
||||
ClientError,
|
||||
'The specified queue does not exist for this wsdl version.'
|
||||
)
|
||||
|
||||
client.send_message_batch.when.called_with(
|
||||
QueueUrl=queue_url,
|
||||
Entries=[]
|
||||
).should.throw(
|
||||
ClientError,
|
||||
'There should be at least one SendMessageBatchRequestEntry in the request.'
|
||||
)
|
||||
|
||||
client.send_message_batch.when.called_with(
|
||||
QueueUrl=queue_url,
|
||||
Entries=[
|
||||
{
|
||||
'Id': '',
|
||||
'MessageBody': 'body_1'
|
||||
}
|
||||
]
|
||||
).should.throw(
|
||||
ClientError,
|
||||
'A batch entry id can only contain alphanumeric characters, '
|
||||
'hyphens and underscores. It can be at most 80 letters long.'
|
||||
)
|
||||
|
||||
client.send_message_batch.when.called_with(
|
||||
QueueUrl=queue_url,
|
||||
Entries=[
|
||||
{
|
||||
'Id': '.!@#$%^&*()+=',
|
||||
'MessageBody': 'body_1'
|
||||
}
|
||||
]
|
||||
).should.throw(
|
||||
ClientError,
|
||||
'A batch entry id can only contain alphanumeric characters, '
|
||||
'hyphens and underscores. It can be at most 80 letters long.'
|
||||
)
|
||||
|
||||
client.send_message_batch.when.called_with(
|
||||
QueueUrl=queue_url,
|
||||
Entries=[
|
||||
{
|
||||
'Id': 'i' * 81,
|
||||
'MessageBody': 'body_1'
|
||||
}
|
||||
]
|
||||
).should.throw(
|
||||
ClientError,
|
||||
'A batch entry id can only contain alphanumeric characters, '
|
||||
'hyphens and underscores. It can be at most 80 letters long.'
|
||||
)
|
||||
|
||||
client.send_message_batch.when.called_with(
|
||||
QueueUrl=queue_url,
|
||||
Entries=[
|
||||
{
|
||||
'Id': 'id_1',
|
||||
'MessageBody': 'b' * 262145
|
||||
}
|
||||
]
|
||||
).should.throw(
|
||||
ClientError,
|
||||
'Batch requests cannot be longer than 262144 bytes. '
|
||||
'You have sent 262145 bytes.'
|
||||
)
|
||||
|
||||
# only the first duplicated Id is reported
|
||||
client.send_message_batch.when.called_with(
|
||||
QueueUrl=queue_url,
|
||||
Entries=[
|
||||
{
|
||||
'Id': 'id_1',
|
||||
'MessageBody': 'body_1'
|
||||
},
|
||||
{
|
||||
'Id': 'id_2',
|
||||
'MessageBody': 'body_2'
|
||||
},
|
||||
{
|
||||
'Id': 'id_2',
|
||||
'MessageBody': 'body_2'
|
||||
},
|
||||
{
|
||||
'Id': 'id_1',
|
||||
'MessageBody': 'body_1'
|
||||
}
|
||||
]
|
||||
).should.throw(
|
||||
ClientError,
|
||||
'Id id_2 repeated.'
|
||||
)
|
||||
|
||||
entries = [{'Id': 'id_{}'.format(i), 'MessageBody': 'body_{}'.format(i)} for i in range(11)]
|
||||
client.send_message_batch.when.called_with(
|
||||
QueueUrl=queue_url,
|
||||
Entries=entries
|
||||
).should.throw(
|
||||
ClientError,
|
||||
'Maximum number of entries per request are 10. '
|
||||
'You have sent 11.'
|
||||
)
|
||||
|
||||
|
||||
@mock_sqs
|
||||
def test_batch_change_message_visibility():
|
||||
if os.environ.get('TEST_SERVER_MODE', 'false').lower() == 'true':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue