mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-01-11 00:31:56 -06:00
7: Roughed out API.finalize(); added corresponding unit tests
This commit is contained in:
parent
91adc9c2d0
commit
26c9f4c881
@ -158,7 +158,7 @@ class NameSpace(object):
|
|||||||
|
|
||||||
|
|
||||||
class API(object):
|
class API(object):
|
||||||
__commands = None
|
__cmd = None
|
||||||
__objects = None
|
__objects = None
|
||||||
__locked = False
|
__locked = False
|
||||||
|
|
||||||
@ -171,9 +171,9 @@ class API(object):
|
|||||||
return self.__objects
|
return self.__objects
|
||||||
objects = property(__get_objects)
|
objects = property(__get_objects)
|
||||||
|
|
||||||
def __get_commands(self):
|
def __get_cmd(self):
|
||||||
return self.__commands
|
return self.__cmd
|
||||||
commands = property(__get_commands)
|
cmd = property(__get_cmd)
|
||||||
|
|
||||||
def __merge(self, base, cls, override):
|
def __merge(self, base, cls, override):
|
||||||
assert issubclass(base, Named)
|
assert issubclass(base, Named)
|
||||||
@ -184,17 +184,24 @@ class API(object):
|
|||||||
raise exceptions.DuplicateError(cls.__name__, id(cls))
|
raise exceptions.DuplicateError(cls.__name__, id(cls))
|
||||||
if cls.__name__ in self.__names and not override:
|
if cls.__name__ in self.__names and not override:
|
||||||
raise exceptions.OverrideError(cls.__name__)
|
raise exceptions.OverrideError(cls.__name__)
|
||||||
|
prefix = base.prefix
|
||||||
|
assert cls.__name__.startswith(prefix)
|
||||||
self.__classes.add(cls)
|
self.__classes.add(cls)
|
||||||
self.__names.add(cls.__name__)
|
self.__names.add(cls.__name__)
|
||||||
if base not in self.__stage:
|
if prefix not in self.__stage:
|
||||||
self.__stage[base.prefix] = {}
|
self.__stage[prefix] = {}
|
||||||
self.__stage[base.prefix][cls.__name__] = cls
|
self.__stage[prefix][cls.__name__] = cls
|
||||||
|
|
||||||
|
|
||||||
def register_command(self, cls, override=False):
|
def register_command(self, cls, override=False):
|
||||||
self.__merge(Command, cls, override)
|
self.__merge(Command, cls, override)
|
||||||
|
|
||||||
def finalize(self):
|
def finalize(self):
|
||||||
pass
|
for (prefix, d) in self.__stage.items():
|
||||||
#i = cls()
|
n = {}
|
||||||
#assert cls.__name__ == (base.prefix + '_' + i.name)
|
for cls in d.values():
|
||||||
|
i = cls()
|
||||||
|
assert cls.__name__ == (prefix + '_' + i.name)
|
||||||
|
n[i.name] = i
|
||||||
|
if prefix == 'cmd':
|
||||||
|
self.__cmd = NameSpace(n)
|
||||||
|
@ -267,8 +267,7 @@ class test_API:
|
|||||||
Test expectations of a fresh API instance.
|
Test expectations of a fresh API instance.
|
||||||
"""
|
"""
|
||||||
api = self.new()
|
api = self.new()
|
||||||
assert read_only(api, 'objects') is None
|
assert read_only(api, 'cmd') is None
|
||||||
assert read_only(api, 'objects') is None
|
|
||||||
|
|
||||||
def test_register_command(self):
|
def test_register_command(self):
|
||||||
api = self.new()
|
api = self.new()
|
||||||
@ -314,3 +313,28 @@ class test_API:
|
|||||||
|
|
||||||
# Check that override=True works:
|
# Check that override=True works:
|
||||||
api.register_command(cmd_my_command, override=True)
|
api.register_command(cmd_my_command, override=True)
|
||||||
|
|
||||||
|
def test_finalize(self):
|
||||||
|
api = self.new()
|
||||||
|
assert read_only(api, 'cmd') is None
|
||||||
|
|
||||||
|
class cmd_my_command(base.Command):
|
||||||
|
pass
|
||||||
|
class cmd_another_command(base.Command):
|
||||||
|
pass
|
||||||
|
|
||||||
|
api.register_command(cmd_my_command)
|
||||||
|
api.register_command(cmd_another_command)
|
||||||
|
|
||||||
|
api.finalize()
|
||||||
|
|
||||||
|
cmd = read_only(api, 'cmd')
|
||||||
|
assert isinstance(cmd, base.NameSpace)
|
||||||
|
assert api.cmd is cmd
|
||||||
|
|
||||||
|
assert len(cmd) == 2
|
||||||
|
assert list(cmd) == ['another_command', 'my_command']
|
||||||
|
assert isinstance(cmd.my_command, cmd_my_command)
|
||||||
|
assert cmd.my_command is cmd['my_command']
|
||||||
|
assert isinstance(cmd.another_command, cmd_another_command)
|
||||||
|
assert cmd.another_command is cmd['another_command']
|
||||||
|
Loading…
Reference in New Issue
Block a user