Improve detection of double-exposed functions + added a unittest

This commit is contained in:
Christophe de Vienne
2012-04-17 15:44:00 +02:00
parent 6e47f1732a
commit f5abdb915c
2 changed files with 13 additions and 2 deletions

View File

@@ -99,7 +99,7 @@ class FunctionDefinition(object):
self.contenttype = None
#: Dictionnary of protocol-specific options.
self.extra_options = {}
self.extra_options = None
@classmethod
def get(cls, func):
@@ -143,7 +143,7 @@ class expose(object):
def __call__(self, func):
func, fd = FunctionDefinition.get(func)
if fd.return_type is not None:
if fd.extra_options is not None:
raise ValueError("This function is already exposed")
fd.return_type = self.return_type
fd.extra_options = self.options

View File

@@ -197,6 +197,17 @@ class TestController(unittest.TestCase):
assert res.status_int == 400
assert res.content_type == 'text/plain', res.content_type
def test_double_expose(self):
try:
class MyRoot(WSRoot):
@expose()
@expose()
def atest(self):
pass
assert False, "A ValueError should have been raised"
except ValueError:
pass
def test_getapi(self):
class MyRoot(WSRoot):
pass