server/test/unittest_hook.py
changeset 4834 b718626a0e60
parent 4766 162b2b127b15
child 4835 13b0b96d7982
equal deleted inserted replaced
4833:41a78fb4107c 4834:b718626a0e60
   106         ex = self.assertRaises(Exception, self.o.register, _Hook)
   106         ex = self.assertRaises(Exception, self.o.register, _Hook)
   107         self.assertEquals(str(ex), 'bad event b on unittest_hook._Hook')
   107         self.assertEquals(str(ex), 'bad event b on unittest_hook._Hook')
   108 
   108 
   109     def test_call_hook(self):
   109     def test_call_hook(self):
   110         self.o.register(AddAnyHook)
   110         self.o.register(AddAnyHook)
   111         cw = mock_object(vreg=self.vreg)
   111         dis = set()
   112         self.assertRaises(HookCalled, self.o.call_hooks, 'before_add_entity', cw)
   112         cw = mock_object(vreg=self.vreg,
       
   113                          is_hook_activated=lambda x, cls: cls.category not in dis)
       
   114         self.assertRaises(HookCalled,
       
   115                           self.o.call_hooks, 'before_add_entity', cw)
   113         self.o.call_hooks('before_delete_entity', cw) # nothing to call
   116         self.o.call_hooks('before_delete_entity', cw) # nothing to call
   114         config.disabled_hooks_categories.add('cat1')
   117         dis.add('cat1')
   115         self.o.call_hooks('before_add_entity', cw) # disabled hooks category, not called
   118         self.o.call_hooks('before_add_entity', cw) # disabled hooks category, not called
   116         config.disabled_hooks_categories.remove('cat1')
   119         dis.remove('cat1')
   117         self.assertRaises(HookCalled, self.o.call_hooks, 'before_add_entity', cw)
   120         self.assertRaises(HookCalled,
       
   121                           self.o.call_hooks, 'before_add_entity', cw)
   118         self.o.unregister(AddAnyHook)
   122         self.o.unregister(AddAnyHook)
   119         self.o.call_hooks('before_add_entity', cw) # nothing to call
   123         self.o.call_hooks('before_add_entity', cw) # nothing to call
   120 
   124 
   121 
   125 
   122 class SystemHooksTC(CubicWebTC):
   126 class SystemHooksTC(CubicWebTC):