SQS: fix trimming .fifo from queue name (#982)

* SQS: fix trimming .fifo from queue name

* add test

* fix lint error
This commit is contained in:
Ilya Konstantinov 2019-01-09 10:36:37 -08:00 committed by Omer Katz
parent 93a05f7261
commit 5ee7c1ddcc
2 changed files with 8 additions and 2 deletions

View File

@ -57,7 +57,7 @@ from . import virtual
logger = get_logger(__name__) logger = get_logger(__name__)
# dots are replaced by dash, all other punctuation # dots are replaced by dash, dash remains dash, all other punctuation
# replaced by underscore. # replaced by underscore.
CHARS_REPLACE_TABLE = { CHARS_REPLACE_TABLE = {
ord(c): 0x5f for c in string.punctuation if c not in '-_.' ord(c): 0x5f for c in string.punctuation if c not in '-_.'
@ -151,7 +151,7 @@ class Channel(virtual.Channel):
def entity_name(self, name, table=CHARS_REPLACE_TABLE): def entity_name(self, name, table=CHARS_REPLACE_TABLE):
"""Format AMQP queue name into a legal SQS queue name.""" """Format AMQP queue name into a legal SQS queue name."""
if name.endswith('.fifo'): if name.endswith('.fifo'):
partial = name.rstrip('.fifo') partial = name[:-len('.fifo')]
partial = text_t(safe_str(partial)).translate(table) partial = text_t(safe_str(partial)).translate(table)
return partial + '.fifo' return partial + '.fifo'
else: else:

View File

@ -224,6 +224,12 @@ class test_Channel:
conn = Connection(hostname=None, transport=SQS.Transport) conn = Connection(hostname=None, transport=SQS.Transport)
assert conn.hostname == conn.clone().hostname assert conn.hostname == conn.clone().hostname
def test_entity_name(self):
assert self.channel.entity_name('foo') == 'foo'
assert self.channel.entity_name('foo.bar-baz*qux_quux') == \
'foo-bar-baz_qux_quux'
assert self.channel.entity_name('abcdef.fifo') == 'abcdef.fifo'
def test_new_queue(self): def test_new_queue(self):
queue_name = 'new_unittest_queue' queue_name = 'new_unittest_queue'
self.channel._new_queue(queue_name) self.channel._new_queue(queue_name)