summaryrefslogtreecommitdiff
path: root/repoze/bfg/tests/test_configuration.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2010-08-08 07:25:28 +0000
committerChris McDonough <chrism@agendaless.com>2010-08-08 07:25:28 +0000
commitd96ff9144f98bb44254f77f56e55967c46b09774 (patch)
tree7cabc160ce28460ebffd70a5e419f1c74178bd96 /repoze/bfg/tests/test_configuration.py
parent9192964c9ccc4b0c1c2f1948af1b62012a11ef7c (diff)
downloadpyramid-d96ff9144f98bb44254f77f56e55967c46b09774.tar.gz
pyramid-d96ff9144f98bb44254f77f56e55967c46b09774.tar.bz2
pyramid-d96ff9144f98bb44254f77f56e55967c46b09774.zip
- New public interface: ``repoze.bfg.exceptions.IExceptionResponse``.
This interface is provided by all internal exception classes (such as ``repoze.bfg.exceptions.NotFound`` and ``repoze.bfg.exceptions.Forbidden``), instances of which are both exception objects and can behave as WSGI response objects. This interface is made public so that exception classes which are also valid WSGI response factories can be configured to implement them or exception instances which are also or response instances can be configured to provide them. - New API class: ``repoze.bfg.view.AppendSlashNotFoundViewFactory`` (undoes previous custom_notfound_view on request passsed to append_slash_notfound_view). - Previously, two default view functions were registered at Configurator setup (one for ``repoze.bfg.exceptions.NotFound`` named ``default_notfound_view`` and one for ``repoze.bfg.exceptions.Forbidden`` named ``default_forbidden_view``) to render internal exception responses. Those default view functions have been removed, replaced with a generic default view function which is registered at Configurator setup for the ``repoze.bfg.interfaces.IExceptionResponse`` interface that simply returns the exception instance; the ``NotFound` and ``Forbidden`` classes are now still exception factories but they are also response factories which generate instances that implement the new ``repoze.bfg.interfaces.IExceptionResponse`` interface.
Diffstat (limited to 'repoze/bfg/tests/test_configuration.py')
-rw-r--r--repoze/bfg/tests/test_configuration.py57
1 files changed, 48 insertions, 9 deletions
diff --git a/repoze/bfg/tests/test_configuration.py b/repoze/bfg/tests/test_configuration.py
index 2f001ba8d..1eae66094 100644
--- a/repoze/bfg/tests/test_configuration.py
+++ b/repoze/bfg/tests/test_configuration.py
@@ -194,11 +194,9 @@ class ConfiguratorTests(unittest.TestCase):
self.assertEqual(reg.notify(1), None)
self.assertEqual(reg.events, (1,))
- def test_setup_registry_registers_default_exception_views(self):
- from repoze.bfg.exceptions import NotFound
- from repoze.bfg.exceptions import Forbidden
- from repoze.bfg.view import default_notfound_view
- from repoze.bfg.view import default_forbidden_view
+ def test_setup_registry_registers_default_exceptionresponse_view(self):
+ from repoze.bfg.interfaces import IExceptionResponse
+ from repoze.bfg.view import default_exceptionresponse_view
class DummyRegistry(object):
def registerUtility(self, *arg, **kw):
pass
@@ -207,10 +205,25 @@ class ConfiguratorTests(unittest.TestCase):
views = []
config.add_view = lambda *arg, **kw: views.append((arg, kw))
config.setup_registry()
- self.assertEqual(views[0], ((default_notfound_view,),
- {'context':NotFound}))
- self.assertEqual(views[1], ((default_forbidden_view,),
- {'context':Forbidden}))
+ self.assertEqual(views[0], ((default_exceptionresponse_view,),
+ {'context':IExceptionResponse}))
+
+ def test_setup_registry_explicit_notfound_trumps_iexceptionresponse(self):
+ from zope.interface import implementedBy
+ from repoze.bfg.interfaces import IRequest
+ from repoze.bfg.exceptions import NotFound
+ from repoze.bfg.registry import Registry
+ reg = Registry()
+ config = self._makeOne(reg)
+ config.setup_registry() # registers IExceptionResponse default view
+ def myview(context, request):
+ return 'OK'
+ config.add_view(myview, context=NotFound)
+ request = self._makeRequest(config)
+ view = self._getViewCallable(config, ctx_iface=implementedBy(NotFound),
+ request_iface=IRequest)
+ result = view(None, request)
+ self.assertEqual(result, 'OK')
def test_setup_registry_custom_settings(self):
from repoze.bfg.registry import Registry
@@ -3702,6 +3715,32 @@ class TestDottedNameResolver(unittest.TestCase):
self.assertEqual(e.args[0],
"The dotted name 'cant.be.found' cannot be imported")
+class Test_isexception(unittest.TestCase):
+ def _callFUT(self, ob):
+ from repoze.bfg.configuration import isexception
+ return isexception(ob)
+
+ def test_is_exception_instance(self):
+ class E(Exception):
+ pass
+ e = E()
+ self.assertEqual(self._callFUT(e), True)
+
+ def test_is_exception_class(self):
+ class E(Exception):
+ pass
+ self.assertEqual(self._callFUT(E), True)
+
+ def test_is_IException(self):
+ from repoze.bfg.interfaces import IException
+ self.assertEqual(self._callFUT(IException), True)
+
+ def test_is_IException_subinterface(self):
+ from repoze.bfg.interfaces import IException
+ class ISubException(IException):
+ pass
+ self.assertEqual(self._callFUT(ISubException), True)
+
class DummyRequest:
subpath = ()
def __init__(self):