mock.sentinel.anon_queue

Here are the examples of the python api mock.sentinel.anon_queue taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

Example 1

Project: pyon Source File: test_channel.py
    def _create_channel(self):
        """
        Test helper method, creates mocked up broker interaction.
        """
        ch = RecvChannel()
        ch._declare_exchange = Mock()
        ch._declare_queue = Mock()
        ch._declare_queue.return_value = sentinel.anon_queue
        ch._bind = Mock()
        return ch

Example 2

Project: pyon Source File: test_channel.py
    def test_setup_listener(self):
        # sub in mocks for _declare_exchange, _declare_queue, _bind
        mxp = Mock()
        mdq = Mock()
        mdq.return_value = sentinel.anon_queue
        mb = Mock()

        def create_channel():
            ch = RecvChannel()
            ch._declare_exchange = mxp
            ch._declare_queue = mdq
            ch._bind = mb
            return ch
        
        ch = create_channel()

        self.assertFalse(ch._setup_listener_called)

        # call setup listener, defining xp, queue, binding
        ch.setup_listener(NameTrio(sentinel.xp, sentinel.queue, sentinel.binding))

        self.assertTrue(hasattr(ch, '_recv_name'))
        self.assertTrue(hasattr(ch._recv_name, 'exchange'))
        self.assertTrue(hasattr(ch._recv_name, 'queue'))
        self.assertEquals(ch._recv_name.exchange, sentinel.xp)
        self.assertEquals(ch._recv_name.queue, sentinel.queue)

        mxp.assert_called_once_with(sentinel.xp)
        mdq.assert_called_once_with(sentinel.queue)
        mb.assert_called_once_with(sentinel.binding)
        
        # you can only call setup_listener once
        self.assertTrue(ch._setup_listener_called)
        
        # calling it again does nothing, does not touch anything
        ch.setup_listener(NameTrio(sentinel.xp2, sentinel.queue2))

        self.assertTrue(hasattr(ch._recv_name, 'exchange'))
        self.assertTrue(hasattr(ch._recv_name, 'queue'))
        self.assertEquals(ch._recv_name.exchange, sentinel.xp)
        self.assertEquals(ch._recv_name.queue, sentinel.queue)
        mxp.assert_called_once_with(sentinel.xp)
        mdq.assert_called_once_with(sentinel.queue)
        mb.assert_called_once_with(sentinel.binding)

        # call setup listener, passing a custom bind this time
        ch = create_channel()
        ch.setup_listener(NameTrio(sentinel.xp2, sentinel.queue2), binding=sentinel.binding)

        mxp.assert_called_with(sentinel.xp2)
        mdq.assert_called_with(sentinel.queue2)
        mb.assert_called_with(sentinel.binding)

        # call setup_listener, use anonymous queue name and no binding (will get return value we set above)
        ch = create_channel()
        ch.setup_listener(NameTrio(sentinel.xp3))

        mxp.assert_called_with(sentinel.xp3)
        mdq.assert_called_with(None)
        mb.assert_called_with(sentinel.anon_queue)

        # call setup_listener with anon queue name but with binding
        ch = create_channel()
        ch.setup_listener(NameTrio(sentinel.xp4), binding=sentinel.binding2)

        mxp.assert_called_with(sentinel.xp4)
        mdq.assert_called_with(None)
        mb.assert_called_with(sentinel.binding2)