def test_parse_error_messages(response_data): response_output = response_data[0] expected_errors = response_data[1] channel_input = "<something/>" xml_input = etree.fromstring(text=channel_input) response = NetconfResponse( host="localhost", channel_input=channel_input, xml_input=xml_input, netconf_version=NetconfVersion.VERSION_1_1, ) response.record_response(result=response_output.encode()) assert response.error_messages == expected_errors
def test_failed_when_contains_default_values(response_data): response_output = response_data[0] response_success = response_data[1] channel_input = "<something/>" xml_input = etree.fromstring(text=channel_input) response = NetconfResponse( host="localhost", channel_input=channel_input, xml_input=xml_input, netconf_version=NetconfVersion.VERSION_1_0, ) response.record_response(result=response_output) assert response.failed is not response_success
def test_record_response(response_setup): netconf_version = response_setup[0] strip_namespaces = response_setup[1] channel_input = response_setup[2] result = response_setup[3] final_result = response_setup[4] xml_elements = response_setup[5] xml_input = etree.fromstring(text=channel_input) response_end_time = str(datetime.now())[:-7] response = NetconfResponse( host="localhost", channel_input=channel_input, xml_input=xml_input, netconf_version=netconf_version, failed_when_contains=[b"<rpc-error>"], strip_namespaces=strip_namespaces, ) response.record_response(result=result.encode()) assert str(response.finish_time)[:-7] == response_end_time assert response.result == final_result assert response.failed is False assert list(response.get_xml_elements().keys()) == xml_elements
def test_raise_for_status(response_data): response_output = response_data[0] expected_errors = response_data[1] channel_input = "<something/>" xml_input = etree.fromstring(text=channel_input) response = NetconfResponse( host="localhost", channel_input=channel_input, xml_input=xml_input, netconf_version=NetconfVersion.VERSION_1_1, ) response.record_response(result=response_output.encode()) if not expected_errors: assert not response.error_messages return with pytest.raises(ScrapliCommandFailure) as exc: response.raise_for_status() assert str(exc.value ) == f"operation failed, reported rpc errors: {expected_errors}"