Beispiel #1
0
    async def test_error_handler_ok(self, mocker):
        app = mocker.Mock()
        handler = CoroutineMock()
        request = mocker.Mock()

        factory = error_handler()
        handle_func = await factory(app, handler)
        await handle_func(request)

        handler.assert_called_once_with(request)
Beispiel #2
0
    async def test_error_custom_error(self, mocker):
        app = mocker.Mock()
        fake_error = 'error'
        handler = CoroutineMock(side_effect=HTTPCustomError(fake_error))
        request = mocker.Mock()
        factory = error_handler()
        handle_func = await factory(app, handler)

        with pytest.raises(HTTPCustomError):
            await handle_func(request)
Beispiel #3
0
    async def test_unhandled_exception_debug_true(self, mocker):
        fake_error_text = 'fake_error_text'
        fake_api_error = mocker.Mock(return_value=mocker.Mock(
            InternalError=mocker.Mock(return_value={})))
        mocked_error = mocker.patch(
            'aiohttp_baseapi.middleware.error_handler.ApiError',
            fake_api_error)

        app = mocker.Mock()
        handler = CoroutineMock(side_effect=Exception(fake_error_text))
        request = mocker.Mock()
        factory = error_handler(is_debug=True)
        handle_func = await factory(app, handler)

        with pytest.raises(HTTPCustomError):
            await handle_func(request)

        mocked_error.return_value.InternalError.assert_called_once_with(
            fake_error_text)
Beispiel #4
0
# -*- coding: utf-8 -*-

from aiohttp.web_middlewares import normalize_path_middleware
from aiohttp_baseapi.middleware.error_handler import error_handler
from aiohttp_baseapi.middleware.params_handler import params_handler

from conf import settings

__all__ = ('middlewares', )

middlewares = list()

middlewares.append(normalize_path_middleware())
middlewares.append(params_handler)
middlewares.append(error_handler(is_debug=settings.DEBUG))