From e8a06d156b4d901ae2808457f9bf58a9bd5ec833 Mon Sep 17 00:00:00 2001 From: Piotr Maslanka <piotr.maslanka@henrietta.com.pl> Date: Tue, 1 Aug 2017 13:27:57 +0200 Subject: [PATCH] fixes #26 --- coolamqp/attaches/consumer.py | 10 +++++++--- tests/test_attaches/__init__.py | 0 tests/test_attaches/test_consumer.py | 13 +++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 tests/test_attaches/__init__.py create mode 100644 tests/test_attaches/test_consumer.py diff --git a/coolamqp/attaches/consumer.py b/coolamqp/attaches/consumer.py index 98da3c0..32085bd 100644 --- a/coolamqp/attaches/consumer.py +++ b/coolamqp/attaches/consumer.py @@ -87,8 +87,10 @@ class Consumer(Channeler): :param on_message: callable that will process incoming messages :type on_message: callable(ReceivedMessage instance) :param no_ack: Will this consumer require acknowledges from messages? - :param qos: a tuple of (prefetch size, prefetch window) for this consumer - :type qos: tuple(int, int) or tuple(None, int) + :param qos: a tuple of (prefetch size, prefetch window) for this consumer, or an int (prefetch window only) + If an int is passed, prefetch size will be set to 0 (which means undefined), and this int + will be used for prefetch window + :type qos: tuple(int, int) or tuple(None, int) or int :param cancel_on_failure: Consumer will cancel itself when link goes down :type cancel_on_failure: bool :param future_to_notify: Future to succeed when this consumer goes online for the first time. @@ -119,7 +121,9 @@ class Consumer(Channeler): # if this is not None, then it has an attribute # on_cancel_customer(Consumer instance) if qos is not None: - if qos[0] is None: + if isinstance(qos, int): + qos = 0, qos + elif qos[0] is None: qos = 0, qos[1] # prefetch_size=0=undefined self.qos = qos self.qos_update_sent = False # QoS was not sent to server diff --git a/tests/test_attaches/__init__.py b/tests/test_attaches/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_attaches/test_consumer.py b/tests/test_attaches/test_consumer.py new file mode 100644 index 0000000..3ddf662 --- /dev/null +++ b/tests/test_attaches/test_consumer.py @@ -0,0 +1,13 @@ +# coding=UTF-8 +from __future__ import print_function, absolute_import, division +import six +import unittest +from coolamqp.attaches import Consumer +from coolamqp.objects import Queue + + +class TestConsumer(unittest.TestCase): + def test_issue_26(self): + """Support for passing qos as int""" + cons = Consumer(Queue('wtf'), lambda msg: None, qos=25) + self.assertEquals(cons.qos, (0, 25)) -- GitLab