Permalink
Browse files

- ``testing.setUp`` now adds a ``settings`` attribute to the registry…

… (both

  when it's passed a registry without any settings and when it creates one).

- The ``testing.setUp`` function now takes a ``settings`` argument, which
  should be a dictionary.  Its values will subsequently be available on the
  returned ``config`` object as ``config.registry.settings``.
  • Loading branch information...
1 parent beff12f commit 2a13b0dff000c5cd766299c52d495d82e3ec83b7 @mcdonc mcdonc committed Jan 21, 2011
Showing with 45 additions and 3 deletions.
  1. +10 −0 CHANGES.txt
  2. +1 −1 pyramid/renderers.py
  3. +9 −1 pyramid/testing.py
  4. +1 −1 pyramid/tests/test_settings.py
  5. +24 −0 pyramid/tests/test_testing.py
View
@@ -13,6 +13,16 @@ Features
to ``True``. If it is set to ``False``, the feature of the policy which
sets a cookie with a wilcard domain will be turned off.
+Bug Fixes
+---------
+
+- ``testing.setUp`` now adds a ``settings`` attribute to the registry (both
+ when it's passed a registry without any settings and when it creates one).
+
+- The ``testing.setUp`` function now takes a ``settings`` argument, which
+ should be a dictionary. Its values will subsequently be available on the
+ returned ``config`` object as ``config.registry.settings``.
+
Documentation
-------------
View
@@ -268,7 +268,7 @@ def __init__(self, name=None, package=None, registry=None):
@reify
def settings(self):
- settings = self.registry.settings
+ settings = self.registry.settings or {}
return settings
@reify
View
@@ -613,7 +613,8 @@ def add_response_callback(self, callback):
self.response_callbacks = []
self.response_callbacks.append(callback)
-def setUp(registry=None, request=None, hook_zca=True, autocommit=True):
+def setUp(registry=None, request=None, hook_zca=True, autocommit=True,
+ settings=None):
"""
Set :app:`Pyramid` registry and request thread locals for the
duration of a single unit test.
@@ -661,6 +662,9 @@ def setUp(registry=None, request=None, hook_zca=True, autocommit=True):
:mod:`zope.component` package cannot be imported, or if
``hook_zca`` is ``False``, the hook will not be set.
+ If ``settings`` is not None, it must be a dictionary representing the
+ values passed to a Configurator as its ``settings=`` argument.
+
This function returns an instance of the
:class:`pyramid.config.Configurator` class, which can be
used for further configuration to set up an environment suitable
@@ -674,6 +678,10 @@ def setUp(registry=None, request=None, hook_zca=True, autocommit=True):
if registry is None:
registry = Registry('testing')
config = Configurator(registry=registry, autocommit=autocommit)
+ if settings is None:
+ settings = {}
+ if getattr(registry, 'settings', None) is None:
+ config._set_settings(settings)
if hasattr(registry, 'registerUtility'):
# Sometimes nose calls us with a non-registry object because
# it thinks this function is module test setup. Likewise,
@@ -243,7 +243,7 @@ def _callFUT(self):
return get_settings()
def test_it_nosettings(self):
- self.assertEqual(self._callFUT(), None)
+ self.assertEqual(self._callFUT()['reload_templates'], False)
def test_it_withsettings(self):
settings = {'a':1}
@@ -586,6 +586,30 @@ def test_it_with_hook_zca_false(self):
getSiteManager.reset()
manager.clear()
+ def test_it_with_settings_passed_explicit_registry(self):
+ from zope.component import getSiteManager
+ from pyramid.threadlocal import manager
+ from pyramid.registry import Registry
+ registry = Registry()
+ try:
+ self._callFUT(registry=registry, hook_zca=False,
+ settings=dict(a=1))
+ self.assertEqual(registry.settings['a'], 1)
+ finally:
+ getSiteManager.reset()
+ manager.clear()
+
+ def test_it_with_settings_passed_implicit_registry(self):
+ from zope.component import getSiteManager
+ from pyramid.threadlocal import manager
+ try:
+ config = self._callFUT(hook_zca=False,
+ settings=dict(a=1))
+ self.assertEqual(config.registry.settings['a'], 1)
+ finally:
+ getSiteManager.reset()
+ manager.clear()
+
class Test_cleanUp(Test_setUp):
def _callFUT(self, *arg, **kw):
from pyramid.testing import cleanUp

0 comments on commit 2a13b0d

Please sign in to comment.