diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-09-25 00:42:38 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-09-25 00:42:38 +0000 |
commit | 4747563a802a08863d2195222b2f428e52af8502 (patch) | |
tree | b2e0ed40a5b62fe1a09a4d5b36fa8bc76d0687b0 /ipalib | |
parent | 79b33ad3663b91ad7816cf55737faa28603fca70 (diff) | |
download | freeipa-4747563a802a08863d2195222b2f428e52af8502.tar.gz freeipa-4747563a802a08863d2195222b2f428e52af8502.tar.xz freeipa-4747563a802a08863d2195222b2f428e52af8502.zip |
356: Modified Method.get_options() to now pull from self.obj.params(); updated unit tests for Method.get_options()
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/frontend.py | 21 | ||||
-rw-r--r-- | ipalib/plugins/example.py | 61 | ||||
-rw-r--r-- | ipalib/tests/test_frontend.py | 20 |
3 files changed, 47 insertions, 55 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py index 6aa21eb80..9f4f52958 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -541,8 +541,13 @@ class Object(plugable.Plugin): def __create_params(self): props = self.properties.__todict__() for spec in self.takes_params: - if type(spec) is str and spec.rstrip('?*+') in props: - yield props.pop(spec.rstrip('?*+')).param + if type(spec) is str: + key = spec.rstrip('?*+') + else: + assert type(spec) is Param + key = spec.name + if key in props: + yield props.pop(key).param else: yield create_param(spec) def get_key(p): @@ -602,15 +607,9 @@ class Method(Attribute, Command): def get_options(self): for option in self.takes_options: yield option - if self.obj is not None and self.obj.properties is not None: - def get_key(p): - if p.param.required: - if p.param.default_from is None: - return 0 - return 1 - return 2 - for prop in sorted(self.obj.properties(), key=get_key): - yield prop.param + if self.obj is not None and self.obj.params is not None: + for param in self.obj.params(): + yield param class Property(Attribute): diff --git a/ipalib/plugins/example.py b/ipalib/plugins/example.py index 24bf5b8fe..143f9f292 100644 --- a/ipalib/plugins/example.py +++ b/ipalib/plugins/example.py @@ -23,6 +23,7 @@ Some example plugins. from ipalib import frontend +from ipalib.frontend import Param from ipalib import api @@ -55,33 +56,33 @@ api.register(user_find) # Register some properties for the 'user' object: -class user_givenname(frontend.Property): - 'User first name' - required = True -api.register(user_givenname) - -class user_sn(frontend.Property): - 'User last name' - required = True -api.register(user_sn) - -class user_login(frontend.Property): - 'User login' - required = True - default_from = frontend.DefaultFrom( - lambda first, last: (first[0] + last).lower(), - 'givenname', 'sn' - ) -api.register(user_login) - -class user_initials(frontend.Property): - 'User initials' - required = True - default_from = frontend.DefaultFrom( - lambda first, last: first[0] + last[0], - 'givenname', 'sn' - ) -api.register(user_initials) +#class user_givenname(frontend.Property): +# 'User first name' +# required = True +#api.register(user_givenname) + +#class user_sn(frontend.Property): +# 'User last name' +# required = True +#api.register(user_sn) + +#class user_login(frontend.Property): +# 'User login' +# required = True +# default_from = frontend.DefaultFrom( +# lambda first, last: (first[0] + last).lower(), +# 'givenname', 'sn' +# ) +#api.register(user_login) + +#class user_initials(frontend.Property): +# 'User initials' +# required = True +# default_from = frontend.DefaultFrom( +# lambda first, last: first[0] + last[0], +# 'givenname', 'sn' +# ) +#api.register(user_initials) # Register some methods for the 'group' object: @@ -132,4 +133,10 @@ api.register(service) class user(frontend.Object): 'User object' + takes_params = ( + 'givenname', + 'sn', + 'uid', + 'krbprincipalname', + ) api.register(user) diff --git a/ipalib/tests/test_frontend.py b/ipalib/tests/test_frontend.py index ec7cccd61..e78aeeb26 100644 --- a/ipalib/tests/test_frontend.py +++ b/ipalib/tests/test_frontend.py @@ -910,24 +910,10 @@ class test_Method(ClassChecker): assert self.cls.implements(frontend.Command) def get_subcls(self): - class example_prop0(frontend.Property): - 'Prop zero' - class example_prop1(frontend.Property): - 'Prop one' class example_obj(object): - __prop = None - def __get_prop(self): - if self.__prop is None: - self.__prop = plugable.NameSpace([ - plugable.PluginProxy( - frontend.Property, example_prop0(), 'attr_name' - ), - plugable.PluginProxy( - frontend.Property, example_prop1(), 'attr_name' - ), - ]) - return self.__prop - properties = property(__get_prop) + params = plugable.NameSpace( + frontend.create_param(n) for n in ('prop0', 'prop1') + ) type_ = ipa_types.Unicode() class noun_verb(self.cls): takes_options= ( |