コード例 #1
0
ファイル: test_pyamqp.py プロジェクト: StackOps/kombu
    def test_close_connection(self):
        connection = Mock()
        connection.client = Mock()
        self.transport.close_connection(connection)

        self.assertIsNone(connection.client)
        connection.close.assert_called_with()
コード例 #2
0
ファイル: test_amqplib.py プロジェクト: DHLabs/keep_isn
    def test_verify_connection(self):
        connection = Mock()
        connection.channels = None
        self.assertFalse(self.transport.verify_connection(connection))

        connection.channels = {1: 1, 2: 2}
        self.assertTrue(self.transport.verify_connection(connection))
コード例 #3
0
ファイル: test_redis.py プロジェクト: StackOps/kombu
    def test_register_BRPOP(self):
        p = self.Poller()
        channel = Mock()
        channel.client.connection._sock = None
        p._register = Mock()

        channel._in_poll = False
        p._register_BRPOP(channel)
        self.assertEqual(channel._brpop_start.call_count, 1)
        self.assertEqual(p._register.call_count, 1)

        channel.client.connection._sock = Mock()
        p._chan_to_sock[(channel, channel.client, 'BRPOP')] = True
        channel._in_poll = True
        p._register_BRPOP(channel)
        self.assertEqual(channel._brpop_start.call_count, 1)
        self.assertEqual(p._register.call_count, 1)
コード例 #4
0
ファイル: test_redis.py プロジェクト: StackOps/kombu
    def test_register_LISTEN(self):
        p = self.Poller()
        channel = Mock()
        channel.subclient.connection._sock = None
        channel._in_listen = False
        p._register = Mock()

        p._register_LISTEN(channel)
        p._register.assert_called_with(channel, channel.subclient, 'LISTEN')
        self.assertEqual(p._register.call_count, 1)
        self.assertEqual(channel._subscribe.call_count, 1)

        channel._in_listen = True
        channel.subclient.connection._sock = Mock()
        p._register_LISTEN(channel)
        self.assertEqual(p._register.call_count, 1)
        self.assertEqual(channel._subscribe.call_count, 1)
コード例 #5
0
ファイル: test_redis.py プロジェクト: StackOps/kombu
    def create_get(self, events=None, queues=None, fanouts=None):
        _pr = [] if events is None else events
        _aq = [] if queues is None else queues
        _af = [] if fanouts is None else fanouts
        p = self.Poller()
        p.poller = Mock()
        p.poller.poll.return_value = _pr

        p._register_BRPOP = Mock()
        p._register_LISTEN = Mock()

        channel = Mock()
        p._channels = [channel]
        channel.active_queues = _aq
        channel.active_fanout_queues = _af

        return p, channel
コード例 #6
0
ファイル: test_redis.py プロジェクト: frol/kombu
    def test_has_queue(self):
        self.channel._in_poll = False
        exists = self.channel.client.exists = Mock()
        exists.return_value = True
        self.assertTrue(self.channel._has_queue('foo'))
        exists.assert_has_call('foo')

        exists.return_value = False
        self.assertFalse(self.channel._has_queue('foo'))
コード例 #7
0
ファイル: test_redis.py プロジェクト: frol/kombu
 def test_receive(self):
     s = self.channel.subclient = Mock()
     self.channel._fanout_to_queue['a'] = 'b'
     s.parse_response.return_value = [
         'message', 'a', dumps({'hello': 'world'})
     ]
     payload, queue = self.channel._receive()
     self.assertDictEqual(payload, {'hello': 'world'})
     self.assertEqual(queue, 'b')
コード例 #8
0
ファイル: test_base.py プロジェクト: FluidInc/8b-kombu
    def test_basic_cancel_not_in_active_queues(self):
        c = self.channel
        c._consumers.add('x')
        c._tag_to_queue['x'] = 'foo'
        c._active_queues = Mock()
        c._active_queues.remove.side_effect = ValueError()

        c.basic_cancel('x')
        c._active_queues.remove.assert_called_with('foo')
コード例 #9
0
ファイル: test_redis.py プロジェクト: zuma89/mozillians
 def test_receive(self):
     s = self.channel.subclient = Mock()
     self.channel._fanout_to_queue["a"] = "b"
     s.parse_response.return_value = [
         "message", "a", dumps({"hello": "world"})
     ]
     payload, queue = self.channel._receive()
     self.assertDictEqual(payload, {"hello": "world"})
     self.assertEqual(queue, "b")
コード例 #10
0
    def test_close_unregisters_fds(self):
        p = self.Poller()
        poller = p.poller = Mock()
        p._chan_to_sock.update({1: 1, 2: 2, 3: 3})

        p.close()

        self.assertEqual(poller.unregister.call_count, 3)
        u_args = poller.unregister.call_args_list

        self.assertItemsEqual(u_args, [((1, ), {}), ((2, ), {}), ((3, ), {})])
