示例#1
0
def test_send_config_commands_correct_commands(first_router_from_devices_yaml, capsys):
    r1 = task_22_2c.CiscoTelnet(**first_router_from_devices_yaml)
    check_attr_or_method(r1, method="send_config_commands")

    correct_commands = ["interface loop55", "ip address 5.5.5.5 255.255.255.255"]
    return_value = r1.send_config_commands(correct_commands)
    assert (
        correct_commands[0] in return_value and correct_commands[1] in return_value
    ), "send_config_commands method returns wrong value"
示例#2
0
def test_send_config_commands_correct_commands(first_router_from_devices_yaml, capsys):
    r1 = task_22_2c.CiscoTelnet(**first_router_from_devices_yaml)
    check_attr_or_method(r1, method="send_config_commands")

    # команды без ошибок
    correct_commands = ["interface loop55", "ip address 5.5.5.5 255.255.255.255"]
    return_value = r1.send_config_commands(correct_commands)
    assert (
        correct_commands[0] in return_value and correct_commands[1] in return_value
    ), "Метод send_config_commands возвращает неправильное значение"
示例#3
0
def test_send_config_commands_wrong_commands(first_router_from_devices_yaml,
                                             capsys, error, command):
    r1 = task_22_2c.CiscoTelnet(**first_router_from_devices_yaml)

    return_value = r1.send_config_commands(command, strict=False)
    stdout, err = capsys.readouterr()
    assert error in stdout, "send_config_commands method does not print error message"

    with pytest.raises(ValueError) as excinfo:
        return_value = r1.send_config_commands(command, strict=True)
    assert error in str(
        excinfo
    ), "send_config_commands method should raise exception when strict=True"
示例#4
0
def test_send_config_commands_wrong_commands(first_router_from_devices_yaml,
                                             capsys, error, command):
    r1 = task_22_2c.CiscoTelnet(**first_router_from_devices_yaml)

    # команда с ошибкой strict=False
    return_value = r1.send_config_commands(command, strict=False)
    out, err = capsys.readouterr()
    assert error in out, "Метод send_config_commands не выводит сообщение об ошибке"

    # команда с ошибкой strict=True
    with pytest.raises(ValueError) as excinfo:
        return_value = r1.send_config_commands(command, strict=True)
    assert error in str(
        excinfo
    ), "Метод send_config_commands должен генерировать исключение, когда strict=True"