ensure invoke_exception_view always returns a response
| | |
| | | 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'] |
| | |
| | | |
| | | from pyramid.httpexceptions import ( |
| | | HTTPFound, |
| | | HTTPNotFound, |
| | | default_exceptionresponse_view, |
| | | ) |
| | | |
| | |
| | | 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 |
| | |
| | | secure=secure, |
| | | request_iface=request_iface.combined, |
| | | ) |
| | | if response is None: |
| | | raise HTTPNotFound |
| | | return response |