Exemplo n.º 1
0
    def test_on_stream_terminated_invokes_access_denied_on_connection_error_and_closed(
            self):
        """_on_stream_terminated invokes `ON_CONNECTION_ERROR` with \
        `ProbableAccessDeniedError` and `ON_CONNECTION_CLOSED` callbacks"""
        with mock.patch.object(self.connection.callbacks, 'process'):

            self.connection._adapter_disconnect_stream = mock.Mock()

            self.connection._set_connection_state(
                self.connection.CONNECTION_TUNE)
            self.connection._opened = False

            original_exc = exceptions.StreamLostError(1, 'error text')
            self.connection._on_stream_terminated(original_exc)

            self.assertEqual(self.connection.callbacks.process.call_count, 1)

            self.connection.callbacks.process.assert_any_call(
                0, self.connection.ON_CONNECTION_ERROR, self.connection,
                self.connection, mock.ANY)

            conn_exc = self.connection.callbacks.process.call_args_list[0][0][
                4]
            self.assertIs(type(conn_exc), exceptions.ProbableAccessDeniedError)
            self.assertSequenceEqual(conn_exc.args, [repr(original_exc)])
Exemplo n.º 2
0
    def test_blocked_connection_on_stream_terminated_removes_timer(
            self, adapter_disconnect_mock, connect_mock, add_timeout_mock,
            remove_timeout_mock):

        with mock.patch.object(ConstructibleConnection,
                               '_adapter_connect_stream'):
            conn = ConstructibleConnection(
                parameters=connection.ConnectionParameters(
                    blocked_connection_timeout=60),
                on_open_error_callback=lambda *args: None)

        conn._on_connection_blocked(
            conn, mock.Mock(name='frame.Method(Connection.Blocked)'))

        self.assertIsNotNone(conn._blocked_conn_timer)

        timer = conn._blocked_conn_timer

        conn._on_stream_terminated(exceptions.StreamLostError())

        # Check
        conn._adapter_remove_timeout.assert_called_once_with(timer)
        self.assertIsNone(conn._blocked_conn_timer)