More code coverage, and fixed a bug with wsme.wsgi.WSRoot.clone
This commit is contained in:
parent
bc420e6316
commit
4ce24d6b5c
|
@ -14,6 +14,8 @@ log = logging.getLogger(__name__)
|
|||
|
||||
registered_protocols = {}
|
||||
|
||||
APIPATH_MAXLEN = 20
|
||||
|
||||
|
||||
html_body = """
|
||||
<html>
|
||||
|
@ -41,8 +43,8 @@ def scan_api(controller, path=[]):
|
|||
elif inspect.isclass(a):
|
||||
continue
|
||||
else:
|
||||
if len(path) > 10:
|
||||
raise ValueError(str(path))
|
||||
if len(path) > APIPATH_MAXLEN:
|
||||
raise ValueError("Path is too long: " + str(path))
|
||||
for i in scan_api(a, path + [name]):
|
||||
yield i
|
||||
|
||||
|
|
|
@ -92,12 +92,28 @@ class TestController(unittest.TestCase):
|
|||
|
||||
r = MyRoot()
|
||||
|
||||
api = [i for i in scan_api(r)]
|
||||
api = list(scan_api(r))
|
||||
assert len(api) == 1
|
||||
fd = api[0]
|
||||
assert fd.path == ['ns']
|
||||
assert fd.name == 'multiply'
|
||||
|
||||
def test_scan_api_too_deep(self):
|
||||
class Loop(object):
|
||||
loop = None
|
||||
Loop.me = Loop()
|
||||
|
||||
class MyRoot(WSRoot):
|
||||
loop = Loop()
|
||||
|
||||
r = MyRoot()
|
||||
|
||||
try:
|
||||
list(scan_api(r))
|
||||
assert False, "ValueError not raised"
|
||||
except ValueError, e:
|
||||
assert str(e).startswith("Path is too long")
|
||||
|
||||
def test_handle_request(self):
|
||||
class MyRoot(WSRoot):
|
||||
@expose()
|
||||
|
|
|
@ -9,3 +9,6 @@ class WSRoot(controller.WSRoot, wsgify):
|
|||
def __init__(self, *args, **kw):
|
||||
super(WSRoot, self).__init__(*args, **kw)
|
||||
wsgify.__init__(self, self._handle_request)
|
||||
|
||||
def clone(self, func=None, **kw):
|
||||
return WSRoot(**kw)
|
||||
|
|
Loading…
Reference in New Issue