From f5abdb915c48b16c4e9bac857d73a36888c07fc4 Mon Sep 17 00:00:00 2001 From: Christophe de Vienne Date: Tue, 17 Apr 2012 15:44:00 +0200 Subject: [PATCH] Improve detection of double-exposed functions + added a unittest --- wsme/api.py | 4 ++-- wsme/tests/test_api.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/wsme/api.py b/wsme/api.py index 1270af9..69a97d5 100644 --- a/wsme/api.py +++ b/wsme/api.py @@ -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 diff --git a/wsme/tests/test_api.py b/wsme/tests/test_api.py index 9d5978d..e0f4c8d 100644 --- a/wsme/tests/test_api.py +++ b/wsme/tests/test_api.py @@ -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