コード例 #1
0
def test_response_init(response_setup):
    netconf_version = response_setup[0]
    channel_input = response_setup[1]
    xml_input = etree.fromstring(text=channel_input)
    response = NetconfResponse(
        host="localhost",
        channel_input=channel_input,
        xml_input=xml_input,
        netconf_version=netconf_version,
        failed_when_contains=[b"<rpc-error>"],
    )
    response_start_time = str(datetime.now())[:-7]
    assert response.host == "localhost"
    assert response.channel_input == "<something/>"
    assert response.xml_input == xml_input
    assert str(response.start_time)[:-7] == response_start_time
    assert response.failed is True
    assert bool(response) is True
    assert (
        repr(response) ==
        "NetconfResponse(host='localhost',channel_input='<something/>',textfsm_platform='',genie_platform='',failed_when_contains=[b'<rpc-error>'])"
    )
    assert str(response) == "NetconfResponse <Success: False>"
    assert response.failed_when_contains == [b"<rpc-error>"]
    with pytest.raises(ScrapliCommandFailure):
        response.raise_for_status()
コード例 #2
0
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}"