示例#1
0
def test_should_return_the_list_with_the_new_selected_values_if_exists_and_is_installed(
        mocker):
    mock_agent = create_mock_agent()
    mocker.patch.object(AgentDatasource,
                        'get_instances',
                        return_value=[mock_agent],
                        autospec=True)
    mocker.patch.object(ConfigStorage,
                        'read_config',
                        return_value=PluginConfig(selected=["demo_agent"]),
                        autospec=True)
    mocker.patch.object(ConfigStorage,
                        'store_config',
                        return_value=None,
                        autospec=True)
    mocker.patch.object(AgentDatasource,
                        'all_plugins',
                        return_value=ALL_PLUGINS_WITH_TAR_INSTALLED,
                        autospec=True)
    message_handler = MessageHandler(ServerStatusDatasource(),
                                     AgentDatasource())

    select_agent = clai_select_state('nlc2cmd')
    action = message_handler.process_message(select_agent)

    assert action.suggested_command == NOOP_COMMAND
    assert action.origin_command == select_agent.command
    assert action.execute
    assert message_handler.agent_datasource.get_current_plugin_name(
        select_agent.user_name) == ['nlc2cmd']
示例#2
0
def test_should_return_an_error_when_selected_is_empty(mocker):
    mock_agent = create_mock_agent()
    mocker.patch.object(AgentDatasource,
                        'get_instances',
                        return_value=[mock_agent],
                        autospec=True)
    mocker.patch.object(AgentDatasource,
                        'all_plugins',
                        return_value=ALL_PLUGINS,
                        autospec=True)
    mocker.patch.object(ConfigStorage,
                        'read_config',
                        return_value=PluginConfig(selected=["nlc2cmd"]),
                        autospec=True)
    mocker.patch.object(ConfigStorage,
                        'store_config',
                        return_value=None,
                        autospec=True)
    message_handler = MessageHandler(ServerStatusDatasource(),
                                     AgentDatasource())

    select_agent = clai_select_state('')
    action = message_handler.process_message(select_agent)

    assert action.suggested_command == NOOP_COMMAND
    assert action.origin_command == select_agent.command
    assert action.execute
    assert action.description == create_error_select('').description
    assert message_handler.agent_datasource.get_current_plugin_name(
        select_agent.user_name) == ['nlc2cmd']
示例#3
0
def test_should_return_the_install_command_when_the_new_plugin_is_not_installed_yet(
        mocker):
    mock_agent = create_mock_agent()
    mocker.patch.object(AgentDatasource,
                        'get_instances',
                        return_value=[mock_agent],
                        autospec=True)
    mocker.patch.object(ConfigStorage,
                        'read_config',
                        return_value=PluginConfig(selected=["nlc2cmd"]),
                        autospec=True)
    mocker.patch.object(ConfigStorage,
                        'store_config',
                        return_value=None,
                        autospec=True)
    mocker.patch.object(AgentDatasource,
                        'all_plugins',
                        return_value=ALL_PLUGINS,
                        autospec=True)
    message_handler = MessageHandler(ServerStatusDatasource(),
                                     AgentDatasource())

    select_agent = clai_select_state('nlc2cmd')
    action = message_handler.process_message(select_agent)

    assert action.suggested_command == "$CLAI_PATH/fileExist.sh nlc2cmd"
    assert action.origin_command == select_agent.command
    assert message_handler.agent_datasource.get_current_plugin_name(
        select_agent.user_name) == ['nlc2cmd']