Fix creating SQS queue with same attributes. Closes #1663.

This commit is contained in:
Steve Pulec 2018-05-31 23:05:50 -04:00
commit 1689a2808f
4 changed files with 40 additions and 1 deletions

View file

@ -1,4 +1,5 @@
from __future__ import unicode_literals
from moto.core.exceptions import RESTError
class MessageNotInflight(Exception):
@ -21,3 +22,11 @@ class MessageAttributesInvalid(Exception):
class QueueDoesNotExist(Exception):
status_code = 404
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)

View file

@ -18,6 +18,7 @@ from .exceptions import (
MessageAttributesInvalid,
MessageNotInflight,
QueueDoesNotExist,
QueueAlreadyExists,
ReceiptHandleIsInvalid,
)
@ -383,7 +384,12 @@ class SQSBackend(BaseBackend):
def create_queue(self, name, **kwargs):
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:
kwargs.pop('region')
except KeyError: