diff options
-rw-r--r-- | pecan/decorators.py | 5 | ||||
-rw-r--r-- | pecan/tests/test_generic.py | 23 |
2 files changed, 28 insertions, 0 deletions
diff --git a/pecan/decorators.py b/pecan/decorators.py index ed054ec..36d33fa 100644 --- a/pecan/decorators.py +++ b/pecan/decorators.py @@ -55,6 +55,11 @@ def expose(template=None, # handle generic controllers if generic: + if f.__name__ in ('_default', '_lookup', '_route'): + raise ValueError( + 'The special method %s cannot be used as a generic ' + 'controller' % f.__name__ + ) cfg['generic'] = True cfg['generic_handlers'] = dict(DEFAULT=f) cfg['allowed_methods'] = [] diff --git a/pecan/tests/test_generic.py b/pecan/tests/test_generic.py index 19127fc..0478799 100644 --- a/pecan/tests/test_generic.py +++ b/pecan/tests/test_generic.py @@ -86,3 +86,26 @@ class TestGeneric(PecanTestCase): r = app.delete('/sub/sub/joe/is/cool') assert r.status_int == 200 assert r.body == b_(dumps(dict(result='joe', args='is, cool'))) + + +class TestGenericWithSpecialMethods(PecanTestCase): + + def test_generics_not_allowed(self): + + class C(object): + + def _default(self): + pass + + def _lookup(self): + pass + + def _route(self): + pass + + for method in (C._default, C._lookup, C._route): + self.assertRaises( + ValueError, + expose(generic=True), + getattr(method, '__func__', method) + ) |