コード例 #11
0
ファイル: test_base.py プロジェクト: FluidInc/8b-kombu
    def test_restore_unacked_once_when_unrestored(self, say,
                                                  emergency_dump_state):
        q = self.channel.qos
        q._flush = Mock()

        class State(dict):
            restored = False

        q._delivered = State({1: 1})
        ru = q.restore_unacked = Mock()
        exc = None
        try:
            raise KeyError()
        except KeyError as exc_:
            exc = exc_
        ru.return_value = [(exc, 1)]

        self.channel.do_restore = True
        q.restore_unacked_once()
        self.assertTrue(say.called)
        self.assertTrue(emergency_dump_state.called)
コード例 #12
0
ファイル: test_redis.py プロジェクト: imtapps/kombu
    def test_register_when_registered_reregisters(self):
        p = self.Poller()
        p.poller = Mock()
        channel, client, type = Mock(), Mock(), Mock()
        sock = client.connection._sock = Mock()
        sock.fileno.return_value = 10

        p._chan_to_sock = {(channel, client, type): 6}
        p._register(channel, client, type)
        p.poller.unregister.assert_called_with(6)
        self.assertTupleEqual(p._fd_to_chan[10], (channel, type))
        self.assertEqual(p._chan_to_sock[(channel, client, type)], sock)
        p.poller.register.assert_called_with(sock, p.eventflags)

        # when client not connected yet
        client.connection._sock = None

        def after_connected():
            client.connection._sock = Mock()
        client.connection.connect.side_effect = after_connected

        p._register(channel, client, type)
        client.connection.connect.assert_called_with()
コード例 #13
0
    def test_subscribe(self):
        self.channel.subclient = Mock()
        self.channel.active_fanout_queues.add('a')
        self.channel.active_fanout_queues.add('b')
        self.channel._fanout_queues.update(a='a', b='b')

        self.channel._subscribe()
        self.assertTrue(self.channel.subclient.subscribe.called)
        s_args, _ = self.channel.subclient.subscribe.call_args
        self.assertItemsEqual(s_args[0], ['a', 'b'])

        self.channel.subclient.connection._sock = None
        self.channel._subscribe()
        self.channel.subclient.connection.connect.assert_called_with()
コード例 #14
0
    def create_get(self, events=None, queues=None, fanouts=None):
        _pr = [] if events is None else events
        _aq = [] if queues is None else queues
        _af = [] if fanouts is None else fanouts
        p = self.Poller()
        p.poller = Mock()
        p.poller.poll.return_value = _pr

        p._register_BRPOP = Mock()
        p._register_LISTEN = Mock()

        channel = Mock()
        p._channels = [channel]
        channel.active_queues = _aq
        channel.active_fanout_queues = _af

        return p, channel
コード例 #15
0
ファイル: test_pyamqp.py プロジェクト: romand/kombu
    def setUp(self):
        if pyamqp is None:
            raise SkipTest('py-amqp not installed')

        class Channel(pyamqp.Channel):
            wait_returns = []

            def _x_open(self, *args, **kwargs):
                pass

            def wait(self, *args, **kwargs):
                return self.wait_returns

            def _send_method(self, *args, **kwargs):
                pass

        self.conn = Mock()
        self.conn.channels = {}
        self.channel = Channel(self.conn, 0)
コード例 #16
0
ファイル: test_pyamqp.py プロジェクト: FluidInc/8b-kombu
    def setUp(self):
        if pyamqp is None:
            raise SkipTest('py-amqp not installed')

        class Channel(pyamqp.Channel):
            wait_returns = []

            def _x_open(self, *args, **kwargs):
                pass

            def wait(self, *args, **kwargs):
                return self.wait_returns

            def _send_method(self, *args, **kwargs):
                pass

        self.conn = Mock()
        self.conn._get_free_channel_id.side_effect = partial(next, count(0))
        self.conn.channels = {}
        self.channel = Channel(self.conn, 0)
コード例 #17
0
    def test_register_BRPOP(self):
        p = self.Poller()
        channel = Mock()
        channel.client.connection._sock = None
        p._register = Mock()

        channel._in_poll = False
        p._register_BRPOP(channel)
        self.assertEqual(channel._brpop_start.call_count, 1)
        self.assertEqual(p._register.call_count, 1)

        channel.client.connection._sock = Mock()
        p._chan_to_sock[(channel, channel.client, 'BRPOP')] = True
        channel._in_poll = True
        p._register_BRPOP(channel)
        self.assertEqual(channel._brpop_start.call_count, 1)
        self.assertEqual(p._register.call_count, 1)
