Merge "Prevent @expose(generic=True) on special methods (_route, _lookup, _default)."

This commit is contained in:
Jenkins 2015-04-12 18:45:21 +00:00 committed by Gerrit Code Review
commit 87b8d00a2e
2 changed files with 28 additions and 0 deletions

View File

@ -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'] = []

View File

@ -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)
)