Merge "Prevent @expose(generic=True) on special methods (_route, _lookup, _default)."
This commit is contained in:
commit
87b8d00a2e
|
@ -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'] = []
|
||||
|
|
|
@ -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)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue