diff options
| author | Chris McDonough <chrism@plope.com> | 2011-08-26 02:03:52 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2011-08-26 02:03:52 -0400 |
| commit | 637bda4c885b01e2ecdb931344bc71f12101eb4e (patch) | |
| tree | 562551e3508332384007a6c2b64a98dff6dbe4c2 | |
| parent | 145612710809dbe6b764e912be45a8cc68b53bd9 (diff) | |
| download | pyramid-637bda4c885b01e2ecdb931344bc71f12101eb4e.tar.gz pyramid-637bda4c885b01e2ecdb931344bc71f12101eb4e.tar.bz2 pyramid-637bda4c885b01e2ecdb931344bc71f12101eb4e.zip | |
- A session factory can now be passed in using the dotted name syntax.
| -rw-r--r-- | CHANGES.txt | 2 | ||||
| -rw-r--r-- | pyramid/config/__init__.py | 12 | ||||
| -rw-r--r-- | pyramid/config/factories.py | 7 | ||||
| -rw-r--r-- | pyramid/tests/test_config/test_init.py | 27 |
4 files changed, 15 insertions, 33 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index b1aa43539..cf1f0ee96 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -12,6 +12,8 @@ Next release Configurator constructor unconditionally registered one that would be treated as if it were "the word of the user". +- A session factory can now be passed in using the dotted name syntax. + 1.2a1 (2011-08-24) ================== diff --git a/pyramid/config/__init__.py b/pyramid/config/__init__.py index 7575f4b2b..a335ae049 100644 --- a/pyramid/config/__init__.py +++ b/pyramid/config/__init__.py @@ -293,10 +293,8 @@ class Configurator( registry.registerUtility(debug_logger, IDebugLogger) - if renderers is None: - for name, renderer in DEFAULT_RENDERERS: - self.add_renderer(name, renderer) - renderers = [] + for name, renderer in DEFAULT_RENDERERS: + self.add_renderer(name, renderer) if exceptionresponse_view is not None: exceptionresponse_view = self.maybe_dotted(exceptionresponse_view) @@ -325,14 +323,16 @@ class Configurator( if authorization_policy: self.set_authorization_policy(authorization_policy) + if authentication_policy: self.set_authentication_policy(authentication_policy) if default_view_mapper is not None: self.set_view_mapper(default_view_mapper) - for name, renderer in renderers: - self.add_renderer(name, renderer) + if renderers: + for name, renderer in renderers: + self.add_renderer(name, renderer) if root_factory is not None: self.set_root_factory(root_factory) diff --git a/pyramid/config/factories.py b/pyramid/config/factories.py index 53db93c64..bf3e0f5cd 100644 --- a/pyramid/config/factories.py +++ b/pyramid/config/factories.py @@ -32,14 +32,15 @@ class FactoriesConfiguratorMixin(object): @action_method def set_session_factory(self, session_factory): """ - Configure the application with a :term:`session factory`. If - this method is called, the ``session_factory`` argument must - be a session factory callable. + Configure the application with a :term:`session factory`. If this + method is called, the ``session_factory`` argument must be a session + factory callable or a :term:`dotted Python name` to that factory. .. note:: Using the ``session_factory`` argument to the :class:`pyramid.config.Configurator` constructor can be used to achieve the same purpose. """ + session_factory = self.maybe_dotted(session_factory) def register(): self.registry.registerUtility(session_factory, ISessionFactory) self.action(ISessionFactory, register, order=PHASE3_CONFIG) diff --git a/pyramid/tests/test_config/test_init.py b/pyramid/tests/test_config/test_init.py index da4e9522e..f3ff5aaca 100644 --- a/pyramid/tests/test_config/test_init.py +++ b/pyramid/tests/test_config/test_init.py @@ -234,10 +234,11 @@ class ConfiguratorTests(unittest.TestCase): def test_ctor_session_factory(self): from pyramid.interfaces import ISessionFactory - config = self._makeOne(session_factory='factory') + factory = object() + config = self._makeOne(session_factory=factory) self.assertEqual(config.registry.queryUtility(ISessionFactory), None) config.commit() - self.assertEqual(config.registry.getUtility(ISessionFactory), 'factory') + self.assertEqual(config.registry.getUtility(ISessionFactory), factory) def test_ctor_default_view_mapper(self): from pyramid.interfaces import IViewMapperFactory @@ -2786,21 +2787,6 @@ pyramid.tests.test_config.dummy_include2""", self.assertEqual(config.registry.getUtility(ILocaleNegotiator), dummyfactory) - def test_set_request_factory(self): - from pyramid.interfaces import IRequestFactory - config = self._makeOne(autocommit=True) - factory = object() - config.set_request_factory(factory) - self.assertEqual(config.registry.getUtility(IRequestFactory), factory) - - def test_set_request_factory_dottedname(self): - from pyramid.interfaces import IRequestFactory - config = self._makeOne(autocommit=True) - config.set_request_factory( - 'pyramid.tests.test_config.dummyfactory') - self.assertEqual(config.registry.getUtility(IRequestFactory), - dummyfactory) - def test_set_renderer_globals_factory(self): import warnings warnings.filterwarnings('ignore') @@ -2852,13 +2838,6 @@ pyramid.tests.test_config.dummy_include2""", from pyramid.tests import test_config self.assertEqual(result, test_config) - def test_set_session_factory(self): - from pyramid.interfaces import ISessionFactory - config = self._makeOne(autocommit=True) - config.set_session_factory('factory') - self.assertEqual(config.registry.getUtility(ISessionFactory), - 'factory') - def test_add_translation_dirs_missing_dir(self): from pyramid.exceptions import ConfigurationError config = self._makeOne() |
