Skip to content

Commit

Permalink
Handle SQS QueueName using an AWSHelperFn (Fixes #773)
Browse files Browse the repository at this point in the history
  • Loading branch information
markpeek committed Jul 25, 2017
1 parent 52d24e0 commit 5cd715e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
34 changes: 34 additions & 0 deletions tests/test_sqs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import unittest
from troposphere import Join
from troposphere.sqs import Queue


class TestQueue(unittest.TestCase):
def test_QueueName(self):
Queue(
"q",
FifoQueue=False,
).validate()

Queue(
"q",
FifoQueue=True,
QueueName="foobar.fifo",
).validate()

Queue(
"q",
FifoQueue=True,
QueueName=Join("foo", "bar"),
).validate()

with self.assertRaises(ValueError):
Queue(
"q",
FifoQueue=True,
QueueName="foobar",
).validate()


if __name__ == '__main__':
unittest.main()
7 changes: 5 additions & 2 deletions troposphere/sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# See LICENSE file for full license.

from . import AWSObject, AWSProperty
from . import AWSHelperFn, AWSObject, AWSProperty
from .validators import integer
try:
from awacs.aws import Policy
Expand Down Expand Up @@ -36,7 +36,10 @@ class Queue(AWSObject):

def validate(self):
if self.properties.get('FifoQueue'):
if not self.properties.get('QueueName', '').endswith('.fifo'):
queuename = self.properties.get('QueueName', '')
if isinstance(queuename, AWSHelperFn):
pass
elif not queuename.endswith('.fifo'):
raise ValueError("SQS: FIFO queues need to provide a "
"QueueName that ends with '.fifo'")

Expand Down

0 comments on commit 5cd715e

Please sign in to comment.