def test_run_actions(mock_config): logs_config = { 'both': {'actions': ['a']}, 'one1': {'actions': ['a', 'b']}, 'one2': {'actions': ['b']}, 'none': {'actions': ['c']}, 'nact': {'actions': []}, } actions = { 'a': MagicMock(spec=Action), 'b': MagicMock(spec=Action), 'c': MagicMock(spec=Action) } mock_config({'logs': logs_config, 'actions': actions}) res = { 'both': (['x', 'y'], ['z']), 'one1': (['x', 'y'], []), 'one2': ([], ['z']), 'none': ([], []), 'nact': (['x', 'y'], ['z']), } run_actions(res) actions['a'].run.assert_called_once_with({'both': res['both'], 'one1': res['one1']}) actions['b'].run.assert_called_once_with({'one1': res['one1'], 'one2': res['one2']}) assert not actions['c'].run.called
def run(): """Run logstapo on all configured logs and perform actions""" results = process_logs() run_actions(results)