コード例 #18
0
    def test_register_LISTEN(self):
        p = self.Poller()
        channel = Mock()
        channel.subclient.connection._sock = None
        channel._in_listen = False
        p._register = Mock()

        p._register_LISTEN(channel)
        p._register.assert_called_with(channel, channel.subclient, 'LISTEN')
        self.assertEqual(p._register.call_count, 1)
        self.assertEqual(channel._subscribe.call_count, 1)

        channel._in_listen = True
        channel.subclient.connection._sock = Mock()
        p._register_LISTEN(channel)
        self.assertEqual(p._register.call_count, 1)
        self.assertEqual(channel._subscribe.call_count, 1)
コード例 #19
0
 def _get_pool(self):
     return Mock()
コード例 #20
0
    def test_subscribe_no_queues(self):
        self.channel.subclient = Mock()
        self.channel.active_fanout_queues.clear()
        self.channel._subscribe()

        self.assertFalse(self.channel.subclient.subscribe.called)
コード例 #21
0
ファイル: test_pyamqp.py プロジェクト: romand/kombu
 def test_drain_events(self):
     connection = Mock()
     self.transport.drain_events(connection, timeout=10.0)
     connection.drain_events.assert_called_with(timeout=10.0)
コード例 #22
0
ファイル: test_pyamqp.py プロジェクト: romand/kombu
 def test_create_channel(self):
     connection = Mock()
     self.transport.create_channel(connection)
     connection.channel.assert_called_with()
コード例 #23
0
ファイル: test_pyamqp.py プロジェクト: romand/kombu
 def test_message_to_python(self):
     message = Mock()
     message.headers = {}
     message.properties = {}
     self.assertTrue(self.channel.message_to_python(message))
コード例 #24
0
 def test_close_when_unregister_raises_KeyError(self):
     p = self.Poller()
     p.poller = Mock()
     p._chan_to_sock.update({1: 1})
     p.poller.unregister.side_effect = KeyError(1)
     p.close()
コード例 #25
0
    def test_receive_different_message_Type(self):
        s = self.channel.subclient = Mock()
        s.parse_response.return_value = ['pmessage', '/foo/', 0, 'data']

        with self.assertRaises(redis.Empty):
            self.channel._receive()
コード例 #26
0
ファイル: test_pyamqp.py プロジェクト: romand/kombu
 def test_heartbeat_check(self):
     t = pyamqp.Transport(Mock())
     conn = Mock()
     t.heartbeat_check(conn, rate=4.331)
     conn.heartbeat_tick.assert_called_with(rate=4.331)
コード例 #27
0
ファイル: test_pyamqp.py プロジェクト: romand/kombu
 def test_event_interface(self):
     t = pyamqp.Transport(Mock())
     t.on_poll_init(Mock())
     t.on_poll_start()
コード例 #28
0
    def test_receive_empty(self):
        s = self.channel.subclient = Mock()
        s.parse_response.return_value = None

        with self.assertRaises(redis.Empty):
            self.channel._receive()
コード例 #29
0
 def test_ack_log_error_when_no_error(self):
     ack = self.message.ack = Mock()
     self.message.ack_log_error(Mock(), KeyError)
     ack.assert_called_with()
コード例 #30
0
    def test_avail_client_when_not_in_poll(self):
        self.channel._in_poll = False
        c = self.channel.client = Mock()

        with self.channel.conn_or_acquire() as client:
            self.assertIs(client, c)
コード例 #31
0
ファイル: test_pyamqp.py プロジェクト: StackOps/kombu
 def test_message_to_python(self):
     message = Mock()
     message.headers = {}
     message.properties = {}
     self.assertTrue(self.channel.message_to_python(message))
コード例 #32
0
ファイル: test_pyamqp.py プロジェクト: romand/kombu
 def test_get_manager(self):
     with patch('kombu.transport.pyamqp.get_manager') as get_manager:
         t = pyamqp.Transport(Mock())
         t.get_manager(1, kw=2)
         get_manager.assert_called_with(t.client, 1, kw=2)
コード例 #33
0
    def test_brpop_read_gives_None(self):
        c = self.channel.client = Mock()
        c.parse_response.return_value = None

        with self.assertRaises(redis.Empty):
            self.channel._brpop_read()
コード例 #34
0
    def test_close_client_close_raises(self):
        c = self.channel.client = Mock()
        c.connection.disconnect.side_effect = self.channel.ResponseError()

        self.channel.close()
        c.connection.disconnect.assert_called_with()
コード例 #35
0
ファイル: test_pyamqp.py プロジェクト: romand/kombu
 def test_eventmap(self):
     t = pyamqp.Transport(Mock())
     conn = Mock()
     self.assertDictEqual(t.eventmap(conn),
                          {conn.sock: t.client.drain_nowait})
コード例 #36
0
 def after_connected():
     client.connection._sock = Mock()