def test_register_hook_not_kolibri_plugin(): try: hooks.register_hook(Hook) pytest.fail( "Allowed a hook defined outside of a kolibri_plugin module to be registered" ) except RuntimeError: pass
def test_register_multiple_hook_single_hook(valid_single_hook): valid_single_hook = hooks.register_hook(valid_single_hook) valid_single_hook.add_hook_to_registries() class OtherSingleHook(SingleHookAbstract): pass OtherSingleHook.__module__ = "test.kolibri_plugin" try: OtherSingleHook = hooks.register_hook(OtherSingleHook) OtherSingleHook.add_hook_to_registries() pytest.fail( "Allowed a hook single instance hook to be registered more than once" ) except RuntimeError: pass
def test_registered_hooks(valid_hook): valid_hook = hooks.register_hook(valid_hook) valid_hook.add_hook_to_registries() hook = valid_hook() assert hook in HookAbstract.registered_hooks assert len(list(HookAbstract.registered_hooks)) == 1
def test_get_hook(valid_hook): valid_hook = hooks.register_hook(valid_hook) valid_hook.add_hook_to_registries() hook = valid_hook() assert HookAbstract.get_hook(hook.unique_id) is hook
def test_singleton_hook(valid_hook): valid_hook = hooks.register_hook(valid_hook) assert valid_hook() is valid_hook()
def test_register_hook_single_hook(valid_single_hook): hooks.register_hook(valid_single_hook)
def test_register_hook_kolibri_plugin(valid_hook): hooks.register_hook(valid_hook)
def setUp(self): super(KolibriTagNavigationTestCase, self).setUp() Hook.__module__ = "test.kolibri_plugin" self.test_hook = register_hook(Hook)()