summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatus Valo <matusvalo@users.noreply.github.com>2018-12-31 11:14:26 +0100
committerAsif Saif Uddin <auvipy@gmail.com>2018-12-31 16:14:26 +0600
commit6e43b7db2fdfa765a7596e8889941304b3becc94 (patch)
tree1f8a08cc50f4c842a8e160ca16b65d497fdbdf85
parent938f8a34bc6608d9b8889958828ea2d96ebdf8ed (diff)
downloadpy-amqp-6e43b7db2fdfa765a7596e8889941304b3becc94.tar.gz
Don't return method signature from AbstractChannel::wait() (#233)
* Don't return method signature from AbstractChannel::wait() Commit f63f8fe9efbe3357741f32541ea2d7b063f7df09 added new parameter `method_sig` for wait() callback. This change breaks some parts of existing code. This commit handles this issue. * Fix basic_publish integration test
-rw-r--r--amqp/abstract_channel.py1
-rw-r--r--amqp/channel.py4
-rw-r--r--t/integration/test_integration.py53
-rw-r--r--t/unit/test_channel.py6
4 files changed, 53 insertions, 11 deletions
diff --git a/amqp/abstract_channel.py b/amqp/abstract_channel.py
index 5fe6611..8530bec 100644
--- a/amqp/abstract_channel.py
+++ b/amqp/abstract_channel.py
@@ -81,6 +81,7 @@ class AbstractChannel(object):
if p.value:
args, kwargs = p.value
+ args = args[1:] # We are not returning method back
return args if returns_tuple else (args and args[0])
finally:
for i, m in enumerate(method):
diff --git a/amqp/channel.py b/amqp/channel.py
index a0c686f..4942a82 100644
--- a/amqp/channel.py
+++ b/amqp/channel.py
@@ -1571,13 +1571,13 @@ class Channel(AbstractChannel):
)
if not nowait:
- # send_method() returns (spec.Basic.ConsumeOk, consumer_tag) tuple.
+ # send_method() returns (consumer_tag,) tuple.
# consumer_tag is returned by broker using following rules:
# * consumer_tag is not specified by client, random one
# is generated by Broker
# * consumer_tag is provided by client, the same one
# is returned by broker
- consumer_tag = p[1]
+ consumer_tag = p[0]
elif nowait and not consumer_tag:
raise ValueError(
'Consumer tag must be specified when nowait is True'
diff --git a/t/integration/test_integration.py b/t/integration/test_integration.py
index 2957656..3a20540 100644
--- a/t/integration/test_integration.py
+++ b/t/integration/test_integration.py
@@ -1,11 +1,13 @@
from __future__ import absolute_import, unicode_literals
+import socket
import pytest
from case import patch, call, Mock
from amqp import spec, Connection, Channel, sasl, Message
from amqp.platform import pack
from amqp.exceptions import ConnectionError
from amqp.serialization import dumps, loads
+from amqp.protocol import queue_declare_ok_t
def ret_factory(method, channel=0, args=b'', arg_format=None):
@@ -98,12 +100,14 @@ def handshake(conn, transport_mock):
def create_channel(channel_id, conn, transport_mock):
- transport_mock().read_frame.return_value = ret_factory(
- spec.Channel.OpenOk,
- channel=channel_id,
- args=(1, False),
- arg_format='Lb'
- )
+ transport_mock().read_frame.side_effect = [
+ ret_factory(
+ spec.Channel.OpenOk,
+ channel=channel_id,
+ args=(1, False),
+ arg_format='Lb'
+ )
+ ]
ch = conn.channel(channel_id=channel_id)
transport_mock().read_frame.side_effect = None
return ch
@@ -341,6 +345,9 @@ class test_channel:
frame_writer_mock = frame_writer_cls_mock()
frame_writer_mock.reset_mock()
msg = Message('test')
+ # we need to mock socket timeout due checks in
+ # Channel._basic_publish
+ transport_mock().read_frame.side_effect = socket.timeout
ch.basic_publish(msg)
frame_writer_mock.assert_called_once_with(
1, 1, spec.Basic.Publish,
@@ -410,3 +417,37 @@ class test_channel:
None
)
assert ch.callbacks['my_tag'] == callback_mock
+
+ def test_queue_declare(self):
+ # Test verifying declaring queue
+ frame_writer_cls_mock = Mock()
+ conn = Connection(frame_writer=frame_writer_cls_mock)
+ with patch.object(conn, 'Transport') as transport_mock:
+ handshake(conn, transport_mock)
+ ch = create_channel(1, conn, transport_mock)
+ transport_mock().read_frame.return_value = ret_factory(
+ spec.Queue.DeclareOk,
+ channel=1,
+ arg_format='sll',
+ args=('foo', 1, 2)
+ )
+ frame_writer_mock = frame_writer_cls_mock()
+ frame_writer_mock.reset_mock()
+ ret = ch.queue_declare('foo')
+ assert ret == queue_declare_ok_t(
+ queue='foo', message_count=1, consumer_count=2
+ )
+ frame_writer_mock.assert_called_once_with(
+ 1, 1, spec.Queue.Declare,
+ dumps(
+ 'BsbbbbbF',
+ (
+ 0,
+ # queue, passive, durable, exclusive,
+ 'foo', False, False, False,
+ # auto_delete, nowait, arguments
+ True, False, None
+ )
+ ),
+ None
+ )
diff --git a/t/unit/test_channel.py b/t/unit/test_channel.py
index 7e7edc6..bcea906 100644
--- a/t/unit/test_channel.py
+++ b/t/unit/test_channel.py
@@ -267,7 +267,7 @@ class test_Channel:
def test_basic_consume(self):
callback = Mock()
on_cancel = Mock()
- self.c.send_method.return_value = (spec.Basic.ConsumeOk, 123)
+ self.c.send_method.return_value = (123, )
self.c.basic_consume(
'q', 123, arguments={'x': 1},
callback=callback,
@@ -283,7 +283,7 @@ class test_Channel:
assert self.c.cancel_callbacks[123] is on_cancel
def test_basic_consume__no_ack(self):
- self.c.send_method.return_value = (spec.Basic.ConsumeOk, 123)
+ self.c.send_method.return_value = (123,)
self.c.basic_consume(
'q', 123, arguments={'x': 1}, no_ack=True,
)
@@ -291,7 +291,7 @@ class test_Channel:
def test_basic_consume_no_consumer_tag(self):
callback = Mock()
- self.c.send_method.return_value = (spec.Basic.ConsumeOk, 123)
+ self.c.send_method.return_value = (123,)
self.c.basic_consume(
'q', arguments={'x': 1},
callback=callback,