basic tests for kojixmlrpc
This commit is contained in:
parent
712fcebe55
commit
965153c7e9
2 changed files with 94 additions and 1 deletions
|
|
@ -132,6 +132,7 @@ class HandlerRegistry(object):
|
|||
return ret
|
||||
|
||||
def list_api(self):
|
||||
"""List available API calls"""
|
||||
funcs = []
|
||||
for name, func in self.funcs.items():
|
||||
# the keys in self.funcs determine the name of the method as seen over xmlrpc
|
||||
|
|
@ -140,7 +141,7 @@ class HandlerRegistry(object):
|
|||
args = []
|
||||
argdesc = []
|
||||
for pname, param in sig.parameters.items():
|
||||
if param.default != inspect._empty:
|
||||
if param.default != param.empty:
|
||||
args.append([pname, param.default])
|
||||
else:
|
||||
args.append(pname)
|
||||
|
|
|
|||
92
tests/test_hub/test_kojixmlrpc.py
Normal file
92
tests/test_hub/test_kojixmlrpc.py
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
import unittest
|
||||
|
||||
import kojixmlrpc
|
||||
|
||||
|
||||
class TestHandler(unittest.TestCase):
|
||||
def test_list_api(self):
|
||||
basic_api = [
|
||||
{
|
||||
'name': '_listapi',
|
||||
'doc': 'List available API calls',
|
||||
'argspec': ([], None, None, None, [], None, {}),
|
||||
'argdesc': '()',
|
||||
'args': []
|
||||
},
|
||||
{
|
||||
'name': 'system.listMethods',
|
||||
'doc': None,
|
||||
'argspec': ([], None, None, None, [], None, {}),
|
||||
'argdesc': '()',
|
||||
'args': []
|
||||
},
|
||||
{
|
||||
'name': 'system.methodSignature',
|
||||
'doc': None,
|
||||
'argspec': (['method'], None, None, None, [], None, {}),
|
||||
'argdesc': '(method)',
|
||||
'args': ['method']},
|
||||
{
|
||||
'name': 'system.methodHelp',
|
||||
'doc': None,
|
||||
'argspec': (['method'], None, None, None, [], None, {}),
|
||||
'argdesc': '(method)', 'args': ['method']
|
||||
}
|
||||
]
|
||||
h = kojixmlrpc.HandlerRegistry()
|
||||
result = h.list_api()
|
||||
self.assertEqual(result, basic_api)
|
||||
|
||||
def test_list_methods(self):
|
||||
basic_methods = {
|
||||
'_listapi',
|
||||
'system.methodSignature',
|
||||
'system.listMethods',
|
||||
'system.methodHelp',
|
||||
}
|
||||
h = kojixmlrpc.HandlerRegistry()
|
||||
result = h.system_listMethods()
|
||||
self.assertEqual(set(result), basic_methods)
|
||||
|
||||
def test_methodSignature(self):
|
||||
h = kojixmlrpc.HandlerRegistry()
|
||||
result = h.system_methodSignature('any method')
|
||||
self.assertEqual(result, 'signatures not supported')
|
||||
|
||||
def test_methodHelp(self):
|
||||
help = '_listapi()\ndescription: List available API calls'
|
||||
h = kojixmlrpc.HandlerRegistry()
|
||||
result = h.system_methodHelp('_listapi')
|
||||
self.assertEqual(result, help)
|
||||
|
||||
def _random_method(self, par1, par2, par3=None, par4='text'):
|
||||
"""Random method docstring"""
|
||||
pass
|
||||
|
||||
def test_registered_func(self):
|
||||
h = kojixmlrpc.HandlerRegistry()
|
||||
h.register_function(self._random_method, name='endpoint')
|
||||
|
||||
result = h.system_listMethods()
|
||||
self.assertIn('endpoint', set(result))
|
||||
|
||||
result = h.list_api()
|
||||
methods = {x['name']: x for x in result}
|
||||
self.assertIn('endpoint', methods.keys())
|
||||
|
||||
api = methods['endpoint']
|
||||
self.assertEqual(api, {
|
||||
'name': 'endpoint',
|
||||
'doc': 'Random method docstring',
|
||||
'args': ['par1', 'par2', ['par3', None], ['par4', 'text']],
|
||||
'argdesc': "(par1, par2, par3=None, par4='text')",
|
||||
'argspec': (
|
||||
['par1', 'par2', 'par3', 'par4'],
|
||||
None, None, (None, 'text'), [], None, {}
|
||||
),
|
||||
})
|
||||
|
||||
result = h.system_methodHelp('endpoint')
|
||||
help = "endpoint(par1, par2, par3=None, par4='text')\ndescription: Random method docstring"
|
||||
self.assertEqual(result, help)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue