summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Petrello <lists@ryanpetrello.com>2015-02-20 09:39:54 -0500
committerRyan Petrello <lists@ryanpetrello.com>2015-03-02 21:11:31 -0500
commit465088213b2d884fe09613aed207eb92ceaeef27 (patch)
tree692fec528e92665375c3d7de19cf04627bb3bca3
parentf4d923dca610da1ee208f403afdb63b1e69f0657 (diff)
downloadpecan-465088213b2d884fe09613aed207eb92ceaeef27.tar.gz
Prevent @expose(generic=True) on special methods (_route, _lookup, _default).
Change-Id: Ie180cc4092ab1457dd97176cc72c563e1d4c561f
-rw-r--r--pecan/decorators.py5
-rw-r--r--pecan/tests/test_generic.py23
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)
+ )