summaryrefslogtreecommitdiffstats
path: root/ipalib/tests/test_plugable.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-08-08 22:13:49 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-08-08 22:13:49 +0000
commit6f144fbaf062d9644af06fdd11020e3d5d349639 (patch)
treea1fc5133225dd4cb6983d04a8250be3a5aced250 /ipalib/tests/test_plugable.py
parent1744723d11b2fbc93f43699f79df40d5d0b9305d (diff)
downloadfreeipa.git-6f144fbaf062d9644af06fdd11020e3d5d349639.tar.gz
freeipa.git-6f144fbaf062d9644af06fdd11020e3d5d349639.tar.xz
freeipa.git-6f144fbaf062d9644af06fdd11020e3d5d349639.zip
89: Moved ClassChecker from test_public.py into tstutil.py; improved unit tests for plugable.ReadOnly
Diffstat (limited to 'ipalib/tests/test_plugable.py')
-rw-r--r--ipalib/tests/test_plugable.py67
1 files changed, 50 insertions, 17 deletions
diff --git a/ipalib/tests/test_plugable.py b/ipalib/tests/test_plugable.py
index 91b9f6e8..1f42aa85 100644
--- a/ipalib/tests/test_plugable.py
+++ b/ipalib/tests/test_plugable.py
@@ -22,9 +22,58 @@ Unit tests for `ipalib.plugable` module.
"""
from tstutil import raises, getitem, no_set, no_del, read_only
+from tstutil import ClassChecker
from ipalib import plugable, errors
+class test_ReadOnly(ClassChecker):
+ """
+ Test the plugable.ReadOnly class
+ """
+ _cls = plugable.ReadOnly
+
+ def test_class(self):
+ assert self.cls.__bases__ == (object,)
+
+ def test_when_unlocked(self):
+ """
+ Test that default state is unlocked, that setting and deleting
+ attributes works.
+ """
+ o = self.cls()
+
+ # Setting:
+ o.hello = 'world'
+ assert o.hello == 'world'
+
+ # Deleting:
+ del o.hello
+ assert not hasattr(o, 'hello')
+
+ def test_when_locked(self):
+ """
+ Test that after __lock__() has been called, setting or deleting an
+ attribute raises AttributeError.
+ """
+ obj = self.cls()
+ obj.__lock__()
+ names = ['not_an_attribute', 'an_attribute']
+ for name in names:
+ no_set(obj, name)
+ no_del(obj, name)
+
+ class some_ro_class(self.cls):
+ def __init__(self):
+ self.an_attribute = 'Hello world!'
+ self.__lock__()
+ obj = some_ro_class()
+ for name in names:
+ no_set(obj, name)
+ no_del(obj, name)
+ assert read_only(obj, 'an_attribute') == 'Hello world!'
+
+
+
def test_valid_identifier():
f = plugable.check_identifier
okay = [
@@ -125,23 +174,7 @@ def test_Plugin():
raises(AssertionError, p.finalize, api)
-def test_ReadOnly():
- obj = plugable.ReadOnly()
- obj.__lock__()
- names = ['not_an_attribute', 'an_attribute']
- for name in names:
- no_set(obj, name)
- no_del(obj, name)
-
- class some_ro_class(plugable.ReadOnly):
- def __init__(self):
- self.an_attribute = 'Hello world!'
- self.__lock__()
- obj = some_ro_class()
- for name in names:
- no_set(obj, name)
- no_del(obj, name)
- assert read_only(obj, 'an_attribute') == 'Hello world!'
+
def test_Proxy():