Improve detection of double-exposed functions + added a unittest
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user