Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    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)