summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ipalib/public.py5
-rw-r--r--ipalib/tests/test_public.py65
2 files changed, 69 insertions, 1 deletions
diff --git a/ipalib/public.py b/ipalib/public.py
index c0ca52559..78e2a7ead 100644
--- a/ipalib/public.py
+++ b/ipalib/public.py
@@ -289,7 +289,10 @@ class Attribute(plugable.Plugin):
__obj = None
def __init__(self):
- m = re.match('^([a-z][a-z0-9]+)_([a-z][a-z0-9]+)$', self.__class__.__name__)
+ m = re.match(
+ '^([a-z][a-z0-9]+)_([a-z][a-z0-9]+)$',
+ self.__class__.__name__
+ )
assert m
self.__obj_name = m.group(1)
self.__attr_name = m.group(2)
diff --git a/ipalib/tests/test_public.py b/ipalib/tests/test_public.py
index 95bb7b9c1..4fd24f8d7 100644
--- a/ipalib/tests/test_public.py
+++ b/ipalib/tests/test_public.py
@@ -333,10 +333,75 @@ class test_Object(ClassChecker):
assert type(self.cls.Property) is property
def test_init(self):
+ """
+ Tests the `public.Object.__init__` method.
+ """
o = self.cls()
assert read_only(o, 'Method') is None
assert read_only(o, 'Property') is None
+ def test_finalize(self):
+ """
+ Tests the `public.Object.finalize` method.
+ """
+ # Setup for test:
+ class DummyAttribute(object):
+ def __init__(self, obj_name, attr_name, name=None):
+ self.obj_name = obj_name
+ self.attr_name = attr_name
+ if name is None:
+ self.name = '%s_%s' % (obj_name, attr_name)
+ else:
+ self.name = name
+ def __clone__(self, attr_name):
+ return self.__class__(
+ self.obj_name,
+ self.attr_name,
+ getattr(self, attr_name)
+ )
+
+ def get_attributes(cnt, format):
+ for name in ['other', 'user', 'another']:
+ for i in xrange(cnt):
+ yield DummyAttribute(name, format % i)
+
+ cnt = 10
+ formats = dict(
+ Method='method_%d',
+ Property='property_%d',
+ )
+
+ class api(object):
+ Method = plugable.NameSpace(
+ get_attributes(cnt, formats['Method'])
+ )
+ Property = plugable.NameSpace(
+ get_attributes(cnt, formats['Property'])
+ )
+ assert len(api.Method) == cnt * 3
+ assert len(api.Property) == cnt * 3
+
+ class user(self.cls):
+ pass
+
+ # Actually perform test:
+ o = user()
+ o.finalize(api)
+ assert read_only(o, 'api') is api
+ for name in ['Method', 'Property']:
+ namespace = getattr(o, name)
+ assert isinstance(namespace, plugable.NameSpace)
+ assert len(namespace) == cnt
+ f = formats[name]
+ for i in xrange(cnt):
+ attr_name = f % i
+ attr = namespace[attr_name]
+ assert isinstance(attr, DummyAttribute)
+ assert attr is getattr(namespace, attr_name)
+ assert attr.obj_name == 'user'
+ assert attr.attr_name == attr_name
+ assert attr.name == attr_name
+
class test_Attribute(ClassChecker):
"""