diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-14 07:10:07 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-14 07:10:07 +0000 |
commit | 00f4272662e56a98fe498cc8f5761cc15bcd3825 (patch) | |
tree | 6cdb1bf0d782cd2fb70a281d5b96b0e6d76b0ba4 /ipalib/tests | |
parent | a59d6698d2a13792210bcaeac1ee79e255fd8f1c (diff) | |
download | freeipa-00f4272662e56a98fe498cc8f5761cc15bcd3825.tar.gz freeipa-00f4272662e56a98fe498cc8f5761cc15bcd3825.tar.xz freeipa-00f4272662e56a98fe498cc8f5761cc15bcd3825.zip |
154: Merged ProxyTarget functionality into Plugin to make things a bit clearer
Diffstat (limited to 'ipalib/tests')
-rw-r--r-- | ipalib/tests/test_plugable.py | 255 |
1 files changed, 123 insertions, 132 deletions
diff --git a/ipalib/tests/test_plugable.py b/ipalib/tests/test_plugable.py index ddb8fed07..aa449b718 100644 --- a/ipalib/tests/test_plugable.py +++ b/ipalib/tests/test_plugable.py @@ -86,138 +86,24 @@ class test_ReadOnly(ClassChecker): assert read_only(obj, 'an_attribute') == 'Hello world!' -class test_Proxy(ClassChecker): - """ - Tests the `Proxy` class. - """ - _cls = plugable.Proxy - - def test_class(self): - assert self.cls.__bases__ == (plugable.ReadOnly,) - - def test_proxy(self): - # Setup: - class base(object): - __public__ = frozenset(( - 'public_0', - 'public_1', - '__call__', - )) - - def public_0(self): - return 'public_0' - - def public_1(self): - return 'public_1' - - def __call__(self, caller): - return 'ya called it, %s.' % caller - - def private_0(self): - return 'private_0' - - def private_1(self): - return 'private_1' - - class plugin(base): - name = 'user_add' - attr_name = 'add' - doc = 'add a new user' - - # Test that TypeError is raised when base is not a class: - raises(TypeError, self.cls, base(), None) - - # Test that ValueError is raised when target is not instance of base: - raises(ValueError, self.cls, base, object()) - - # Test with correct arguments: - i = plugin() - p = self.cls(base, i) - assert read_only(p, 'name') is plugin.name - assert read_only(p, 'doc') == plugin.doc - assert list(p) == sorted(base.__public__) - - # Test normal methods: - for n in xrange(2): - pub = 'public_%d' % n - priv = 'private_%d' % n - assert getattr(i, pub)() == pub - assert getattr(p, pub)() == pub - assert hasattr(p, pub) - assert getattr(i, priv)() == priv - assert not hasattr(p, priv) - - # Test __call__: - value = 'ya called it, dude.' - assert i('dude') == value - assert p('dude') == value - assert callable(p) - - # Test name_attr='name' kw arg - i = plugin() - p = self.cls(base, i, 'attr_name') - assert read_only(p, 'name') == 'add' - - def test_implements(self): - """ - Tests the `implements` method. - """ - class base(object): - __public__ = frozenset() - name = 'base' - doc = 'doc' - @classmethod - def implements(cls, arg): - return arg + 7 - - class sub(base): - @classmethod - def implements(cls, arg): - """ - Defined to make sure base.implements() is called, not - target.implements() - """ - return arg - - o = sub() - 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' - doc = 'doc' - 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' - - -class test_ProxyTarget(ClassChecker): +class test_Plugin(ClassChecker): """ - Test the `ProxyTarget` class. + Tests the `Plugin` class. """ - _cls = plugable.ProxyTarget + _cls = plugable.Plugin def test_class(self): assert self.cls.__bases__ == (plugable.ReadOnly,) + assert self.cls.__public__ == frozenset() assert type(self.cls.name) is property - assert self.cls.implements(frozenset()) + assert type(self.cls.doc) is property + assert type(self.cls.api) is property def test_name(self): """ Tests the `name` property. """ - assert read_only(self.cls(), 'name') == 'ProxyTarget' + assert read_only(self.cls(), 'name') == 'Plugin' class some_subclass(self.cls): pass @@ -323,17 +209,6 @@ class test_ProxyTarget(ClassChecker): assert base.implemented_by(fail) is False assert base.implemented_by(fail()) is False - -class test_Plugin(ClassChecker): - """ - Tests the `Plugin` class. - """ - _cls = plugable.Plugin - - def test_class(self): - assert self.cls.__bases__ == (plugable.ProxyTarget,) - assert type(self.cls.api) is property - def test_finalize(self): """ Tests the `finalize` method. @@ -360,6 +235,122 @@ class test_Plugin(ClassChecker): raises(AssertionError, sub.finalize, api) +class test_Proxy(ClassChecker): + """ + Tests the `Proxy` class. + """ + _cls = plugable.Proxy + + def test_class(self): + assert self.cls.__bases__ == (plugable.ReadOnly,) + + def test_proxy(self): + # Setup: + class base(object): + __public__ = frozenset(( + 'public_0', + 'public_1', + '__call__', + )) + + def public_0(self): + return 'public_0' + + def public_1(self): + return 'public_1' + + def __call__(self, caller): + return 'ya called it, %s.' % caller + + def private_0(self): + return 'private_0' + + def private_1(self): + return 'private_1' + + class plugin(base): + name = 'user_add' + attr_name = 'add' + doc = 'add a new user' + + # Test that TypeError is raised when base is not a class: + raises(TypeError, self.cls, base(), None) + + # Test that ValueError is raised when target is not instance of base: + raises(ValueError, self.cls, base, object()) + + # Test with correct arguments: + i = plugin() + p = self.cls(base, i) + assert read_only(p, 'name') is plugin.name + assert read_only(p, 'doc') == plugin.doc + assert list(p) == sorted(base.__public__) + + # Test normal methods: + for n in xrange(2): + pub = 'public_%d' % n + priv = 'private_%d' % n + assert getattr(i, pub)() == pub + assert getattr(p, pub)() == pub + assert hasattr(p, pub) + assert getattr(i, priv)() == priv + assert not hasattr(p, priv) + + # Test __call__: + value = 'ya called it, dude.' + assert i('dude') == value + assert p('dude') == value + assert callable(p) + + # Test name_attr='name' kw arg + i = plugin() + p = self.cls(base, i, 'attr_name') + assert read_only(p, 'name') == 'add' + + def test_implements(self): + """ + Tests the `implements` method. + """ + class base(object): + __public__ = frozenset() + name = 'base' + doc = 'doc' + @classmethod + def implements(cls, arg): + return arg + 7 + + class sub(base): + @classmethod + def implements(cls, arg): + """ + Defined to make sure base.implements() is called, not + target.implements() + """ + return arg + + o = sub() + 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' + doc = 'doc' + 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_check_name(): """ Tests the `check_name` function. |