mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Continued work on xmlrpc.dispatch() unit tests; fixed bug in Command.args_to_kw()
This commit is contained in:
parent
7350ccbffe
commit
29d680b211
@ -577,12 +577,18 @@ class Command(plugable.Plugin):
|
||||
if len(values) > i:
|
||||
if arg.multivalue:
|
||||
multivalue = True
|
||||
yield (arg.name, values[i:])
|
||||
if len(values) == i + 1 and type(values[i]) in (list, tuple):
|
||||
yield (arg.name, values[i])
|
||||
else:
|
||||
yield (arg.name, values[i:])
|
||||
else:
|
||||
yield (arg.name, values[i])
|
||||
else:
|
||||
break
|
||||
|
||||
def args_options_2_params(self, args, options):
|
||||
pass
|
||||
|
||||
def params_2_args_options(self, params):
|
||||
"""
|
||||
Split params into (args, kw).
|
||||
|
@ -145,6 +145,13 @@ class Unicode(Type):
|
||||
self.regex = re.compile(pattern)
|
||||
super(Unicode, self).__init__(unicode)
|
||||
|
||||
def convert(self, value):
|
||||
assert type(value) not in (list, tuple)
|
||||
try:
|
||||
return self.type(value)
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
|
||||
def validate(self, value):
|
||||
if type(value) is not self.type:
|
||||
return 'Must be a string'
|
||||
|
@ -22,6 +22,7 @@ Test the `ipa_server.rpc` module.
|
||||
"""
|
||||
|
||||
from tests.util import create_test_api, raises, PluginTester
|
||||
from tests.data import unicode_str
|
||||
from ipalib import errors, Command
|
||||
from ipa_server import rpc
|
||||
|
||||
@ -51,7 +52,25 @@ class test_xmlrpc(PluginTester):
|
||||
"""
|
||||
Test the `ipa_server.rpc.xmlrpc.dispatch` method.
|
||||
"""
|
||||
(o, api, home) = self.instance('Backend')
|
||||
e = raises(errors.CommandError, o.dispatch, 'example', tuple())
|
||||
assert str(e) == "Unknown command 'example'"
|
||||
assert e.kw['name'] == 'example'
|
||||
(o, api, home) = self.instance('Backend', in_server=True)
|
||||
e = raises(errors.CommandError, o.dispatch, 'echo', tuple())
|
||||
assert str(e) == "Unknown command 'echo'"
|
||||
assert e.kw['name'] == 'echo'
|
||||
|
||||
class echo(Command):
|
||||
takes_args = ['arg1', 'arg2+']
|
||||
takes_options = ['option1?', 'option2?']
|
||||
def execute(self, *args, **options):
|
||||
assert type(args[1]) is tuple
|
||||
return args + (options,)
|
||||
|
||||
(o, api, home) = self.instance('Backend', echo, in_server=True)
|
||||
def call(params):
|
||||
response = o.dispatch('echo', params)
|
||||
assert type(response) is tuple and len(response) == 1
|
||||
return response[0]
|
||||
arg1 = unicode_str
|
||||
arg2 = (u'Hello', unicode_str, u'world!')
|
||||
options = dict(option1=u'How are you?', option2=unicode_str)
|
||||
assert call((arg1, arg2, options)) == (arg1, arg2, options)
|
||||
assert call((arg1,) + arg2 + (options,)) == (arg1, arg2, options)
|
||||
|
Loading…
Reference in New Issue
Block a user