summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2011-04-06 15:36:11 -0400
committerChris McDonough <chrism@plope.com>2011-04-06 15:36:11 -0400
commit8af47bc6bdc15cacfbe26e0507bd674ebf7ce80f (patch)
tree5aff465043548a7e182950c3b5c74017d4abc909
parent88f9674662dbb53073756c616c4610c8dd0beb48 (diff)
downloadpyramid-8af47bc6bdc15cacfbe26e0507bd674ebf7ce80f.tar.gz
pyramid-8af47bc6bdc15cacfbe26e0507bd674ebf7ce80f.tar.bz2
pyramid-8af47bc6bdc15cacfbe26e0507bd674ebf7ce80f.zip
- ``testing.DummyRequest`` used the wrong registry (the global registry) as
``self.registry`` if a dummy request was created *before* ``testing.setUp`` was executed (``testing.setUp`` pushes a local registry onto the threadlocal stack). Fixed by implementing ``registry`` as a property for DummyRequest instead of eagerly assigning an attribute. See also https://github.com/Pylons/pyramid/issues/165 Closes #165.
-rw-r--r--CHANGES.txt7
-rw-r--r--pyramid/testing.py5
-rw-r--r--pyramid/tests/test_testing.py14
3 files changed, 24 insertions, 2 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 12da3bc06..780df9e8a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -66,6 +66,13 @@ Bug Fixes
``factory=`` to ``add_static_view`` to protect a particular static view
with a custom ACL.
+- ``testing.DummyRequest`` used the wrong registry (the global registry) as
+ ``self.registry`` if a dummy request was created *before* ``testing.setUp``
+ was executed (``testing.setUp`` pushes a local registry onto the
+ threadlocal stack). Fixed by implementing ``registry`` as a property for
+ DummyRequest instead of eagerly assigning an attribute.
+ See also https://github.com/Pylons/pyramid/issues/165
+
1.0 (2011-01-30)
================
diff --git a/pyramid/testing.py b/pyramid/testing.py
index 3b3bb7c67..a98807a19 100644
--- a/pyramid/testing.py
+++ b/pyramid/testing.py
@@ -690,7 +690,6 @@ class DummyRequest(object):
self.root = None
self.virtual_root = None
self.marshalled = params # repoze.monty
- self.registry = get_current_registry()
self.session = DummySession()
self.__dict__.update(kw)
@@ -699,6 +698,10 @@ class DummyRequest(object):
self.response_callbacks = []
self.response_callbacks.append(callback)
+ @property
+ def registry(self):
+ return get_current_registry()
+
def setUp(registry=None, request=None, hook_zca=True, autocommit=True,
settings=None):
"""
diff --git a/pyramid/tests/test_testing.py b/pyramid/tests/test_testing.py
index b432928ab..99b0a1911 100644
--- a/pyramid/tests/test_testing.py
+++ b/pyramid/tests/test_testing.py
@@ -488,7 +488,19 @@ class TestDummyRequest(unittest.TestCase):
request = self._makeOne()
request.add_response_callback(1)
self.assertEqual(request.response_callbacks, [1])
-
+
+ def test_registry_is_config_registry_when_setup_is_called_after_ctor(self):
+ # see https://github.com/Pylons/pyramid/issues/165
+ from pyramid.registry import Registry
+ from pyramid.config import Configurator
+ request = self._makeOne()
+ try:
+ registry = Registry('this_test')
+ config = Configurator(registry=registry)
+ config.begin()
+ self.failUnless(request.registry is registry)
+ finally:
+ config.end()
class TestDummyTemplateRenderer(unittest.TestCase):
def _getTargetClass(self, ):