def test_get_channel_id(self): ch = BaseChannel() self.assertTrue(ch.get_channel_id() is None) ch.on_channel_open(Mock()) self.assertEquals(ch.get_channel_id(), ch._transport.channel_number)
def test_on_channel_close(self): ch = BaseChannel() ch._amq_chan = Mock() ch._amq_chan.channel_number = 1 ch.on_channel_close(0, 'hi') self.assertIsNone(ch._amq_chan)
def test_on_channel_close(self): ch = BaseChannel() ch.on_channel_open(Mock()) ch._transport.channel_number = 1 ch.on_channel_close(ch, 0, 'hi') self.assertIsNone(ch._transport)
def test_get_channel_id(self): ch = BaseChannel() self.assertTrue(ch.get_channel_id() is None) ch._amq_chan = Mock() self.assertEquals(ch.get_channel_id(), ch._amq_chan.channel_number)
def test__sync_call_with_mult_rets(self): def async_func(*args, **kwargs): cbparam = kwargs.get('callback') cbparam(sentinel.val, sentinel.val2) ch = BaseChannel() rv = ch._sync_call(async_func, 'callback') self.assertEquals(rv, (sentinel.val, sentinel.val2))
def test__sync_call_with_normal_and_kwarg_rets(self): def async_func(*args, **kwargs): cbparam = kwargs.get('callback') cbparam(sentinel.arg, sup=sentinel.val, sup2=sentinel.val2) ch = BaseChannel() rv = ch._sync_call(async_func, 'callback') self.assertEquals(rv, (sentinel.arg, {'sup':sentinel.val, 'sup2':sentinel.val2}))
def test_on_channel_open(self): ch = BaseChannel() ac = Mock(pchannel.Channel) ch.on_channel_open(ac) ac.add_on_close_callback.assert_called_once_with(ch.on_channel_close) self.assertEquals(ch._amq_chan, ac)
def test_close_with_callback(self): # with close callback cbmock = Mock() ch = BaseChannel(close_callback=cbmock) ch._fsm.current_state = ch.S_ACTIVE ch.close() cbmock.assert_called_once_with(ch)
def test_on_channel_open(self): ch = BaseChannel() transport = Mock() ch.on_channel_open(transport) transport.add_on_close_callback.assert_called_once_with(ch.on_channel_close) self.assertEquals(ch._transport, transport)
def test__sync_call_with_kwarg_rets(self): def async_func(*args, **kwargs): cbparam = kwargs.get("callback") cbparam(sup=sentinel.val, sup2=sentinel.val2) ch = BaseChannel() rv = ch._sync_call(async_func, "callback") self.assertEquals(rv, {"sup": sentinel.val, "sup2": sentinel.val2})
def test__sync_call_with_ret_value(self): def async_func(*args, **kwargs): cbparam = kwargs.get("callback") cbparam(sentinel.val) ch = BaseChannel() rv = ch._sync_call(async_func, "callback") self.assertEquals(rv, sentinel.val)
def test__sync_call_no_ret_value(self): def async_func(*args, **kwargs): cbparam = kwargs.get("callback") cbparam() ch = BaseChannel() rv = ch._sync_call(async_func, "callback") self.assertIsNone(rv)
def test_on_channel_open(self): ch = BaseChannel() transport = Mock() ch.on_channel_open(transport) transport.add_on_close_callback.assert_called_once_with( ch.on_channel_close) self.assertEquals(ch._transport, transport)
def test_close(self): # without close callback transport = Mock() ch = BaseChannel() ch.on_channel_open(transport) ch._fsm.current_state = ch.S_ACTIVE ch.close() transport.close.assert_called_once_with()
def test_close(self): # without close callback ac = Mock() #pchannel.Channel) # cannot use this because callbacks is populated dynamically ch = BaseChannel() ch._amq_chan = ac ch._fsm.current_state = ch.S_ACTIVE ch.close() ac.close.assert_called_once_with() self.assertEquals(ac.callbacks.remove.call_count, 4)
def test__sync_call_with_normal_and_kwarg_rets(self): def async_func(*args, **kwargs): cbparam = kwargs.get('callback') cbparam(sentinel.arg, sup=sentinel.val, sup2=sentinel.val2) ch = BaseChannel() rv = ch._sync_call(async_func, 'callback') self.assertEquals(rv, (sentinel.arg, { 'sup': sentinel.val, 'sup2': sentinel.val2 }))
def test_close(self): # without close callback ac = Mock( ) #pchannel.Channel) # cannot use this because callbacks is populated dynamically ch = BaseChannel() ch._amq_chan = ac ch._fsm.current_state = ch.S_ACTIVE ch.close() ac.close.assert_called_once_with() self.assertEquals(ac.callbacks.remove.call_count, 4)
def test_declare_exchange_point(self): # make sure no xp param results in assertion ch = BaseChannel() self.assertRaises(AssertionError, ch._declare_exchange, None) transport = Mock() ch.on_channel_open(transport) ch._declare_exchange('hello') self.assertTrue(transport.declare_exchange_impl.called) self.assertIn('hello', transport.declare_exchange_impl.call_args[0]) self.assertIn('exchange_type', transport.declare_exchange_impl.call_args[1]) self.assertIn('durable', transport.declare_exchange_impl.call_args[1]) self.assertIn('auto_delete', transport.declare_exchange_impl.call_args[1])
def test_declare_exchange_point(self): # make sure no xp param results in assertion ch = BaseChannel() self.assertRaises(AssertionError, ch._declare_exchange, None) ch._transport = Mock() ch._amq_chan = Mock() ch._declare_exchange("hello") self.assertTrue(ch._transport.declare_exchange_impl.called) self.assertIn(ch._amq_chan, ch._transport.declare_exchange_impl.call_args[0]) self.assertIn("hello", ch._transport.declare_exchange_impl.call_args[0]) self.assertIn("exchange_type", ch._transport.declare_exchange_impl.call_args[1]) self.assertIn("durable", ch._transport.declare_exchange_impl.call_args[1]) self.assertIn("auto_delete", ch._transport.declare_exchange_impl.call_args[1])
def test__sync_call_with_error(self): ch = BaseChannel() def async_func(*args, **kwargs): ch.on_channel_close(1, 'bam') self.assertRaises(ChannelError, ch._sync_call, async_func, 'callback')
def test_on_channel_closed_with_error_callback(self): ch = BaseChannel() ch.on_channel_open(Mock()) ch._transport.channel_number = 1 closemock = Mock() ch.set_closed_error_callback(closemock) ch.on_channel_close(ch, 1, 'hi') closemock.assert_called_once_with(ch, 1, 'hi')
def test_on_channel_close_with_error_in_error_callback(self, logmock): ch = BaseChannel() ch.on_channel_open(Mock()) ch._transport.channel_number = 1 closemock = Mock() closemock.side_effect = StandardError ch.set_closed_error_callback(closemock) ch.on_channel_close(ch, 1, 'hi') self.assertEquals(logmock.warn.call_count, 1)
def test_on_channel_closed_with_error_callback(self): ch = BaseChannel() ch._amq_chan = Mock() ch._amq_chan.channel_number = 1 closemock = Mock() ch.set_closed_error_callback(closemock) ch.on_channel_close(1, 'hi') closemock.assert_called_once_with(ch, 1, 'hi')
def test_declare_exchange_point(self): # make sure no xp param results in assertion ch = BaseChannel() self.assertRaises(AssertionError, ch._declare_exchange_point, None) # test it for real ac = Mock(spec=pchannel.Channel) def cbparam(*args, **kwargs): cbkwarg = kwargs.get('callback') cbkwarg(kwargs.get('exchange')) return kwargs.get('exchange') ac.exchange_declare.side_effect = cbparam ch._amq_chan = ac ch._declare_exchange_point('hello') self.assertTrue(ac.exchange_declare.called) self.assertIn('exchange', ac.exchange_declare.call_args[1]) self.assertIn('type', ac.exchange_declare.call_args[1]) self.assertIn('durable', ac.exchange_declare.call_args[1]) self.assertIn('auto_delete', ac.exchange_declare.call_args[1]) self.assertIn('hello', ac.exchange_declare.call_args[1].itervalues())
def test_on_channel_close(self): # er this just does logging, make the calls anyway for coverage. ch = BaseChannel() ch._amq_chan = Mock() ch._amq_chan.channel_number = 1 ch.on_channel_close(0, 'hi') ch.on_channel_close(1, 'onoes')
def test_on_channel_close_with_error_in_error_callback(self, logmock): ch = BaseChannel() ch._amq_chan = Mock() ch._amq_chan.channel_number = 1 closemock = Mock() closemock.side_effect = StandardError ch.set_closed_error_callback(closemock) ch.on_channel_close(1, "hi") self.assertEquals(logmock.warn.call_count, 1)
def test_close(self): # with close callback cbmock = Mock() ch = BaseChannel(close_callback=cbmock) ch.close() cbmock.assert_called_once_with(ch) # without close callback ac = Mock() #pchannel.Channel) # cannot use this because callbacks is populated dynamically ch = BaseChannel() ch._amq_chan = ac ch.close() ac.close.assert_called_once_with() self.assertEquals(ac.callbacks.remove.call_count, 4)
def test__ensure_transport(self): ch = BaseChannel() with self.assertRaises(ChannelError): with ch._ensure_transport(): pass
def test_attach_underlying_channel(self): ch = BaseChannel() ch.attach_underlying_channel(sentinel.amq_chan) self.assertEquals(ch._amq_chan, sentinel.amq_chan)
def test_init(self): ch = BaseChannel() self.assertIsNone(ch._close_callback) ch = BaseChannel(close_callback=sentinel.closecb) self.assertEquals(ch._close_callback, sentinel.closecb)
def test__ensure_amq_chan(self): ch = BaseChannel() self.assertRaises(ChannelError, ch._ensure_amq_chan)