def test_multi_response():
    host = "localhost"
    response1 = Response(host, "ls -al")
    response2 = Response(host, "ls -al")
    multi_response = MultiResponse()
    assert multi_response.host == ""
    multi_response.extend([response1, response2])
    assert len(multi_response) == 2
    assert multi_response.failed is True
    assert (
        repr(multi_response) ==
        "[Response(host='localhost',channel_input='ls -al',textfsm_platform='',genie_platform='',failed_when_contains=None), Response(host='localhost',channel_input='ls -al',textfsm_platform='',genie_platform='',failed_when_contains=None)]"
    )
    assert str(multi_response
               ) == "MultiResponse <Success: False; Response Elements: 2>"
    with pytest.raises(ScrapliCommandFailure):
        multi_response.raise_for_status()
    multi_response[0].failed = False
    multi_response[1].failed = False
    assert multi_response.failed is False
    assert multi_response.raise_for_status() is None
    assert multi_response.host == host
    assert (
        repr(multi_response) ==
        "[Response(host='localhost',channel_input='ls -al',textfsm_platform='',genie_platform='',failed_when_contains=None), Response(host='localhost',channel_input='ls -al',textfsm_platform='',genie_platform='',failed_when_contains=None)]"
    )
    assert str(multi_response
               ) == "MultiResponse <Success: True; Response Elements: 2>"
    assert multi_response.result == "ls -al\nls -al\n"
Exemple #2
0
def test_multi_response():
    response1 = Response("localhost", "ls -al")
    response2 = Response("localhost", "ls -al")
    multi_response = MultiResponse([response1, response2])
    assert len(multi_response) == 2
    assert multi_response.failed is True
    assert repr(multi_response) == "MultiResponse <Success: False; Response Elements: 2>"
    assert str(multi_response) == "MultiResponse <Success: False; Response Elements: 2>"
    with pytest.raises(ScrapliCommandFailure):
        multi_response.raise_for_status()
    multi_response[0].failed = False
    multi_response[1].failed = False
    assert multi_response.failed is False
    assert multi_response.raise_for_status() is None
    assert repr(multi_response) == "MultiResponse <Success: True; Response Elements: 2>"
    assert str(multi_response) == "MultiResponse <Success: True; Response Elements: 2>"