Example #1
0
class TestHandler(object):

    _HANDLER_CONFIG = """
        protocol.include = Log,
        protocol.exclude = AccessRights,"""
        
    def setup_method(self, _):
        self._handler = Handler(None)
        self._config = ConfigObj(self._HANDLER_CONFIG.splitlines())
        self._handler._singularize = mock.Mock()
        self._handler._summarize = mock.Mock()
        
    def test_singularize_check_not_skipped(self):
        entry = mock.Mock(check="Log")
        entry.is_included.return_value = True
        self._handler.singularize(self._config, entry, debug=True)
        assert self._handler._singularize.called
        
    def test_singularize_check_skipped(self):
        entry = mock.Mock(check="AccessRights")
        entry.is_included.return_value = False
        self._handler.singularize(self._config, entry, debug=True)
        assert not self._handler._singularize.called
        
    def test_singularize_error(self):
        entry = mock.Mock(check="Log")
        entry.is_included.return_value = True
        self._handler._singularize.side_effect = ValueError
        pytest.raises(ValueError,
            self._handler.singularize, self._config, entry, debug=True)
        
    def test_summarize_success(self):
        protocol = mock.MagicMock()
        self._handler.summarize(self._config, protocol, debug=True)
        assert self._handler._summarize.called
        assert protocol.filter.called
        
    def test_summarize_error(self):
        protocol = mock.MagicMock()
        self._handler._summarize.side_effect = ValueError
        pytest.raises(ValueError, 
            self._handler.summarize, self._config, protocol, debug=True)
        assert protocol.filter.called
Example #2
0
    def __init__(self, transaction):
        Handler.__init__(self, transaction)

        self._sender = transaction.user_id + "@" + socket.gethostname()
Example #3
0
 def setup_method(self, _):
     self._handler = Handler(None)
     self._config = ConfigObj(self._HANDLER_CONFIG.splitlines())
     self._handler._singularize = mock.Mock()
     self._handler._summarize = mock.Mock()
Example #4
0
    def __init__(self, transaction):
        Handler.__init__(self, transaction)

        self._sender = transaction.user_id + "@" + socket.gethostname()