From 2a818aa445a5ed844c30d9a5df1f89adfab728d4 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Fri, 26 Aug 2011 01:45:12 -0400 Subject: - An include could not set a root factory successfully because the Configurator constructor unconditionally registered one that would be treated as if it were "the word of the user". --- CHANGES.txt | 4 ++++ pyramid/config/__init__.py | 3 ++- pyramid/tests/test_config/test_init.py | 15 +++++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 71b4fbecc..b1aa43539 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -8,6 +8,10 @@ Next release - Mako rendering exceptions had the wrong value for an error message. +- An include could not set a root factory successfully because the + Configurator constructor unconditionally registered one that would be + treated as if it were "the word of the user". + 1.2a1 (2011-08-24) ================== diff --git a/pyramid/config/__init__.py b/pyramid/config/__init__.py index dc592977b..7575f4b2b 100644 --- a/pyramid/config/__init__.py +++ b/pyramid/config/__init__.py @@ -334,7 +334,8 @@ class Configurator( for name, renderer in renderers: self.add_renderer(name, renderer) - self.set_root_factory(root_factory) + if root_factory is not None: + self.set_root_factory(root_factory) if locale_negotiator: self.set_locale_negotiator(locale_negotiator) diff --git a/pyramid/tests/test_config/test_init.py b/pyramid/tests/test_config/test_init.py index 0a787275d..da4e9522e 100644 --- a/pyramid/tests/test_config/test_init.py +++ b/pyramid/tests/test_config/test_init.py @@ -201,7 +201,15 @@ class ConfiguratorTests(unittest.TestCase): config = self._makeOne() self.assertEqual(config.registry.queryUtility(IRootFactory), None) config.commit() - self.assertTrue(config.registry.getUtility(IRootFactory)) + self.assertEqual(config.registry.queryUtility(IRootFactory), None) + + def test_ctor_with_root_factory(self): + from pyramid.interfaces import IRootFactory + factory = object() + config = self._makeOne(root_factory=factory) + self.assertEqual(config.registry.queryUtility(IRootFactory), None) + config.commit() + self.assertEqual(config.registry.queryUtility(IRootFactory), factory) def test_ctor_alternate_renderers(self): from pyramid.interfaces import IRendererFactory @@ -512,15 +520,14 @@ class ConfiguratorTests(unittest.TestCase): config.setup_registry(authorization_policy=policy) config = self.assertRaises(ConfigurationExecutionError, config.commit) - def test_setup_registry_default_root_factory(self): + def test_setup_registry_no_default_root_factory(self): from pyramid.registry import Registry from pyramid.interfaces import IRootFactory reg = Registry() config = self._makeOne(reg) config.setup_registry() - self.assertEqual(reg.queryUtility(IRootFactory), None) config.commit() - self.assertTrue(reg.getUtility(IRootFactory)) + self.assertEqual(reg.queryUtility(IRootFactory), None) def test_setup_registry_dottedname_root_factory(self): from pyramid.registry import Registry -- cgit v1.2.3