summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2013-09-28 02:56:50 -0500
committerMichael Merickel <michael@merickel.org>2013-09-28 02:56:50 -0500
commit97f366094b3e31f43d6fe63bd16c86542b7e90e3 (patch)
tree28310f2c3d26691514aeb6017019e070982883fd
parent9221e806f945bd746044740f3fc7f05aaa41b656 (diff)
downloadpyramid-97f366094b3e31f43d6fe63bd16c86542b7e90e3.tar.gz
pyramid-97f366094b3e31f43d6fe63bd16c86542b7e90e3.tar.bz2
pyramid-97f366094b3e31f43d6fe63bd16c86542b7e90e3.zip
set custom request methods when doing a pview lookup
-rw-r--r--CHANGES.txt10
-rw-r--r--pyramid/scripts/pviews.py6
-rw-r--r--pyramid/tests/test_scripts/test_pviews.py33
3 files changed, 49 insertions, 0 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 8b2210a99..550dd0a39 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -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)
==================
diff --git a/pyramid/scripts/pviews.py b/pyramid/scripts/pviews.py
index 081c13e9d..070b08c30 100644
--- a/pyramid/scripts/pviews.py
+++ b/pyramid/scripts/pviews.py
@@ -63,6 +63,7 @@ class PViewsCommand(object):
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 @@ class PViewsCommand(object):
'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__
diff --git a/pyramid/tests/test_scripts/test_pviews.py b/pyramid/tests/test_scripts/test_pviews.py
index 266d1ec90..ee9be6770 100644
--- a/pyramid/tests/test_scripts/test_pviews.py
+++ b/pyramid/tests/test_scripts/test_pviews.py
@@ -465,6 +465,39 @@ class TestPViewsCommand(unittest.TestCase):
' 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