示例#1
0
def test_function_return_value_continue_no(first_router_from_devices_yaml,
                                           capsys, monkeypatch, c_map,
                                           commands_1, commands_2):
    # проверяем сообщения об ошибках, при условии,
    # что после первой команды с ошибкой, была сделана остановка
    monkeypatch.setattr("builtins.input", lambda x=None: "n")
    commands = commands_1 + commands_2

    return_value = task_18_2c.send_config_commands(
        first_router_from_devices_yaml, commands, log=False)

    assert return_value != None, "Функция ничего не возвращает"
    assert type(return_value) == tuple, "Функция должна возвращать кортеж"
    assert len(return_value) == 2 and all(
        type(item) == dict for item in
        return_value), "Функция должна возвращать кортеж с двумя словарями"
    return_good, return_bad = return_value
    if c_map[0] == "bad":
        commands_with_errors, correct_commands = commands_1, commands_2
        assert (list(return_good) == []
                and sorted(return_bad) == commands_with_errors[:1]
                ), "Функция возвращает неправильное значение"
    else:
        commands_with_errors, correct_commands = commands_2, commands_1
        assert (list(return_good) == correct_commands
                and list(return_bad) == commands_with_errors[:1]
                ), "Функция возвращает неправильное значение"
示例#2
0
def test_function_return_value_continue_no(
    first_router_from_devices_yaml, capsys, monkeypatch, c_map, commands_1, commands_2
):
    monkeypatch.setattr("builtins.input", lambda x=None: "n")
    commands = commands_1 + commands_2

    return_value = task_18_2c.send_config_commands(
        first_router_from_devices_yaml, commands, log=False
    )

    assert return_value != None, "The function returns None"
    assert type(return_value) == tuple, "The function must return a tuple"
    assert 2 == len(return_value) and all(
        type(item) == dict for item in return_value
    ), "The function must return a tuple with two dicts"
    return_good, return_bad = return_value
    if c_map[0] == "bad":
        commands_with_errors, correct_commands = commands_1, commands_2
        assert [] == list(return_good) and commands_with_errors[:1] == sorted(
            return_bad
        ), "Function returns wrong value"
    else:
        commands_with_errors, correct_commands = commands_2, commands_1
        assert correct_commands == list(return_good) and commands_with_errors[
            :1
        ] == list(return_bad), "Function returns wrong value"
示例#3
0
def test_function_stdout(error, command, first_router_from_devices_yaml,
                         capsys, monkeypatch):
    monkeypatch.setattr("builtins.input", lambda x=None: "y")

    return_value = task_18_2c.send_config_commands(
        first_router_from_devices_yaml, [command], log=False)

    out, err = capsys.readouterr()
    ip = first_router_from_devices_yaml["host"]
    assert error in out, "The error message does not contain the error itself"
    assert command in out, "There is no command in the error message"
    assert ip in out, "The error message does not contain the IP address of the device"
示例#4
0
def test_function_return_value_continue_yes(first_router_from_devices_yaml,
                                            capsys, monkeypatch):
    monkeypatch.setattr("builtins.input", lambda x=None: "y")

    return_value = task_18_2c.send_config_commands(
        first_router_from_devices_yaml, test_commands, log=False)

    assert return_value != None, "The function returns None"
    assert type(return_value) == tuple, "The function must return a tuple"
    assert len(return_value) == 2 and all(
        type(item) == dict for item in
        return_value), "The function must return a tuple with two dicts"
    correct_good, correct_bad = correct_return_value
    return_good, return_bad = return_value
    assert (return_good.keys() == correct_good.keys() and return_bad.keys()
            == correct_bad.keys()), "Function returns wrong value"
示例#5
0
def test_function_return_value_continue_yes(first_router_from_devices_yaml,
                                            capsys, monkeypatch):
    # проверяем возвращаемое значение, при условии,
    # что было выбрано продолжать выполнять вcе команды
    monkeypatch.setattr("builtins.input", lambda x=None: "y")

    return_value = task_18_2c.send_config_commands(
        first_router_from_devices_yaml, test_commands, log=False)

    assert return_value != None, "Функция ничего не возвращает"
    assert type(return_value) == tuple, "Функция должна возвращать кортеж"
    assert len(return_value) == 2 and all(
        type(item) == dict for item in
        return_value), "Функция должна возвращать кортеж с двумя словарями"
    correct_good, correct_bad = correct_return_value
    return_good, return_bad = return_value
    assert (return_good.keys() == correct_good.keys() and return_bad.keys()
            == correct_bad.keys()), "Функция возвращает неправильное значение"
示例#6
0
def test_function_stdout(error, command, first_router_from_devices_yaml,
                         capsys, monkeypatch):
    # проверяем сообщения об ошибках, при условии,
    # что было выбрано продолжать выполнять вcе команды
    monkeypatch.setattr("builtins.input", lambda x=None: "y")

    return_value = task_18_2c.send_config_commands(
        first_router_from_devices_yaml, [command], log=False)

    # Проверяем вывод информации об ошибках в stdout
    # во входящих данных три команды с ошибками
    # при каждой ошибке, должна выводиться информация:
    # ошибка, IP устройства, команда
    # в тесте проверяется наличие этих полей
    out, err = capsys.readouterr()
    ip = first_router_from_devices_yaml["host"]
    assert error in out, "В сообщении об ошибке нет самой ошибки"
    assert command in out, "В сообщении об ошибке нет выполняемой команды"
    assert ip in out, "В сообщении об ошибке нет IP-адреса устройства"