Ejemplo n.º 1
0
def test_middleware__no_exc(app):
    @asyncio.coroutine
    def handler(request):
        return 'response'

    mw = yield from exc_handlers_middleware(app, handler)
    response = yield from mw('request')

    assert response == 'response'
Ejemplo n.º 2
0
def test_middleware__http_exc(app):
    @asyncio.coroutine
    def handler(request):
        raise HTTPMethodNotAllowed(method='GET', allowed_methods=[])

    mw = yield from exc_handlers_middleware(app, handler)
    response = yield from mw('request')

    assert isinstance(response, HTTPMethodNotAllowed)
Ejemplo n.º 3
0
def test_middleware__not_found(app):
    @asyncio.coroutine
    def handler(request):
        raise RuntimeError()

    mw = yield from exc_handlers_middleware(app, handler)

    with pytest.raises(RuntimeError):
        yield from mw('request')
Ejemplo n.º 4
0
def test_middleware__exc_eq(app):
    @asyncio.coroutine
    def handler(request):
        raise RuntimeError()

    @asyncio.coroutine
    def exc_handler(request, exc):
        return 'response'

    app['exc_handlers'] = {RuntimeError: exc_handler}

    mw = yield from exc_handlers_middleware(app, handler)
    response = yield from mw('request')

    assert response == 'response'
Ejemplo n.º 5
0
def test_middleware__exc_inheritance(app):
    class Exc(RuntimeError):
        pass

    @asyncio.coroutine
    def handler(request):
        raise Exc()

    @asyncio.coroutine
    def exc_handler(request, exc):
        return 'response'

    app['exc_handlers'] = {RuntimeError: exc_handler}

    mw = yield from exc_handlers_middleware(app, handler)
    response = yield from mw('request')

    assert response == 'response'
Ejemplo n.º 6
0
def test_middleware__twice_exc(app):
    @asyncio.coroutine
    def handler(request):
        raise RuntimeError()

    @asyncio.coroutine
    def exc_handler_1(request, exc):
        raise ValueError()

    @asyncio.coroutine
    def exc_handler_2(request, exc):
        return 'response'

    app['exc_handlers'] = {
        RuntimeError: exc_handler_1,
        ValueError: exc_handler_2,
    }

    mw = yield from exc_handlers_middleware(app, handler)

    with pytest.raises(ValueError):
        yield from mw('request')