Esempio n. 1
0
def test_request_response():
    s = MockSock([SERVER_HELLO + DELIMITER_10])
    with Session(s) as session:
        response_f = session.send_rpc(TEST_RPC)

        s.recvs.put(
            frame_message_11(TEST_NOTIFICATION) +
            frame_message_11(TEST_RPC_REPLY) +
            frame_message_11(TEST_NOTIFICATION))

        assert response_f.result()[0] == TEST_RPC_REPLY
        assert session.notifications.get(timeout=1)[0] == TEST_NOTIFICATION
        assert session.notifications.get(timeout=1)[0] == TEST_NOTIFICATION
Esempio n. 2
0
def test_request_error_response():
    s = MockSock([SERVER_HELLO + DELIMITER_10])
    with Session(s) as session:
        response_f = session.send_rpc(TEST_RPC)
        response_f2 = session.send_rpc(TEST_RPC)

        s.recvs.put(frame_message_11(RPC_ERROR_WITHOUT_MSG))

        with pytest.raises(RpcError):
            response_f.result()

        # And then ensure a regular message can still get through
        s.recvs.put(frame_message_11(TEST_RPC_REPLY))
        assert response_f2.result()[0] == TEST_RPC_REPLY
Esempio n. 3
0
def test_encoding_11():
    s = MockSock(
        [SERVER_HELLO + DELIMITER_10,
         frame_message_11(TEST_RPC_REPLY)])
    with Session(s) as session:
        assert s.sent == [DEFAULT_HELLO + DELIMITER_10]
        s.sent = []
        assert not s.closed

        assert session.server_hello == SERVER_HELLO
        assert session.session_id == 4
        assert session.server_capabilities == [
            "urn:ietf:params:netconf:base:1.1",
            "http://example.com/foo",
        ]
        assert session.client_capabilities == [
            "urn:ietf:params:netconf:base:1.1"
        ]
        assert session.mode == "1.1"

        session.send_msg(TEST_RPC)
        assert s.sent == [b"\n#102\n" + TEST_RPC + b"\n##\n"]

        assert session.unknown_recvq.get(timeout=1)[0] == TEST_RPC_REPLY

    assert s.closed