def test_hook_disabled(self): hp = hook_point('foo') result_func = hp(inc) # We should now have a config option we can set to disabled self.config(disabled=True, group='hook_point:foo') # The result is 2 so no extra add hook was applied self.assertEqual(result_func(1), 2)
def test_hook_enabled_when_config_key_exists(self): hp = hook_point('foo') hp(inc) # Add our config self.config(bar='from config', group='hook_point:foo') # reapply our hook result_func = hp(inc) # The result is 3 so the extra add hook was applied self.assertEqual(result_func(1), 3)
def test_hook_init(self): hp = hook_point('foo') # Make sure we set up our object when the hook point is # applied to a function / method. hp.find_name = Mock(return_value='foo.bar.baz') hp.hook_manager = Mock(return_value=get_hook_manager()) hp.find_config = Mock(return_value={'enabled': True}) hp.update_config_opts = Mock() hp(inc) self.assertEqual(hp.name, 'foo.bar.baz') self.assertEqual(hp.group, 'hook_point:foo.bar.baz') hp.update_config_opts.assert_called_with(hp.group, hp.hooks)
def test_apply_N_hooks(self): hp = hook_point('foo') hp.hook_manager = Mock(return_value=get_hook_manager(AddHook, AddHook)) assert hp(inc)(1) == 4
def test_hook_is_decorator(self): hp = hook_point('foo') hp.hook_manager = Mock(return_value=get_hook_manager()) assert hp(inc)(1) == 3
def test_no_hookpoint_is_noop(self): def doit(self, name): return 'done: %s' % name self.assertEqual(doit, hook_point('foo')(doit))
def test_hook_adds_config_opts(self): hp = hook_point('foo') hp.hook_manager = Mock(return_value=get_hook_manager()) hp(inc) assert hp.group in self.CONF.keys()
def test_hook_adds_config_opts(self): hp = hook_point('foo') hp.hook_manager = Mock(return_value=get_hook_manager()) hp(inc) assert hp.group in list(six.iterkeys(self.CONF))