Permalink
Browse files

set custom request methods when doing a pview lookup

  • Loading branch information...
1 parent 9221e80 commit 97f366094b3e31f43d6fe63bd16c86542b7e90e3 @mmerickel mmerickel committed Sep 28, 2013
Showing with 49 additions and 0 deletions.
  1. +10 −0 CHANGES.txt
  2. +6 −0 pyramid/scripts/pviews.py
  3. +33 −0 pyramid/tests/test_scripts/test_pviews.py
View
@@ -6,6 +6,16 @@ Documentation
- Added a "Quick Tutorial" to go with the Quick Tour
+Bug Fixes
+---------
+
+- The ``pviews`` script did not work when a url required custom request
+ methods in order to perform traversal. Custom methods and descriptors added
+ via ``pyramid.config.Configurator.add_request_method`` will now be present,
+ allowing traversal to continue.
+ See https://github.com/Pylons/pyramid/issues/1104
+
+
1.5a2 (2013-09-22)
==================
@@ -63,6 +63,7 @@ def _find_view(self, url, registry):
from pyramid.interfaces import IRequest
from pyramid.interfaces import IRootFactory
from pyramid.interfaces import IRouteRequest
+ from pyramid.interfaces import IRequestExtensions
from pyramid.interfaces import IRequestFactory
from pyramid.interfaces import IRoutesMapper
from pyramid.interfaces import IView
@@ -121,6 +122,11 @@ def __init__(self, infos, context_iface, root_factory, request):
'PATH_INFO':url,
}
request = request_factory(environ)
+
+ extensions = registry.queryUtility(IRequestExtensions)
+ if extensions is not None:
+ request._set_extensions(extensions)
+
context = None
routes_multiview = None
attrs = request.__dict__
@@ -465,6 +465,39 @@ def predicate(): pass
' pyramid.tests.test_scripts.dummy.view.call')
self.assertEqual(L[9], ' view predicates (predicate = x)')
+ def test_find_views_with_request_extensions(self):
+ from zope.interface import providedBy
+ from pyramid.interfaces import IRequest
+ from pyramid.interfaces import IRequestExtensions
+ from pyramid.interfaces import IRootFactory
+ from pyramid.interfaces import IViewClassifier
+ from pyramid.interfaces import IView
+ from pyramid.registry import Registry
+
+ class DummyExtensions(object):
+ descriptors = {}
+ methods = {'foo': lambda r: 'bar'}
+
+ registry = Registry()
+ registry.registerUtility(DummyExtensions(), IRequestExtensions)
+
+ called = []
+ def factory(request):
+ called.append(request.foo())
+
+ def view1(): pass
+ request = dummy.DummyRequest({'PATH_INFO':'/a'})
+ root_iface = providedBy(None)
+ registry.registerUtility(factory, IRootFactory)
+ registry.registerAdapter(view1,
+ (IViewClassifier, IRequest, root_iface),
+ IView, name='a')
+ self._register_mapper(registry, [])
+ command = self._makeOne(registry=registry)
+ result = command._find_view('/a', registry)
+ self.assertEqual(result, view1)
+ self.assertEqual(called, ['bar'])
+
class Test_main(unittest.TestCase):
def _callFUT(self, argv):
from pyramid.scripts.pviews import main

0 comments on commit 97f3660

Please sign in to comment.