Exemplo n.º 1
0
def test_should_return_valid_action_if_the_select_agent_return_none(mocker):
    mock_agent = create_mock_agent()
    mocker.patch.object(AgentDatasource,
                        'get_instances',
                        return_value=[mock_agent],
                        autospec=True)
    mock_agent.execute.return_value = None
    mocker.patch.object(ConfigStorage,
                        'read_config',
                        return_value=PluginConfig(selected=["demo_agent"]),
                        autospec=True)
    message_handler = MessageHandler(ServerStatusDatasource(),
                                     AgentDatasource())

    action = message_handler.process_message(command_state())

    assert action.suggested_command is action.origin_command
    assert action.origin_command == command_state().command
    assert not action.execute
    assert not action.description
Exemplo n.º 2
0
def test_should_return_empty_action_from_selected_agent_when_the_command_goes_to_the_agent_and_not_confidence(
        mocker):
    mock_agent = create_mock_agent()
    mocker.patch.object(AgentDatasource,
                        'get_instances',
                        return_value=[mock_agent],
                        autospec=True)
    action_to_execute = Action(suggested_command="command", confidence=0.1)
    mock_agent.execute.return_value = action_to_execute
    mocker.patch.object(ConfigStorage,
                        'read_config',
                        return_value=PluginConfig(selected=["demo_agent"]),
                        autospec=True)
    message_handler = MessageHandler(ServerStatusDatasource(),
                                     AgentDatasource())

    action = message_handler.process_message(command_state())

    assert action.suggested_command is action.origin_command
    assert action.origin_command == command_state().command
    assert not action.execute
    assert not action.description
Exemplo n.º 3
0
def test_should_return_the_suggestion_from_agent_ignoring_confidence_if_is_name_agent_command(
        mocker):
    mock_agent = create_mock_agent()
    mocker.patch.object(AgentDatasource,
                        'get_instances',
                        return_value=[mock_agent],
                        autospec=True)
    action_to_execute = Action(suggested_command="command", confidence=0.0)
    mock_agent.execute.return_value = action_to_execute
    mocker.patch.object(ConfigStorage,
                        'read_config',
                        return_value=PluginConfig(selected=["demo_agent"]),
                        autospec=True)
    message_handler = MessageHandler(ServerStatusDatasource(),
                                     AgentDatasource())

    action = message_handler.process_message(COMMAND_NAME_AGENT_STATE)

    assert action.suggested_command == action_to_execute.suggested_command
    assert action.origin_command == command_state().command
    assert not action.execute
    assert not action.description