From af9f2e5fd5664aeaea2057ce1c518fb04617a0f0 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sun, 29 Nov 2009 14:52:29 +0000 Subject: - Trying to use an HTTP method name string such as ``GET`` as a ``request_type`` predicate caused a startup time failure when it was encountered in imperative configuration or in a decorator (symptom: ``Type Error: Required specification must be a specification``). This now works again, although ``request_method`` is a more modern predicate. --- repoze/bfg/configuration.py | 5 +++++ repoze/bfg/tests/test_configuration.py | 13 +++++++++++++ 2 files changed, 18 insertions(+) (limited to 'repoze') diff --git a/repoze/bfg/configuration.py b/repoze/bfg/configuration.py index c37ed2c72..4d7e8dd57 100644 --- a/repoze/bfg/configuration.py +++ b/repoze/bfg/configuration.py @@ -547,6 +547,11 @@ class Configurator(object): raise ConfigurationError('"view" was not specified and ' 'no "renderer" specified') + if request_type in ('GET', 'HEAD', 'PUT', 'POST', 'DELETE'): + # b/w compat for 1.0 + request_method = request_type + request_type = None + if request_type and route_name: raise ConfigurationError( 'A view cannot be configured with both the request_type and ' diff --git a/repoze/bfg/tests/test_configuration.py b/repoze/bfg/tests/test_configuration.py index 060f30e3a..416df3086 100644 --- a/repoze/bfg/tests/test_configuration.py +++ b/repoze/bfg/tests/test_configuration.py @@ -345,6 +345,19 @@ class ConfiguratorTests(unittest.TestCase): self.assertRaises(ConfigurationError, config.add_view, view, '', None, None, True, True) + def test_add_view_with_request_type_string(self): + view = lambda *arg: 'OK' + config = self._makeOne() + config.add_view(view=view, request_type='GET') + wrapper = self._getViewCallable(config) + request = DummyRequest() + request.method = 'POST' + self._assertNotFound(wrapper, None, request) + request = DummyRequest() + request.method = 'GET' + result = wrapper(None, request) + self.assertEqual(result, 'OK') + def test_add_view_view_callable_None_with_renderer(self): config = self._makeOne() self._registerRenderer(config, name='dummy') -- cgit v1.2.3