Exemple #1
0
def test_should_print_the_suggested_dialog_when_suggested_is_different(mocker):
    spy_print(mocker)
    mock_input_console(mocker, 'n')
    mocker.patch.object(ClaiClient,
                        'send',
                        return_value=SUGGESTED_ACTION,
                        autospec=True)

    process_command_from_user(ANY_ID, ANY_USER, ANY_INPUT_COMMAND)

    # pylint: disable=no-member
    assert print.call_count == 1
Exemple #2
0
def test_should_not_print_the_suggested_dialog_when_suggested_is_different_and_execute_is_enable(
        mocker):
    spy_print(mocker)
    mocker.patch.object(ClaiClient,
                        'send',
                        return_value=EXECUTABLE_ACTION,
                        autospec=True)

    process_command_from_user(ANY_ID, ANY_USER, ANY_NO_ACTION.origin_command)

    # pylint: disable=no-member
    assert print.call_count == 0
Exemple #3
0
def test_should_not_print_the_suggested_dialog_when_the_action_only_contains_original_command(
        mocker):
    spy_print(mocker)
    mocker.patch.object(ClaiClient,
                        'send',
                        return_value=BASIC_ACTION,
                        autospec=True)

    process_command_from_user(ANY_ID, ANY_USER, ANY_INPUT_COMMAND)

    # pylint: disable=no-member
    assert print.call_count == 0
Exemple #4
0
def test_should_not_print_the_suggested_dialog_when_suggested_command_is_empty(
        mocker):
    spy_print(mocker)
    empty_suggested_command = Action(origin_command=ANY_INPUT_COMMAND,
                                     suggested_command="")
    mocker.patch.object(ClaiClient,
                        'send',
                        return_value=empty_suggested_command,
                        autospec=True)

    process_command_from_user(ANY_ID, ANY_USER, ANY_INPUT_COMMAND)

    # pylint: disable=no-member
    assert print.call_count == 0
Exemple #5
0
def test_should_return_the_original_command_when_read_throw_exception(mocker):
    mocker.patch.object(ClientConnector,
                        'send',
                        side_effect=socket.error(),
                        autospec=True)

    command_to_execute, _ = process_command_from_user(ANY_ID, ANY_USER,
                                                      ANY_INPUT_COMMAND)

    assert command_to_execute == ANY_INPUT_COMMAND
Exemple #6
0
def test_should_return_the_original_command_when_the_action_not_contains_suggestion(
        mocker):
    mocker.patch.object(ClaiClient,
                        'send',
                        return_value=BASIC_ACTION,
                        autospec=True)

    command_to_execute, _ = process_command_from_user(
        ANY_ID, ANY_USER, BASIC_ACTION.origin_command)

    assert command_to_execute == BASIC_ACTION.origin_command
Exemple #7
0
def test_should_return_the_suggested_command_when_the_action_execute_true(
        mocker):
    mocker.patch.object(ClaiClient,
                        'send',
                        return_value=EXECUTABLE_ACTION,
                        autospec=True)

    command_to_execute, _ = process_command_from_user(
        ANY_ID, ANY_USER, EXECUTABLE_ACTION.origin_command)

    assert command_to_execute == EXECUTABLE_ACTION.suggested_command
Exemple #8
0
def test_should_return_the_original_command_when_the_user_press_no(mocker):
    mock_input_console(mocker, 'n')
    mocker.patch.object(ClaiClient,
                        'send',
                        return_value=SUGGESTED_ACTION,
                        autospec=True)

    command_to_execute, _ = process_command_from_user(
        ANY_ID, ANY_USER, SUGGESTED_ACTION.origin_command)

    assert command_to_execute == SUGGESTED_ACTION.origin_command
Exemple #9
0
def test_should_return_the_original_command_when_the_command_is_the_same(
        mocker):
    mocker.patch.object(ClaiClient,
                        'send',
                        return_value=ANY_NO_ACTION,
                        autospec=True)

    command_to_execute, _ = process_command_from_user(
        ANY_ID, ANY_USER, ANY_NO_ACTION.origin_command)

    assert command_to_execute == ANY_NO_ACTION.origin_command