Michael Merickel
2016-05-10 eb93e51d52ce3cc7e965d20b5247f4ef74e51cd9
ensure invoke_exception_view always returns a response
2 files modified
33 ■■■■■ changed files
pyramid/tests/test_view.py 25 ●●●●● patch | view | raw | blame | history
pyramid/view.py 8 ●●●● patch | view | raw | blame | history
pyramid/tests/test_view.py
@@ -805,6 +805,31 @@
        else: # pragma: no cover
            self.fail()
    def test_it_raises_if_not_found(self):
        from pyramid.httpexceptions import HTTPNotFound
        request = self._makeOne()
        dummy_exc = RuntimeError()
        try:
            raise dummy_exc
        except RuntimeError:
            self.assertRaises(HTTPNotFound, request.invoke_exception_view)
        else: # pragma: no cover
            self.fail()
    def test_it_raises_predicate_mismatch(self):
        from pyramid.exceptions import PredicateMismatch
        def exc_view(exc, request): pass
        self.config.add_view(exc_view, context=Exception, request_method='POST')
        request = self._makeOne()
        request.method = 'GET'
        dummy_exc = RuntimeError()
        try:
            raise dummy_exc
        except RuntimeError:
            self.assertRaises(PredicateMismatch, request.invoke_exception_view)
        else: # pragma: no cover
            self.fail()
class ExceptionResponse(Exception):
    status = '404 Not Found'
    app_iter = ['Not Found']
pyramid/view.py
@@ -21,6 +21,7 @@
from pyramid.httpexceptions import (
    HTTPFound,
    HTTPNotFound,
    default_exceptionresponse_view,
    )
@@ -589,8 +590,9 @@
        object that this method is attached to as the ``request``, and
        ``True`` for ``secure``.
        This method returns a :term:`response` object or ``None`` if no
        matching exception view can be found."""
        This method returns a :term:`response` object or raises
        :class:`pyramid.httpexceptions.HTTPNotFound` if a matching view cannot
        be found."""
        if request is None:
            request = self
@@ -623,4 +625,6 @@
                secure=secure,
                request_iface=request_iface.combined,
                )
            if response is None:
                raise HTTPNotFound
            return response