From 358dc276d28fb395a9a742ff53dc66ee115c58ad Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sun, 11 Jan 2009 02:20:52 +0000 Subject: Merge router-simplify branch. Changelog below. Bug Fixes --------- - Fix a bug where the Paste configuration's ``unicode_path_segments`` (and os.environ's ``BFG_UNICODE_PATH_SEGMENTS``) may have been defaulting to false in some circumstances. It now always defaults to true, matching the documentation and intent. - The ``repoze.bfg.traversal.find_model`` API did not work properly when passed a ``path`` argument which was unicode and contained high-order bytes when the ``unicode_path_segments`` or ``BFG_UNICODE_PATH_SEGMENTS`` configuration variables were "true". - A new module was added: ``repoze.bfg.settings``. This contains deployment-settings-related code. Behavior Changes ---------------- - The ``make_app`` callable within ``repoze.bfg.router`` now registers the ``root_policy`` argument as a utility (unnamed, using the new ``repoze.bfg.interfaces.IRootFactory`` as a provides interface) rather than passing it as the first argument to the ``repoze.bfg.router.Router`` class. As a result the ``repoze.bfg.router.Router`` router class only accepts a single argument: ``registry``. The ``repoze.bfg.router.Router`` class retrieves the root policy via a utility lookup now. The ``repoze.bfg.router.make_app`` API also now performs some important application registrations that were previously handled inside ``repoze.bfg.registry.makeRegistry``. - The ``repoze.bfg.settings.Settings`` class (an instance of which is registered as a utility providing ``repoze.bfg.interfaces.ISettings`` when any application is started) now automatically calls ``repoze.bfg.settings.get_options`` on the options passed to its constructor. This means that usage of ``get_options`` within an application's ``make_app`` function is no longer required (the "raw" ``options`` dict or None may be passed). Deprecations ------------ - Moved the ``repoze.bfg.registry.Settings`` class. This has been moved to ``repoze.bfg.settings.Settings``. A deprecation warning is issued when it is imported from the older location. - Moved the ``repoze.bfg.registry.get_options`` function This has been moved to ``repoze.bfg.settings.get_options``. A deprecation warning is issued when it is imported from the older location. - The ``repoze.bfg.interfaces.IRootPolicy`` interface was renamed within the interfaces package. It has been renamed to ``IRootFactory``. A deprecation warning is issued when it is imported from the older location. --- repoze/bfg/tests/test_registry.py | 129 -------------------------------------- 1 file changed, 129 deletions(-) (limited to 'repoze/bfg/tests/test_registry.py') diff --git a/repoze/bfg/tests/test_registry.py b/repoze/bfg/tests/test_registry.py index 9bf09399f..0d051c131 100644 --- a/repoze/bfg/tests/test_registry.py +++ b/repoze/bfg/tests/test_registry.py @@ -23,144 +23,15 @@ class TestMakeRegistry(unittest.TestCase, PlacelessSetup): old = repoze.bfg.registry.setRegistryManager(dummyregmgr) registry = makeRegistry('configure.zcml', fixtureapp, - options={'reload_templates':True, - 'debug_authorization':True}, lock=dummylock) from zope.component.registry import Components self.failUnless(isinstance(registry, Components)) self.assertEqual(dummylock.acquired, True) self.assertEqual(dummylock.released, True) self.assertEqual(dummyregmgr.registry, registry) - from zope.component import getUtility - from repoze.bfg.interfaces import ISettings - from repoze.bfg.interfaces import ILogger - settings = getUtility(ISettings) - logger = getUtility(ILogger, name='repoze.bfg.debug') - self.assertEqual(logger.name, 'repoze.bfg.debug') - self.assertEqual(settings.reload_templates, True) - self.assertEqual(settings.debug_authorization, True) finally: repoze.bfg.registry.setRegistryManager(old) -class TestGetOptions(unittest.TestCase): - def _getFUT(self): - from repoze.bfg.registry import get_options - return get_options - - def test_reload_templates(self): - get_options = self._getFUT() - result = get_options({}) - self.assertEqual(result['reload_templates'], False) - result = get_options({'reload_templates':'false'}) - self.assertEqual(result['reload_templates'], False) - result = get_options({'reload_templates':'t'}) - self.assertEqual(result['reload_templates'], True) - result = get_options({'reload_templates':'1'}) - self.assertEqual(result['reload_templates'], True) - result = get_options({}, {'BFG_RELOAD_TEMPLATES':'1'}) - self.assertEqual(result['reload_templates'], True) - result = get_options({'reload_templates':'false'}, - {'BFG_RELOAD_TEMPLATES':'1'}) - self.assertEqual(result['reload_templates'], True) - - def test_debug_authorization(self): - get_options = self._getFUT() - result = get_options({}) - self.assertEqual(result['debug_authorization'], False) - result = get_options({'debug_authorization':'false'}) - self.assertEqual(result['debug_authorization'], False) - result = get_options({'debug_authorization':'t'}) - self.assertEqual(result['debug_authorization'], True) - result = get_options({'debug_authorization':'1'}) - self.assertEqual(result['debug_authorization'], True) - result = get_options({}, {'BFG_DEBUG_AUTHORIZATION':'1'}) - self.assertEqual(result['debug_authorization'], True) - result = get_options({'debug_authorization':'false'}, - {'BFG_DEBUG_AUTHORIZATION':'1'}) - self.assertEqual(result['debug_authorization'], True) - - def test_debug_notfound(self): - get_options = self._getFUT() - result = get_options({}) - self.assertEqual(result['debug_notfound'], False) - result = get_options({'debug_notfound':'false'}) - self.assertEqual(result['debug_notfound'], False) - result = get_options({'debug_notfound':'t'}) - self.assertEqual(result['debug_notfound'], True) - result = get_options({'debug_notfound':'1'}) - self.assertEqual(result['debug_notfound'], True) - result = get_options({}, {'BFG_DEBUG_NOTFOUND':'1'}) - self.assertEqual(result['debug_notfound'], True) - result = get_options({'debug_notfound':'false'}, - {'BFG_DEBUG_NOTFOUND':'1'}) - self.assertEqual(result['debug_notfound'], True) - - def test_debug_all(self): - get_options = self._getFUT() - result = get_options({}) - self.assertEqual(result['debug_notfound'], False) - self.assertEqual(result['debug_authorization'], False) - result = get_options({'debug_all':'false'}) - self.assertEqual(result['debug_notfound'], False) - self.assertEqual(result['debug_authorization'], False) - result = get_options({'debug_all':'t'}) - self.assertEqual(result['debug_notfound'], True) - self.assertEqual(result['debug_authorization'], True) - result = get_options({'debug_all':'1'}) - self.assertEqual(result['debug_notfound'], True) - self.assertEqual(result['debug_authorization'], True) - result = get_options({}, {'BFG_DEBUG_ALL':'1'}) - self.assertEqual(result['debug_notfound'], True) - self.assertEqual(result['debug_authorization'], True) - result = get_options({'debug_all':'false'}, - {'BFG_DEBUG_ALL':'1'}) - self.assertEqual(result['debug_notfound'], True) - self.assertEqual(result['debug_authorization'], True) - - def test_unicode_path_segments(self): - get_options = self._getFUT() - result = get_options({}) - self.assertEqual(result['unicode_path_segments'], False) - result = get_options({'unicode_path_segments':'false'}) - self.assertEqual(result['unicode_path_segments'], False) - result = get_options({'unicode_path_segments':'t'}) - self.assertEqual(result['unicode_path_segments'], True) - result = get_options({'unicode_path_segments':'1'}) - self.assertEqual(result['unicode_path_segments'], True) - result = get_options({}, {'BFG_UNICODE_PATH_SEGMENTS':'1'}) - self.assertEqual(result['unicode_path_segments'], True) - result = get_options({'unicode_path_segments':'false'}, - {'BFG_UNICODE_PATH_SEGMENTS':'1'}) - self.assertEqual(result['unicode_path_segments'], True) - - def test_originals_kept(self): - get_options = self._getFUT() - result = get_options({'a':'i am so a'}) - self.assertEqual(result['a'], 'i am so a') - -class TestSettings(unittest.TestCase): - def _getTargetClass(self): - from repoze.bfg.registry import Settings - return Settings - - def _makeOne(self, **options): - klass = self._getTargetClass() - return klass(options) - - def test_no_options(self): - settings = self._makeOne() - self.assertEqual(settings.reload_templates, False) - self.assertEqual(settings.debug_notfound, False) - self.assertEqual(settings.debug_authorization, False) - self.assertEqual(settings.unicode_path_segments, True) - - def test_with_option(self): - settings = self._makeOne(reload_templates=True) - self.assertEqual(settings.reload_templates, True) - self.assertEqual(settings.debug_notfound, False) - self.assertEqual(settings.debug_authorization, False) - self.assertEqual(settings.unicode_path_segments, True) - class TestThreadLocalRegistryManager(unittest.TestCase, PlacelessSetup): def setUp(self): PlacelessSetup.setUp(self) -- cgit v1.2.3