diff options
-rw-r--r-- | ipalib/frontend.py | 8 | ||||
-rw-r--r-- | ipalib/ipa_types.py | 7 | ||||
-rw-r--r-- | tests/test_ipa_server/test_rpc.py | 27 |
3 files changed, 37 insertions, 5 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py index 6dcbea694..e4dd7637a 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -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). diff --git a/ipalib/ipa_types.py b/ipalib/ipa_types.py index 2da8e0be8..583cceed8 100644 --- a/ipalib/ipa_types.py +++ b/ipalib/ipa_types.py @@ -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' diff --git a/tests/test_ipa_server/test_rpc.py b/tests/test_ipa_server/test_rpc.py index 6c46b130a..f73f6cd0d 100644 --- a/tests/test_ipa_server/test_rpc.py +++ b/tests/test_ipa_server/test_rpc.py @@ -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) |