summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Gutierrez <chibby0ne@gmail.com>2018-08-12 04:59:27 +0200
committerAsif Saifuddin Auvi <auvipy@gmail.com>2018-08-12 08:59:27 +0600
commit1160b92c27f2f6c56554663f0d6d4ad9194b3dff (patch)
tree7d8f9af08aaf176978b3031ec774033fbad3f31c
parent073001e3419fa275eb34c5ca31a1bb5d7225b405 (diff)
downloadkombu-1160b92c27f2f6c56554663f0d6d4ad9194b3dff.tar.gz
Queue: add handling of Exchange as str to constructor (#904)
To fit with the documentation, Queue can now handle a str argument for the exchange parameter in the constructor, as well as an actual Exchange object. Added relevant unit tests to avoid regressions. Fixes: https://github.com/celery/kombu/issues/903 Signed-off-by: Antonio Gutierrez <chibby0ne@gmail.com>
-rw-r--r--kombu/entity.py5
-rw-r--r--t/unit/test_entity.py14
2 files changed, 18 insertions, 1 deletions
diff --git a/kombu/entity.py b/kombu/entity.py
index bded8454..ccdeda2e 100644
--- a/kombu/entity.py
+++ b/kombu/entity.py
@@ -568,7 +568,10 @@ class Queue(MaybeChannelBound):
**kwargs):
super(Queue, self).__init__(**kwargs)
self.name = name or self.name
- self.exchange = exchange or self.exchange
+ if isinstance(exchange, str):
+ self.exchange = Exchange(exchange)
+ elif isinstance(exchange, Exchange):
+ self.exchange = exchange
self.routing_key = routing_key or self.routing_key
self.bindings = set(bindings or [])
self.on_declared = on_declared
diff --git a/t/unit/test_entity.py b/t/unit/test_entity.py
index ccf50c0e..c44c0677 100644
--- a/t/unit/test_entity.py
+++ b/t/unit/test_entity.py
@@ -214,6 +214,20 @@ class test_Queue:
def setup(self):
self.exchange = Exchange('foo', 'direct')
+ def test_constructor_with_actual_exchange(self):
+ exchange = Exchange('exchange_name', 'direct')
+ queue = Queue(name='queue_name', exchange=exchange)
+ assert queue.exchange == exchange
+
+ def test_constructor_with_string_exchange(self):
+ exchange_name = str('exchange_name')
+ queue = Queue(name='queue_name', exchange=exchange_name)
+ assert queue.exchange == Exchange(exchange_name)
+
+ def test_constructor_with_default_exchange(self):
+ queue = Queue(name='queue_name')
+ assert queue.exchange == Exchange('')
+
def test_hash(self):
assert hash(Queue('a')) == hash(Queue('a'))
assert hash(Queue('a')) != hash(Queue('b'))