diff options
-rw-r--r-- | ipalib/public.py | 11 | ||||
-rw-r--r-- | ipalib/tests/test_public.py | 19 |
2 files changed, 30 insertions, 0 deletions
diff --git a/ipalib/public.py b/ipalib/public.py index c64e29d5..045f1012 100644 --- a/ipalib/public.py +++ b/ipalib/public.py @@ -173,6 +173,7 @@ class Option(plugable.ReadOnly): class Command(plugable.Plugin): __public__ = frozenset(( 'get_default', + 'convert', 'normalize', 'validate', 'execute', @@ -196,6 +197,16 @@ class Command(plugable.Plugin): return self.__Option Option = property(__get_Option) + def __convert_iter(self, kw): + for (key, value) in kw.iteritems(): + if key in self.Option: + yield (key, self.Option[key].convert(value)) + else: + yield (key, value) + + def convert(self, **kw): + return dict(self.__convert_iter(kw)) + def __normalize_iter(self, kw): for (key, value) in kw.items(): if key in self.Option: diff --git a/ipalib/tests/test_public.py b/ipalib/tests/test_public.py index 012b6253..4df55d2f 100644 --- a/ipalib/tests/test_public.py +++ b/ipalib/tests/test_public.py @@ -385,6 +385,25 @@ class test_Command(ClassChecker): assert isinstance(option, public.Option) assert option.name == name + def test_convert(self): + """ + Tests the `public.Command.convert` method. + """ + assert 'convert' in self.cls.__public__ # Public + kw = dict( + option0='option0', + option1='option1', + whatever=False, + also=object, + ) + expected = dict(kw) + expected.update(dict(option0=u'option0', option1=u'option1')) + o = self.subcls() + for (key, value) in o.convert(**kw).iteritems(): + v = expected[key] + assert value == v + assert type(value) is type(v) + def test_normalize(self): """ Tests the `public.Command.normalize` method. |