From 49c1c29df199dfce5d426ebe15003ab3f8431e71 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Mon, 22 Sep 2008 00:37:01 +0000 Subject: [PATCH] 313: Added Object.params instance attribute --- ipalib/public.py | 12 +++++++++++- ipalib/tests/test_public.py | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/ipalib/public.py b/ipalib/public.py index af964ca57..21c6822c4 100644 --- a/ipalib/public.py +++ b/ipalib/public.py @@ -394,9 +394,20 @@ class Object(plugable.Plugin): __public__ = frozenset(( 'Method', 'Property', + 'params' )) __Method = None __Property = None + takes_params = tuple() + + def __init__(self): + self.params = plugable.NameSpace( + (create_param(p) for p in self.takes_params), sort=False + ) + + def __create_params(self): + for param in self.takes_params: + yield create_param(param) def __get_Method(self): return self.__Method @@ -411,7 +422,6 @@ class Object(plugable.Plugin): self.__Method = self.__create_namespace('Method') self.__Property = self.__create_namespace('Property') - def __create_namespace(self, name): return plugable.NameSpace(self.__filter_members(name)) diff --git a/ipalib/tests/test_public.py b/ipalib/tests/test_public.py index e97bfbc11..a79569071 100644 --- a/ipalib/tests/test_public.py +++ b/ipalib/tests/test_public.py @@ -702,6 +702,24 @@ class test_Object(ClassChecker): assert attr.attr_name == attr_name assert attr.name == attr_name + def test_params(self): + """ + Test the ``public.Object.params`` instance attribute. + """ + ns = self.cls().params + assert type(ns) is plugable.NameSpace + assert len(ns) == 0 + class example(self.cls): + takes_params = ('banana', 'apple') + ns = example().params + assert type(ns) is plugable.NameSpace + assert len(ns) == 2, repr(ns) + assert list(ns) == ['banana', 'apple'] + for p in ns(): + assert type(p) is public.Param + assert p.required is True + assert p.multivalue is False + class test_Attribute(ClassChecker): """