from __future__ import absolute_import import pickle from kombu import Connection, Exchange, Producer, Queue, binding from kombu.exceptions import NotBoundError from kombu.serialization import registry from .case import Case, Mock, call from .mocks import Transport def get_conn(): return Connection(transport=Transport) class test_binding(Case): def test_constructor(self): x = binding( Exchange('foo'), 'rkey', arguments={'barg': 'bval'}, unbind_arguments={'uarg': 'uval'}, ) self.assertEqual(x.exchange, Exchange('foo')) self.assertEqual(x.routing_key, 'rkey') self.assertDictEqual(x.arguments, {'barg': 'bval'}) self.assertDictEqual(x.unbind_arguments, {'uarg': 'uval'}) def test_declare(self): chan = get_conn().channel() x = binding(Exchange('foo'), 'rkey') x.declare(chan) self.assertIn('exchange_declare', chan) def test_declare_no_exchange(self): chan = get_conn().channel() x = binding() x.declare(chan) self.assertNotIn('exchange_declare', chan) def test_bind(self): chan = get_conn().channel() x = binding(Exchange('foo')) x.bind(Exchange('bar')(chan)) self.assertIn('exchange_bind', chan) def test_unbind(self): chan = get_conn().channel() x = binding(Exchange('foo')) x.unbind(Exchange('bar')(chan)) self.assertIn('exchange_unbind', chan) def test_repr(self): b = binding(Exchange('foo'), 'rkey') self.assertIn('foo', repr(b)) self.assertIn('rkey', repr(b)) class test_Exchange(Case): def test_bound(self): exchange = Exchange('foo', 'direct') self.assertFalse(exchange.is_bound) self.assertIn('