Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

includeOverrides didn't work in Pyramid 1.2

  • Loading branch information...
commit 9577a3b8be6b5e96a8b80b60924db2b26a440b7e 1 parent 90e948c
@mcdonc mcdonc authored
View
18 pyramid_zcml/__init__.py
@@ -824,7 +824,6 @@ def load_zcml(self, spec='configure.zcml', lock=threading.Lock()):
# ZCML expects. So we don't autocommit each ZCML directive action
# while parsing is happening, but we do make sure to commit right
# after parsing if autocommit it True.
-
context = ConfigurationMachine()
context.registry = self.registry
context.autocommit = False
@@ -836,14 +835,29 @@ def load_zcml(self, spec='configure.zcml', lock=threading.Lock()):
lock.acquire()
try:
+ # old_action_state will be None for Pyramid 1.0 and 1.1, but
+ # not for 1.2
+ old_action_state = getattr(self.registry, 'action_state', None)
+ if old_action_state is not None:
+ # For Pyramid 1.2+, we need to assign a temporary action state to
+ # the registry, because the configurator actions must populate
+ # the context's action list (instead of the registry action
+ # state's action list) in order for includeOverrides to work
+ # properly.
+ from pyramid.config import ActionState
+ self.registry.action_state = ActionState()
+ self.registry.action_state.actions = context.actions
xmlconfig.file(filename, package, context=context,
execute=False)
finally:
+ if old_action_state is not None:
+ # if we reassigned the action state, restore the old one (1.2 only)
+ self.registry.action_state = old_action_state
lock.release()
self.manager.pop()
_ctx = self._ctx
- if _ctx is None: # will never be true under 1.2a5+
+ if _ctx is None: # pragma: no cover ; will never be true under 1.2a5+
_ctx = self._ctx = self._make_context(self.autocommit)
_ctx.actions.extend(context.actions)
if self.autocommit:
View
1  pyramid_zcml/tests/includeoverrideapp/__init__.py
@@ -0,0 +1 @@
+# package
View
16 pyramid_zcml/tests/includeoverrideapp/configure.zcml
@@ -0,0 +1,16 @@
+<configure xmlns="http://pylonshq.com/pyramid">
+
+ <include package="pyramid_zcml" />
+
+ <route
+ path="abc"
+ name="theroute" />
+
+ <view
+ view=".views.theview"
+ route_name="theroute"
+ />
+
+ <includeOverrides package=".sub" file="overrides.zcml"/>
+
+</configure>
View
1  pyramid_zcml/tests/includeoverrideapp/sub/__init__.py
@@ -0,0 +1 @@
+# package
View
12 pyramid_zcml/tests/includeoverrideapp/sub/overrides.zcml
@@ -0,0 +1,12 @@
+<configure xmlns="http://pylonshq.com/pyramid">
+
+ <route
+ path="abc"
+ name="theroute" />
+
+ <view
+ view=".views.theview"
+ route_name="theroute"
+ />
+
+</configure>
View
4 pyramid_zcml/tests/includeoverrideapp/sub/views.py
@@ -0,0 +1,4 @@
+from pyramid.response import Response
+
+def theview(request): return Response('thesubview')
+
View
3  pyramid_zcml/tests/includeoverrideapp/views.py
@@ -0,0 +1,3 @@
+from pyramid.response import Response
+
+def theview(request): return Response('theview')
View
3  pyramid_zcml/tests/index.html
@@ -0,0 +1,3 @@
+<html>
+fixture
+</html>
View
16 pyramid_zcml/tests/test_integration.py
@@ -182,3 +182,19 @@ def test_route_raise_exception4(self):
res = self.testapp.get('/route_raise_exception4', status=200)
self.failUnless('whoa' in res.body)
+class TestIncludeOverrideApp(unittest.TestCase):
+ config = 'pyramid_zcml.tests.includeoverrideapp:configure.zcml'
+ def test_it(self):
+ # see http://www.mail-archive.com/zope-dev@zope.org/msg35171.html
+ # for an explanation of why load_zcml of includeoverrideapp's
+ # configure.zcml should raise a ConfigurationConflictError
+ try: # pragma: no cover
+ from pyramid.exceptions import ConfigurationConflictError
+ except ImportError: # pragma: no cover
+ from zope.configuration.config import ConfigurationConflictError
+ from pyramid_zcml import includeme
+ from pyramid.config import Configurator
+ config = Configurator()
+ config.include(includeme)
+ config.load_zcml(self.config)
+ self.assertRaises(ConfigurationConflictError, config.make_wsgi_app)
View
29 pyramid_zcml/tests/test_units.py
@@ -1,4 +1,5 @@
import logging
+import sys
logging.basicConfig()
@@ -66,8 +67,6 @@ def pred2(context, request):
self.assertEqual(len(actions), 1)
discrim = actions[0]['discriminator']
self.assertEqual(discrim[0], 'view')
- self.assertTrue(pred1 in discrim)
- self.assertTrue(pred2 in discrim)
register = actions[0]['callable']
register()
regview = reg.adapters.lookup(
@@ -539,6 +538,9 @@ def test_with_neither_path_nor_pattern(self):
class TestStaticDirective(unittest.TestCase):
def setUp(self):
self.config = testing.setUp(autocommit=False)
+ package = sys.modules[__name__]
+ self.config.package = package
+ self.config.package_name = package.__name__
def tearDown(self):
testing.tearDown()
@@ -549,7 +551,6 @@ def _callFUT(self, *arg, **kw):
def test_it_with_slash(self):
self.config.testing_securitypolicy(permissive=False)
- from pyramid.static import PackageURLParser
from zope.interface import implementedBy
try:
from pyramid.config.views import StaticURLInfo
@@ -560,9 +561,10 @@ def test_it_with_slash(self):
from pyramid.interfaces import IRouteRequest
from pyramid.interfaces import IRoutesMapper
reg = self.config.registry
+
context = DummyZCMLContext(self.config)
- self._callFUT(context, 'name', 'fixtures/static',
+ self._callFUT(context, 'name', '',
renderer=null_renderer)
actions = extract_actions(context.actions)
_execute_actions(actions)
@@ -570,14 +572,15 @@ def test_it_with_slash(self):
routes = mapper.get_routes()
self.assertEqual(len(routes), 1)
self.assertEqual(routes[0].pattern, 'name/*subpath')
- self.assertEqual(routes[0].name, 'name/')
+ self.assertTrue('name' in routes[0].name)
iface = implementedBy(StaticURLInfo)
- request_type = reg.getUtility(IRouteRequest, 'name/')
+ request_type = reg.getUtility(IRouteRequest, routes[0].name)
view = reg.adapters.lookup(
(IViewClassifier, request_type, iface), IView, name='')
request = DummyRequest()
- self.assertEqual(view(None, request).__class__, PackageURLParser)
+ val = view(None, request).__class__.__name__
+ self.assertTrue(val in ['PackageURLParser', 'HTTPMovedPermanently'])
def test_it_with_nondefault_permission(self):
from pyramid.exceptions import Forbidden
@@ -600,11 +603,11 @@ def test_it_with_nondefault_permission(self):
routes = mapper.get_routes()
self.assertEqual(len(routes), 1)
self.assertEqual(routes[0].pattern, 'name/*subpath')
- self.assertEqual(routes[0].name, 'name/')
+ self.assertTrue('name' in routes[0].name)
iface = implementedBy(StaticURLInfo)
- request_type = reg.getUtility(IRouteRequest, 'name/')
+ request_type = reg.getUtility(IRouteRequest, routes[0].name)
view = reg.adapters.lookup(
(IViewClassifier, request_type, iface), IView, name='')
request = DummyRequest()
@@ -1257,16 +1260,18 @@ class DummyRoute:
class DummyRequest:
subpath = ()
+ path_url = ''
+ query_string = ''
def __init__(self, environ=None):
if environ is None:
environ = {}
self.environ = environ
self.path_info = environ.get('PATH_INFO', None)
- def get_response(self, app):
+ def get_response(self, app): # pragma: no cover
return app
- def copy(self):
+ def copy(self): # pragma: no cover
return self
class DummyPackage(object):
@@ -1326,7 +1331,7 @@ def hook_zca(self):
class DummyZCMLContext(object):
def __init__(self, config):
- if hasattr(config, '_make_context'):
+ if hasattr(config, '_make_context'): # pragma: no cover
# 1.0, 1.1 b/c
config._ctx = config._make_context()
self.registry = config.registry
Please sign in to comment.
Something went wrong with that request. Please try again.