Bugfix: a complex type used only in validate and never in expose was not registered

This commit is contained in:
Christophe de Vienne
2011-10-28 09:47:33 +02:00
parent a05ff59e33
commit a4290c7ae9
2 changed files with 12 additions and 0 deletions

View File

@@ -230,6 +230,7 @@ class validate(object):
args = args[1:]
for i, argname in enumerate(args):
datatype = self.param_types[i]
register_type(datatype)
mandatory = defaults is None or i < (len(args) - len(defaults))
default = None
if not mandatory:

View File

@@ -8,6 +8,7 @@ import webtest
from wsme import *
from wsme.controller import getprotocol, scan_api, pexpose
from wsme.controller import FunctionArgument, FunctionDefinition, CallContext
from wsme.types import iscomplex
import wsme.wsgi
@@ -90,12 +91,20 @@ class TestController(unittest.TestCase):
assert MyWS.getint._wsme_definition.return_type == int
def test_validate(self):
class ComplexType(object):
attr = int
class MyWS(object):
@expose(int)
@validate(int, int, int)
def add(self, a, b, c=0):
return a + b + c
@expose(bool)
@validate(ComplexType)
def setcplx(self, obj):
pass
args = MyWS.add._wsme_definition.arguments
assert args[0].name == 'a'
@@ -113,6 +122,8 @@ class TestController(unittest.TestCase):
assert not args[2].mandatory
assert args[2].default == 0
assert iscomplex(ComplexType)
def test_register_protocol(self):
import wsme.controller
wsme.controller.register_protocol(DummyProtocol)