diff options
| author | Rob Miller <rob@mochimedia.com> | 2010-12-28 22:53:17 -0800 |
|---|---|---|
| committer | Rob Miller <rob@mochimedia.com> | 2010-12-28 22:53:17 -0800 |
| commit | 88231cc1b16f1f5a0983dba1dab9b401bbde0c00 (patch) | |
| tree | d89a14c52546a512120bd2201165a2c420b832f5 | |
| parent | 91f9e646e86dabd68b4184aa0f48bb60856aec14 (diff) | |
| download | pyramid-88231cc1b16f1f5a0983dba1dab9b401bbde0c00.tar.gz pyramid-88231cc1b16f1f5a0983dba1dab9b401bbde0c00.tar.bz2 pyramid-88231cc1b16f1f5a0983dba1dab9b401bbde0c00.zip | |
Enforce that _action_decorator must be a classmethod
| -rw-r--r-- | pyramid/config.py | 4 | ||||
| -rw-r--r-- | pyramid/tests/test_config.py | 11 |
2 files changed, 15 insertions, 0 deletions
diff --git a/pyramid/config.py b/pyramid/config.py index 5c3bf7002..274938225 100644 --- a/pyramid/config.py +++ b/pyramid/config.py @@ -942,6 +942,10 @@ class Configurator(object): pattern = route.pattern action_decorator = getattr(handler, '_action_decorator', None) + if action_decorator is not None and action_decorator.im_self is None: + raise ConfigurationError( + 'The "_action_decorator" method on a handler class MUST be ' + 'defined as a classmethod.') path_has_action = ':action' in pattern or '{action}' in pattern diff --git a/pyramid/tests/test_config.py b/pyramid/tests/test_config.py index 2bbd2e4aa..0a87f4d7f 100644 --- a/pyramid/tests/test_config.py +++ b/pyramid/tests/test_config.py @@ -1993,6 +1993,17 @@ class ConfiguratorTests(unittest.TestCase): self.assertEqual(len(views), 1) self.assertEqual(views[0]['decorator'], MyHandler._action_decorator) + def test_add_handler_with_action_decorator_no_classmethod(self): + config = self._makeOne(autocommit=True) + class MyHandler(object): + def _action_decorator(self, fn): # pragma: no cover + return fn + def action(self): # pragma: no cover + return 'response' + from pyramid.exceptions import ConfigurationError + self.assertRaises(ConfigurationError, config.add_handler, + 'name', '/{action}', MyHandler) + def test_add_handler_doesnt_mutate_expose_dict(self): config = self._makeOne(autocommit=True) views = [] |
