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): |