summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-08-09 01:46:12 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-08-09 01:46:12 +0000
commit3495c67d57868a02bafe6f1935d4846cd5615bf5 (patch)
tree389815c4ddaec1777ddb789751e1b83a595b1324 /ipalib
parentcc5b0174949a4769876a892b210a9faa9683d81e (diff)
downloadfreeipa.git-3495c67d57868a02bafe6f1935d4846cd5615bf5.tar.gz
freeipa.git-3495c67d57868a02bafe6f1935d4846cd5615bf5.tar.xz
freeipa.git-3495c67d57868a02bafe6f1935d4846cd5615bf5.zip
94: Renamed Proxy._clone() method to Proxy.__clone__(); updated unit tests
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/plugable.py10
-rw-r--r--ipalib/public.py2
-rw-r--r--ipalib/tests/test_plugable.py33
3 files changed, 29 insertions, 16 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 1e1f4a90..c5ec08ec 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -139,6 +139,14 @@ class Proxy(ReadOnly):
def implements(self, arg):
return self.__base.implements(arg)
+ def __clone__(self, name_attr):
+ """
+ Returns a Proxy instance identical to this one except the proxy name
+ might be derived from a different attribute on the target. The same
+ base and target will be used.
+ """
+ return self.__class__(self.__base, self.__target, name_attr)
+
def __iter__(self):
"""
Iterates (in ascending order) though the attribute names this proxy is
@@ -168,8 +176,6 @@ class Proxy(ReadOnly):
def __call__(self, *args, **kw):
return self['__call__'](*args, **kw)
- def _clone(self, name_attr):
- return self.__class__(self.__base, self.__target, name_attr)
def __repr__(self):
return '%s(%s, %r, %r)' % (
diff --git a/ipalib/public.py b/ipalib/public.py
index 7bce4992..21403169 100644
--- a/ipalib/public.py
+++ b/ipalib/public.py
@@ -226,7 +226,7 @@ class obj(plugable.Plugin):
def __filter(self, name):
for i in getattr(self.api, name):
if i.obj_name == self.name:
- yield i._clone('attr_name')
+ yield i.__clone__('attr_name')
class attr(plugable.Plugin):
diff --git a/ipalib/tests/test_plugable.py b/ipalib/tests/test_plugable.py
index faf2fd92..605debe5 100644
--- a/ipalib/tests/test_plugable.py
+++ b/ipalib/tests/test_plugable.py
@@ -174,12 +174,12 @@ class test_ProxyTarget(ClassChecker):
class test_Proxy(ClassChecker):
"""
- Test the `Proxy` class.
+ Tests the `Proxy` class.
"""
_cls = plugable.Proxy
def test_class(self):
- assert self.cls.__bases__ == (plugable.ReadOnly,)
+ assert self.cls.__bases__ == (plugable.ReadOnly,)
def test_proxy(self):
# Setup:
@@ -242,19 +242,9 @@ class test_Proxy(ClassChecker):
p = self.cls(base, i, 'attr_name')
assert read_only(p, 'name') == 'add'
- # Test _clone():
- i = plugin()
- p = self.cls(base, i)
- assert read_only(p, 'name') == 'user_add'
- c = p._clone('attr_name')
- assert isinstance(c, self.cls)
- assert read_only(c, 'name') == 'add'
- assert c is not p
- assert c('whoever') == p('whoever')
-
def test_implements(self):
"""
- Test the `implements` method.
+ Tests the `implements` method.
"""
class base(object):
__public__ = frozenset()
@@ -276,6 +266,23 @@ class test_Proxy(ClassChecker):
p = self.cls(base, o)
assert p.implements(3) == 10
+ def test_clone(self):
+ """
+ Tests the `__clone__` method.
+ """
+ class base(object):
+ __public__ = frozenset()
+ class sub(base):
+ name = 'some_name'
+ label = 'another_name'
+
+ p = self.cls(base, sub())
+ assert read_only(p, 'name') == 'some_name'
+ c = p.__clone__('label')
+ assert isinstance(c, self.cls)
+ assert c is not p
+ assert read_only(c, 'name') == 'another_name'
+
def test_Plugin():
cls = plugable.Plugin