Exemplo n.º 1
0
    def test_route_response_false(self, mock_logging, mock_defer,
                                  mock_reactor):
        test_func = Mock()
        mock_pm = Mock()
        mock_pm.do.return_value = False
        mock_self = Mock()
        mock_self.plugin_manager = mock_pm

        test_f = route(test_func)
        test_f(mock_self, 'data')

        mock_pm.do.assert_called_with(mock_self, 'on', 'data')
        self.assertFalse(mock_defer.called)
    def test_route_response_false(
        self, mock_logging, mock_defer, mock_reactor
    ):
        test_func = Mock()
        mock_pm = Mock()
        mock_pm.do.return_value = False
        mock_self = Mock()
        mock_self.plugin_manager = mock_pm

        test_f = route(test_func)
        test_f(mock_self, 'data')

        mock_pm.do.assert_called_with(mock_self, 'on', 'data')
        self.assertFalse(mock_defer.called)
Exemplo n.º 3
0
    def test_route_response_true(self, mock_logging, mock_defer, mock_reactor):
        test_func = Mock()
        mock_pm = Mock()
        mock_self = Mock()
        mock_self.plugin_manager = mock_pm
        add_err_back = Mock()
        mock_defer.return_value = add_err_back
        logger = Mock()
        mock_logging.getLogger.return_value = logger

        test_f = route(test_func)
        test_f(mock_self, 'data')

        mock_pm.do.assert_called_with(mock_self, 'on', 'data')
        mock_defer.assert_called_with(mock_reactor, .01, mock_pm.do, mock_self,
                                      'after', 'data')
        self.assertTrue(add_err_back.addErrback.called)
        self.assertTrue(mock_logging.getLogger.called)

        error_callback = add_err_back.addErrback.call_args[0][0]
        self.assertFalse(logger.error.called)
        error_callback('test')
        self.assertTrue(logger.error.called)
    def test_route_response_true(self, mock_logging, mock_defer, mock_reactor):
        test_func = Mock()
        mock_pm = Mock()
        mock_self = Mock()
        mock_self.plugin_manager = mock_pm
        add_err_back = Mock()
        mock_defer.return_value = add_err_back
        logger = Mock()
        mock_logging.getLogger.return_value = logger

        test_f = route(test_func)
        test_f(mock_self, 'data')

        mock_pm.do.assert_called_with(mock_self, 'on', 'data')
        mock_defer.assert_called_with(
            mock_reactor, .01, mock_pm.do, mock_self, 'after', 'data'
        )
        self.assertTrue(add_err_back.addErrback.called)
        self.assertTrue(mock_logging.getLogger.called)

        error_callback = add_err_back.addErrback.call_args[0][0]
        self.assertFalse(logger.error.called)
        error_callback('test')
        self.assertTrue(logger.error.called)