From 7c96246eb6e14f5cd9414ddd61de089fe1f073d1 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Sun, 20 Oct 2013 21:13:49 -0500 Subject: notfound and forbidden decorators were ignoring view_defaults This could be fixed in other ways but the basic problem is that because config.add_notfound_view and config.add_forbidden_view have actual signatures instead of *args, **kwargs, the arguments are squashing the view_defaults which are applied later on the call to config.add_view. Basically, by the time the args get to config.add_view, they look explicit when they are not. fix #1173 --- pyramid/config/views.py | 2 ++ pyramid/tests/test_config/test_views.py | 60 +++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/pyramid/config/views.py b/pyramid/config/views.py index 233bbac12..69f68e422 100644 --- a/pyramid/config/views.py +++ b/pyramid/config/views.py @@ -1550,6 +1550,7 @@ class ViewsConfiguratorMixin(object): return deriver(view) + @viewdefaults @action_method def add_forbidden_view( self, @@ -1629,6 +1630,7 @@ class ViewsConfiguratorMixin(object): set_forbidden_view = add_forbidden_view # deprecated sorta-bw-compat alias + @viewdefaults @action_method def add_notfound_view( self, diff --git a/pyramid/tests/test_config/test_views.py b/pyramid/tests/test_config/test_views.py index 4924fff57..051961d25 100644 --- a/pyramid/tests/test_config/test_views.py +++ b/pyramid/tests/test_config/test_views.py @@ -1815,6 +1815,36 @@ class TestViewsConfigurationMixin(unittest.TestCase): self.assertRaises(ConfigurationError, config.add_forbidden_view, http_cache='foo') + def test_add_forbidden_view_with_view_defaults(self): + from pyramid.interfaces import IRequest + from pyramid.renderers import null_renderer + from pyramid.exceptions import PredicateMismatch + from pyramid.httpexceptions import HTTPForbidden + from zope.interface import directlyProvides + from zope.interface import implementedBy + class view(object): + __view_defaults__ = { + 'containment':'pyramid.tests.test_config.IDummy' + } + def __init__(self, request): + pass + def __call__(self): + return 'OK' + config = self._makeOne(autocommit=True) + config.add_forbidden_view( + view=view, + renderer=null_renderer) + wrapper = self._getViewCallable( + config, ctx_iface=implementedBy(HTTPForbidden), + request_iface=IRequest) + context = DummyContext() + directlyProvides(context, IDummy) + request = self._makeRequest(config) + self.assertEqual(wrapper(context, request), 'OK') + context = DummyContext() + request = self._makeRequest(config) + self.assertRaises(PredicateMismatch, wrapper, context, request) + def test_add_notfound_view(self): from pyramid.renderers import null_renderer from zope.interface import implementedBy @@ -1882,6 +1912,36 @@ class TestViewsConfigurationMixin(unittest.TestCase): result = view(None, request) self.assertEqual(result.location, '/scriptname/foo/?a=1&b=2') + def test_add_notfound_view_with_view_defaults(self): + from pyramid.interfaces import IRequest + from pyramid.renderers import null_renderer + from pyramid.exceptions import PredicateMismatch + from pyramid.httpexceptions import HTTPNotFound + from zope.interface import directlyProvides + from zope.interface import implementedBy + class view(object): + __view_defaults__ = { + 'containment':'pyramid.tests.test_config.IDummy' + } + def __init__(self, request): + pass + def __call__(self): + return 'OK' + config = self._makeOne(autocommit=True) + config.add_notfound_view( + view=view, + renderer=null_renderer) + wrapper = self._getViewCallable( + config, ctx_iface=implementedBy(HTTPNotFound), + request_iface=IRequest) + context = DummyContext() + directlyProvides(context, IDummy) + request = self._makeRequest(config) + self.assertEqual(wrapper(context, request), 'OK') + context = DummyContext() + request = self._makeRequest(config) + self.assertRaises(PredicateMismatch, wrapper, context, request) + # Since Python 3 has to be all cool and fancy and different... def _assertBody(self, response, value): from pyramid.compat import text_type -- cgit v1.2.3 From 64223904fd6330eb9e528311799cc4dd10e9daf1 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Tue, 22 Oct 2013 22:11:13 -0500 Subject: update changelog --- CHANGES.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 203db1a44..895dc572f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -57,6 +57,10 @@ Bug Fixes to decode with UTF-8 first, and will fallback to Latin-1. See https://github.com/Pylons/pyramid/pull/1170 +- The ``@view_defaults`` now apply to notfound and forbidden views + that are defined as methods of a decorated class. + See https://github.com/Pylons/pyramid/issues/1173 + Documentation ------------- -- cgit v1.2.3