def test_function_return_value_from_all_devices( three_routers_from_devices_yaml, r1_r2_r3_test_connection, tmpdir): """ Проверка работы функции """ routers_ip = [router["host"] for router in three_routers_from_devices_yaml] commands = ["sh ip int br", "show ip int bri | exc unass", "show int desc"] out1, out2, out3 = [ r.send_command(command) for r, command in zip(r1_r2_r3_test_connection, commands) ] dest_filename = tmpdir.mkdir("test_tasks").join("task_19_3.txt") return_value = task_19_3.send_command_to_devices( three_routers_from_devices_yaml, dict(zip(routers_ip, commands)), dest_filename, limit=3, ) assert None == return_value, "Функция должна возвращать None" dest_file_content = dest_filename.read().strip() # проверяем, что вывод с каждого устройства есть в файле assert (out1.strip() in dest_file_content ), "В итоговом файле нет вывода с первого устройства" assert (out2.strip() in dest_file_content ), "В итоговом файле нет вывода со второго устройства" assert (out3.strip() in dest_file_content ), "В итоговом файле нет вывода с третьего устройства"
def test_function_return_value_from_all_devices( three_routers_from_devices_yaml, r1_r2_r3_test_connection, tmpdir ): """ Function check """ routers_ip = [router["host"] for router in three_routers_from_devices_yaml] commands = ["sh ip int br", "show ip int bri | exc unass", "show int desc"] out1, out2, out3 = [ r.send_command(command) for r, command in zip(r1_r2_r3_test_connection, commands) ] dest_filename = tmpdir.mkdir("test_tasks").join("task_19_3.txt") return_value = task_19_3.send_command_to_devices( three_routers_from_devices_yaml, dict(zip(routers_ip, commands)), dest_filename, limit=3, ) assert return_value == None, "The function must return None" dest_file_content = dest_filename.read().strip() assert ( out1.strip() in dest_file_content ), "Output file does not have output from first device" assert ( out2.strip() in dest_file_content ), "Output file does not have output from second device" assert ( out3.strip() in dest_file_content ), "Output file does not have output from third device"
def test_function_return_value_from_single_device( three_routers_from_devices_yaml, r1_r2_r3_test_connection, tmpdir, device, command_dict, ): """ Проверка работы функции """ device_ip = device["host"] command = command_dict[device_ip] ssh = create_ssh_connect(device) correct_output = strip_empty_lines( f"{ssh.find_prompt()}{command}\n{ssh.send_command(command)}\n") ssh.disconnect() dest_filename = tmpdir.mkdir("test_tasks").join("task_19_3.txt") return_value = task_19_3.send_command_to_devices( devices=[device], commands_dict=command_dict, filename=dest_filename, limit=3, ) assert None == return_value, "Функция должна возвращать None" dest_file_content = strip_empty_lines(dest_filename.read().strip()) assert (correct_output == dest_file_content ), f"В итоговом файле нет вывода с {device_ip}"
def test_function_return_value_from_single_device( three_routers_from_devices_yaml, r1_r2_r3_test_connection, tmpdir, device, command_dict, ): """ Function check """ device_ip = device["host"] command = command_dict[device_ip] ssh = create_ssh_connect(device) output = f"{ssh.find_prompt()}{command}\n{ssh.send_command(command)}\n" ssh.disconnect() dest_filename = tmpdir.mkdir("test_tasks").join("task_19_3.txt") return_value = task_19_3.send_command_to_devices( devices=[device], commands_dict=command_dict, filename=dest_filename, limit=3, ) assert return_value == None, "The function must return None" dest_file_content = dest_filename.read().strip() assert strip_empty_lines(output) == strip_empty_lines( dest_file_content ), f"Output file does not have output from {device_ip}"