def test_init(self): left = Mock() right = Mock() ct = ComposableTransport(left, right, *ComposableTransport.common_methods) self.assertEquals(ct._transports, [left, right]) self.assertEquals( ct._methods, { 'declare_exchange_impl': left.declare_exchange_impl, 'delete_exchange_impl': left.delete_exchange_impl, 'declare_queue_impl': left.declare_queue_impl, 'delete_queue_impl': left.delete_queue_impl, 'bind_impl': left.bind_impl, 'unbind_impl': left.unbind_impl, 'purge_impl': left.purge_impl, 'setup_listener': left.setup_listener, 'ack_impl': right.ack_impl, 'reject_impl': right.reject_impl, 'start_consume_impl': right.start_consume_impl, 'stop_consume_impl': right.stop_consume_impl, 'get_stats_impl': right.get_stats_impl, 'qos_impl': right.qos_impl, 'publish_impl': right.publish_impl, })
def test_active(self): left = Mock() right = Mock() left.active = True right.active = True ct = ComposableTransport(left, right) self.assertTrue(ct.active)
def test_active_one_not(self): left = Mock() right = Mock() left.active = False right.active = True ct = ComposableTransport(left, right) self.assertFalse(ct.active)
def test_close(self): left = Mock() right = Mock() ct = ComposableTransport(left, right) ct.close() left.close.assert_called_once_with() right.close.assert_called_once_with()
def test_overlay(self): left = Mock() ct = ComposableTransport(left, None) self.assertEquals(ct._transports, [left]) right = Mock() ct.overlay(right, 'brambles') self.assertIn('brambles', ct._methods) self.assertEquals(ct._methods['brambles'], right.brambles)
def test_overlay_multiple_times(self): left = Mock() ct = ComposableTransport(left, None) middle = Mock() ct.overlay(middle, 'wallof') right = Mock() ct.overlay(right, 'wallof') self.assertEquals(ct._transports, [left, middle, right]) self.assertIn('wallof', ct._methods) self.assertEquals(ct._methods['wallof'], right.wallof)
def test_close_with_callbacks(self): left = Mock() right = Mock() ct = ComposableTransport(left, right) cb = Mock() ct.add_on_close_callback(cb) self.assertEquals(ct._close_callbacks, [cb]) ct.close() left.close.assert_called_once_with() right.close.assert_called_once_with() cb.assert_called_once_with(ct, 200, "Closed OK")
def _new_channel(self, ch_type, ch_number=None, transport=None): """ Creates a pyon Channel based on the passed in type, and activates it for use. @param transport If specified, will wrap the underlying transport created here. """ chan = ch_type() new_transport = self._new_transport(ch_number=ch_number) # create overlay transport if transport is not None: new_transport = ComposableTransport(transport, new_transport, *ComposableTransport.common_methods) chan.on_channel_open(new_transport) return chan
def test_channel_number(self): left = Mock() right = Mock() ct = ComposableTransport(left, right) self.assertEquals(ct.channel_number, right.channel_number)
def test_overlay_and_call_all_methods(self): left = Mock() right = Mock() ct = ComposableTransport(left, right, *ComposableTransport.common_methods) ct.declare_exchange_impl(sentinel.exchange) ct.delete_exchange_impl(sentinel.exchange) ct.declare_queue_impl(sentinel.queue) ct.delete_queue_impl(sentinel.queue) ct.bind_impl(sentinel.exchange, sentinel.queue, sentinel.binding) ct.unbind_impl(sentinel.exchange, sentinel.queue, sentinel.binding) ct.ack_impl(sentinel.dtag) ct.reject_impl(sentinel.dtag) ct.start_consume_impl(sentinel.callback, sentinel.queue) ct.stop_consume_impl(sentinel.ctag) ct.setup_listener(sentinel.binding, sentinel.callback) ct.get_stats_impl(sentinel.queue) ct.purge_impl(sentinel.queue) ct.qos_impl() ct.publish_impl(sentinel.exchange, sentinel.rkey, sentinel.body, sentinel.props) left.declare_exchange_impl.assert_called_once_with(sentinel.exchange) left.delete_exchange_impl.assert_called_once_with(sentinel.exchange) left.declare_queue_impl.assert_called_once_with(sentinel.queue) left.delete_queue_impl.assert_called_once_with(sentinel.queue) left.bind_impl.assert_called_once_with(sentinel.exchange, sentinel.queue, sentinel.binding) left.unbind_impl.assert_called_once_with(sentinel.exchange, sentinel.queue, sentinel.binding) left.purge_impl.assert_called_once_with(sentinel.queue) left.setup_listener.assert_called_once_with(sentinel.binding, sentinel.callback) right.ack_impl.assert_called_once_with(sentinel.dtag) right.reject_impl.assert_called_once_with(sentinel.dtag, requeue=False) right.start_consume_impl.assert_called_once_with(sentinel.callback, sentinel.queue, no_ack=False, exclusive=False) right.stop_consume_impl.assert_called_once_with(sentinel.ctag) right.get_stats_impl.assert_called_once_with(sentinel.queue) right.qos_impl.assert_called_once_with(prefetch_size=0, prefetch_count=0, global_=False) right.publish_impl.assert_called_once_with(sentinel.exchange, sentinel.rkey, sentinel.body, sentinel.props, immediate=False, mandatory=False, durable_msg=False) # assert non-calls on other side self.assertEquals(right.declare_exchange_impl.call_count, 0) self.assertEquals(right.delete_exchange_impl.call_count, 0) self.assertEquals(right.declare_queue_impl.call_count, 0) self.assertEquals(right.delete_queue_impl.call_count, 0) self.assertEquals(right.bind_impl.call_count, 0) self.assertEquals(right.unbind_impl.call_count, 0) self.assertEquals(right.purge_impl.call_count, 0) self.assertEquals(right.setup_listener.call_count, 0) self.assertEquals(left.ack_impl.call_count, 0) self.assertEquals(left.reject_impl.call_count, 0) self.assertEquals(left.start_consume_impl.call_count, 0) self.assertEquals(left.stop_consume_impl.call_count, 0) self.assertEquals(left.get_stats_impl.call_count, 0) self.assertEquals(left.qos_impl.call_count, 0) self.assertEquals(left.publish_impl.call_count, 0)