summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2016-05-10 00:06:21 -0500
committerMichael Merickel <michael@merickel.org>2016-05-10 00:06:21 -0500
commite045cfa4e1cae401273430ef0d49cd706f0e65b4 (patch)
treebfcd9dee53dd66df2cb37b71c4cb50d263373c8d
parent7b0a89a9eae779c1cddb765e1831bf8b4ab6e165 (diff)
downloadpyramid-e045cfa4e1cae401273430ef0d49cd706f0e65b4.tar.gz
pyramid-e045cfa4e1cae401273430ef0d49cd706f0e65b4.tar.bz2
pyramid-e045cfa4e1cae401273430ef0d49cd706f0e65b4.zip
ensure invoke_exception_view always returns a response
-rw-r--r--pyramid/tests/test_view.py25
-rw-r--r--pyramid/view.py8
2 files changed, 31 insertions, 2 deletions
diff --git a/pyramid/tests/test_view.py b/pyramid/tests/test_view.py
index 2be47e318..2de44d579 100644
--- a/pyramid/tests/test_view.py
+++ b/pyramid/tests/test_view.py
@@ -805,6 +805,31 @@ class TestViewMethodsMixin(unittest.TestCase):
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']
diff --git a/pyramid/view.py b/pyramid/view.py
index 62ac5310e..88c6397af 100644
--- a/pyramid/view.py
+++ b/pyramid/view.py
@@ -21,6 +21,7 @@ from pyramid.exceptions import PredicateMismatch
from pyramid.httpexceptions import (
HTTPFound,
+ HTTPNotFound,
default_exceptionresponse_view,
)
@@ -589,8 +590,9 @@ class ViewMethodsMixin(object):
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 @@ class ViewMethodsMixin(object):
secure=secure,
request_iface=request_iface.combined,
)
+ if response is None:
+ raise HTTPNotFound
return response