Fix creating SQS queue with same attributes. Closes #1663.
This commit is contained in:
parent
cf71532fa9
commit
1689a2808f
@ -47,6 +47,7 @@ _stderr_regex = re.compile(r'START|END|REPORT RequestId: .*')
|
|||||||
_orig_adapter_send = requests.adapters.HTTPAdapter.send
|
_orig_adapter_send = requests.adapters.HTTPAdapter.send
|
||||||
docker_3 = docker.__version__.startswith("3")
|
docker_3 = docker.__version__.startswith("3")
|
||||||
|
|
||||||
|
|
||||||
def zip2tar(zip_bytes):
|
def zip2tar(zip_bytes):
|
||||||
with TemporaryDirectory() as td:
|
with TemporaryDirectory() as td:
|
||||||
tarname = os.path.join(td, 'data.tar')
|
tarname = os.path.join(td, 'data.tar')
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
from moto.core.exceptions import RESTError
|
||||||
|
|
||||||
|
|
||||||
class MessageNotInflight(Exception):
|
class MessageNotInflight(Exception):
|
||||||
@ -21,3 +22,11 @@ class MessageAttributesInvalid(Exception):
|
|||||||
class QueueDoesNotExist(Exception):
|
class QueueDoesNotExist(Exception):
|
||||||
status_code = 404
|
status_code = 404
|
||||||
description = "The specified queue does not exist for this wsdl version."
|
description = "The specified queue does not exist for this wsdl version."
|
||||||
|
|
||||||
|
|
||||||
|
class QueueAlreadyExists(RESTError):
|
||||||
|
code = 400
|
||||||
|
|
||||||
|
def __init__(self, message):
|
||||||
|
super(QueueAlreadyExists, self).__init__(
|
||||||
|
"QueueAlreadyExists", message)
|
||||||
|
@ -18,6 +18,7 @@ from .exceptions import (
|
|||||||
MessageAttributesInvalid,
|
MessageAttributesInvalid,
|
||||||
MessageNotInflight,
|
MessageNotInflight,
|
||||||
QueueDoesNotExist,
|
QueueDoesNotExist,
|
||||||
|
QueueAlreadyExists,
|
||||||
ReceiptHandleIsInvalid,
|
ReceiptHandleIsInvalid,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -383,7 +384,12 @@ class SQSBackend(BaseBackend):
|
|||||||
|
|
||||||
def create_queue(self, name, **kwargs):
|
def create_queue(self, name, **kwargs):
|
||||||
queue = self.queues.get(name)
|
queue = self.queues.get(name)
|
||||||
if queue is None:
|
if queue:
|
||||||
|
# Queue already exist. If attributes don't match, throw error
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if getattr(queue, camelcase_to_underscores(key)) != value:
|
||||||
|
raise QueueAlreadyExists("The specified queue already exists.")
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
kwargs.pop('region')
|
kwargs.pop('region')
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -40,6 +40,29 @@ def test_create_fifo_queue_fail():
|
|||||||
raise RuntimeError('Should of raised InvalidParameterValue Exception')
|
raise RuntimeError('Should of raised InvalidParameterValue Exception')
|
||||||
|
|
||||||
|
|
||||||
|
@mock_sqs
|
||||||
|
def test_create_queue_with_different_attributes_fail():
|
||||||
|
sqs = boto3.client('sqs', region_name='us-east-1')
|
||||||
|
|
||||||
|
sqs.create_queue(
|
||||||
|
QueueName='test-queue',
|
||||||
|
Attributes={
|
||||||
|
'VisibilityTimeout': '10',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
sqs.create_queue(
|
||||||
|
QueueName='test-queue',
|
||||||
|
Attributes={
|
||||||
|
'VisibilityTimeout': '60',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
except botocore.exceptions.ClientError as err:
|
||||||
|
err.response['Error']['Code'].should.equal('QueueAlreadyExists')
|
||||||
|
else:
|
||||||
|
raise RuntimeError('Should of raised QueueAlreadyExists Exception')
|
||||||
|
|
||||||
|
|
||||||
@mock_sqs
|
@mock_sqs
|
||||||
def test_create_fifo_queue():
|
def test_create_fifo_queue():
|
||||||
sqs = boto3.client('sqs', region_name='us-east-1')
|
sqs = boto3.client('sqs', region_name='us-east-1')
|
||||||
|
Loading…
Reference in New Issue
Block a user