diff --git a/ipalib/public.py b/ipalib/public.py index 10f916937..17d00f048 100644 --- a/ipalib/public.py +++ b/ipalib/public.py @@ -130,7 +130,8 @@ class option(plugable.Plugin): class cmd(plugable.Plugin): __public__ = frozenset(( 'normalize', - 'autofill', + 'default', + 'validate', '__call__', 'get_doc', 'options', @@ -182,11 +183,6 @@ class cmd(plugable.Plugin): def normalize(self, **kw): return dict(self.normalize_iter(kw)) - def validate(self, **kw): - for (key, value) in kw.items(): - if key in self.options: - self.options.validate(value) - def default(self, **kw): d = {} for opt in self.options: @@ -198,11 +194,16 @@ class cmd(plugable.Plugin): kw.update(d) return kw + def validate(self, **kw): + for (key, value) in kw.items(): + if key in self.options: + self.options.validate(value) + def __call__(self, **kw): - (args, kw) = self.normalize(*args, **kw) - (args, kw) = self.autofill(*args, **kw) - self.validate(*args, **kw) - self.execute(*args, **kw) + kw = self.normalize(**kw) + kw = self.default(**kw) + self.validate(**kw) + self.execute(**kw) diff --git a/ipalib/tests/test_public.py b/ipalib/tests/test_public.py index 7e98b7355..8f0ac9633 100644 --- a/ipalib/tests/test_public.py +++ b/ipalib/tests/test_public.py @@ -167,6 +167,13 @@ class test_cmd(ClassChecker): class my_option(public.option): def normalize(self, value): return super(my_option, self).normalize(value).lower() + @public.rule + def my_rule(self, value): + if value != self.name: + return 'must equal %s' % name + def default(self, **kw): + return kw['default_from'] + class option0(my_option): pass class option1(my_option): @@ -221,6 +228,28 @@ class test_cmd(ClassChecker): sub = self.subcls() assert sub.normalize(**kw) == norm + def test_default(self): + """ + Tests the `default` method. + """ + assert 'default' in self.cls.__public__ # Public + no_fill = dict( + option0='value0', + option1='value1', + whatever='hello world', + ) + fill = dict( + default_from='the default', + ) + filled = dict( + option0='the default', + option1='the default', + default_from='the default', + ) + sub = self.subcls() + assert sub.default(**no_fill) == no_fill + assert sub.default(**fill) == filled + def test_obj(): cls = public.obj