mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
187: Renamed plubic.obj to Object; reworked plublic.Object unit tests to use ClassChecker
This commit is contained in:
@@ -126,14 +126,14 @@ api.register(service_find)
|
|||||||
|
|
||||||
# And to emphasis that the registration order doesn't matter,
|
# And to emphasis that the registration order doesn't matter,
|
||||||
# we'll register the objects last:
|
# we'll register the objects last:
|
||||||
class group(public.obj):
|
class group(public.Object):
|
||||||
'Group object'
|
'Group object'
|
||||||
api.register(group)
|
api.register(group)
|
||||||
|
|
||||||
class service(public.obj):
|
class service(public.Object):
|
||||||
'Service object'
|
'Service object'
|
||||||
api.register(service)
|
api.register(service)
|
||||||
|
|
||||||
class user(public.obj):
|
class user(public.Object):
|
||||||
'User object'
|
'User object'
|
||||||
api.register(user)
|
api.register(user)
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ class Command(plugable.Plugin):
|
|||||||
self.execute(**kw)
|
self.execute(**kw)
|
||||||
|
|
||||||
|
|
||||||
class obj(plugable.Plugin):
|
class Object(plugable.Plugin):
|
||||||
__public__ = frozenset((
|
__public__ = frozenset((
|
||||||
'Method',
|
'Method',
|
||||||
'Property',
|
'Property',
|
||||||
@@ -266,17 +266,17 @@ class obj(plugable.Plugin):
|
|||||||
Property = property(__get_Property)
|
Property = property(__get_Property)
|
||||||
|
|
||||||
def finalize(self, api):
|
def finalize(self, api):
|
||||||
super(obj, self).finalize(api)
|
super(Object, self).finalize(api)
|
||||||
self.__Method = self.__create_ns('Method')
|
self.__Method = self.__create_namespace('Method')
|
||||||
self.__Property = self.__create_ns('Property')
|
self.__Property = self.__create_namespace('Property')
|
||||||
|
|
||||||
def __create_ns(self, name):
|
def __create_namespace(self, name):
|
||||||
return plugable.NameSpace(self.__filter(name))
|
return plugable.NameSpace(self.__filter_members(name))
|
||||||
|
|
||||||
def __filter(self, name):
|
def __filter_members(self, name):
|
||||||
namespace = getattr(self.api, name)
|
namespace = getattr(self.api, name)
|
||||||
assert type(namespace) is plugable.NameSpace
|
assert type(namespace) is plugable.NameSpace
|
||||||
for proxy in namespace(): # Like dict.itervalues()
|
for proxy in namespace(): # Equivalent to dict.itervalues()
|
||||||
if proxy.obj_name == self.name:
|
if proxy.obj_name == self.name:
|
||||||
yield proxy.__clone__('attr_name')
|
yield proxy.__clone__('attr_name')
|
||||||
|
|
||||||
@@ -312,7 +312,7 @@ class Attribute(plugable.Plugin):
|
|||||||
|
|
||||||
def finalize(self, api):
|
def finalize(self, api):
|
||||||
super(Attribute, self).finalize(api)
|
super(Attribute, self).finalize(api)
|
||||||
self.__obj = api.obj[self.obj_name]
|
self.__obj = api.Object[self.obj_name]
|
||||||
|
|
||||||
|
|
||||||
class Method(Attribute, Command):
|
class Method(Attribute, Command):
|
||||||
@@ -335,4 +335,4 @@ class Property(Attribute, option):
|
|||||||
|
|
||||||
class PublicAPI(plugable.API):
|
class PublicAPI(plugable.API):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(PublicAPI, self).__init__(Command, obj, Method, Property)
|
super(PublicAPI, self).__init__(Command, Object, Method, Property)
|
||||||
|
|||||||
@@ -321,10 +321,21 @@ class test_cmd(ClassChecker):
|
|||||||
assert 'execute' in self.cls.__public__ # Public
|
assert 'execute' in self.cls.__public__ # Public
|
||||||
|
|
||||||
|
|
||||||
def test_obj():
|
class test_Object(ClassChecker):
|
||||||
cls = public.obj
|
"""
|
||||||
assert issubclass(cls, plugable.Plugin)
|
Tests the `public.Object` class.
|
||||||
|
"""
|
||||||
|
_cls = public.Object
|
||||||
|
|
||||||
|
def test_class(self):
|
||||||
|
assert self.cls.__bases__ == (plugable.Plugin,)
|
||||||
|
assert type(self.cls.Method) is property
|
||||||
|
assert type(self.cls.Property) is property
|
||||||
|
|
||||||
|
def test_init(self):
|
||||||
|
o = self.cls()
|
||||||
|
assert read_only(o, 'Method') is None
|
||||||
|
assert read_only(o, 'Property') is None
|
||||||
|
|
||||||
|
|
||||||
class test_Attribute(ClassChecker):
|
class test_Attribute(ClassChecker):
|
||||||
@@ -350,7 +361,7 @@ class test_Attribute(ClassChecker):
|
|||||||
def test_finalize(self):
|
def test_finalize(self):
|
||||||
user_obj = 'The user public.Object instance'
|
user_obj = 'The user public.Object instance'
|
||||||
class api(object):
|
class api(object):
|
||||||
obj = dict(user=user_obj)
|
Object = dict(user=user_obj)
|
||||||
class user_add(self.cls):
|
class user_add(self.cls):
|
||||||
pass
|
pass
|
||||||
o = user_add()
|
o = user_add()
|
||||||
|
|||||||
Reference in New Issue
Block a user