mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
123: API.finalize() now raises AssetionError if called more than once; added corresponding unit tests
This commit is contained in:
parent
64054a673c
commit
7db3aae1b2
@ -480,6 +480,8 @@ class Registrar(ReadOnly):
|
||||
|
||||
|
||||
class API(ReadOnly):
|
||||
__finalized = False
|
||||
|
||||
def __init__(self, *allowed):
|
||||
self.__keys = tuple(b.__name__ for b in allowed)
|
||||
self.register = Registrar(*allowed)
|
||||
@ -489,6 +491,7 @@ class API(ReadOnly):
|
||||
"""
|
||||
Finalize the registration, instantiate the plugins.
|
||||
"""
|
||||
assert not self.__finalized, 'finalize() can only be called once'
|
||||
d = {}
|
||||
def plugin_iter(base, classes):
|
||||
for cls in classes:
|
||||
@ -506,6 +509,7 @@ class API(ReadOnly):
|
||||
plugin.__lock__()
|
||||
assert plugin.__islocked__() is True
|
||||
assert plugin.api is self
|
||||
object.__setattr__(self, '_API__finalized', True)
|
||||
|
||||
def __iter__(self):
|
||||
for key in self.__keys:
|
||||
|
@ -622,3 +622,6 @@ def test_API():
|
||||
assert proxy.name == plugin_name
|
||||
assert read_only(ns, plugin_name) is proxy
|
||||
assert read_only(proxy, 'method')(7) == 7 + b
|
||||
|
||||
# Test that calling finilize again raises AssertionError:
|
||||
raises(AssertionError, api.finalize)
|
||||
|
Loading…
Reference in New Issue
Block a user