diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-11 17:37:33 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-11 17:37:33 +0000 |
commit | fd6c215d596912493fa582079a7ec6de45466446 (patch) | |
tree | aefd4627987f8ff512a84b65c7b4457d5dfce9d5 | |
parent | 8aee8e060c8d155ea0798cb677e784a0a72fa7ab (diff) | |
download | freeipa.git-fd6c215d596912493fa582079a7ec6de45466446.tar.gz freeipa.git-fd6c215d596912493fa582079a7ec6de45466446.tar.xz freeipa.git-fd6c215d596912493fa582079a7ec6de45466446.zip |
107: Some cleanup in cmd; added unit tests for cmd.default() method
-rw-r--r-- | ipalib/public.py | 21 | ||||
-rw-r--r-- | ipalib/tests/test_public.py | 29 |
2 files changed, 40 insertions, 10 deletions
diff --git a/ipalib/public.py b/ipalib/public.py index 10f91693..17d00f04 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 7e98b735..8f0ac963 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 |