async def test_on_session_failed(self, mocker: MockerFixture,
                                     target: ClientChannel) -> None:
        # Arrange
        session = Session(SessionState.FAILED)
        session.id = SESSION_ID

        spy_transport = mocker.spy(target.transport, 'close_async')
        # Act
        target.on_session(session)

        # Assert
        spy_transport.assert_called_once()
    async def test_on_session_authenticating(self, mocker: MockerFixture,
                                             target: ClientChannel) -> None:
        # Arrange
        session = Session(SessionState.AUTHENTICATING)
        session.id = SESSION_ID

        spy = mocker.spy(target, 'on_session_authenticating')
        # Act
        target.on_session(session)

        # Assert
        spy.assert_called_once_with(session)
    async def test_start_new_session_async(self, mocker: MockerFixture,
                                           target: ClientChannel) -> None:
        # Arrange
        target.state = SessionState.NEW

        spy = mocker.spy(target, SEND_SESSION_METHOD)
        sent_session = Session(SessionState.NEW)

        # Act
        target.start_new_session_async()

        # Assert
        sent_session.id = spy.call_args[0][0].id
        spy.assert_called_once_with(sent_session)
    async def test_send_finishing_session_async(self, mocker: MockerFixture,
                                                target: ClientChannel) -> None:
        # Arrange
        target.state = SessionState.ESTABLISHED
        target.session_id = SESSION_ID

        spy = mocker.spy(target, SEND_SESSION_METHOD)
        sent_session = Session(SessionState.FINISHING)
        sent_session.id = SESSION_ID

        # Act
        target.send_finishing_session_async()

        # Assert
        spy.assert_called_once_with(sent_session)
    async def test_on_session_established(self, mocker: MockerFixture,
                                          target: ClientChannel) -> None:
        # Arrange
        session = Session(SessionState.ESTABLISHED)
        session.id = SESSION_ID
        session.to = TO
        session.from_n = FROM_N

        spy = mocker.spy(target, 'on_session_established')
        # Act
        target.on_session(session)

        # Assert
        spy.assert_called_once_with(session)
        assert target.local_node == str(session.to)
        assert target.remote_node == session.from_n
    async def test_negotiate_session_async(self, mocker: MockerFixture,
                                           target: ClientChannel) -> None:
        # Arrange
        target.state = SessionState.NEGOTIATING

        spy = mocker.spy(target, SEND_SESSION_METHOD)
        sent_session = Session(SessionState.NEGOTIATING,
                               compression=SessionCompression.GZIP,
                               encryption=SessionEncryption.TLS)

        # Act
        target.negotiate_session_async(SessionCompression.GZIP,
                                       SessionEncryption.TLS)

        # Assert
        sent_session.id = spy.call_args[0][0].id
        spy.assert_called_once_with(sent_session)
    async def test_authenticate_session_async(self, mocker: MockerFixture,
                                              target: ClientChannel) -> None:
        # Arrange
        target.state = SessionState.AUTHENTICATING
        target.session_id = SESSION_ID

        spy = mocker.spy(target, SEND_SESSION_METHOD)
        identity = '*****@*****.**'
        instance = 'test'
        authentication = PlainAuthentication('any-pswd')
        sent_session = Session(SessionState.AUTHENTICATING,
                               scheme=authentication.scheme,
                               authentication=authentication)
        sent_session.from_n = f'{identity}/{instance}'
        sent_session.id = SESSION_ID

        # Act
        target.authenticate_session_async(identity, authentication, instance)

        # Assert
        spy.assert_called_once_with(sent_session)