server/test/unittest_hooksmanager.py
changeset 2773 b2530e3e0afb
parent 1977 606923dff11b
child 2809 04fa75d43af4
equal deleted inserted replaced
2767:58c519e5a31f 2773:b2530e3e0afb
     4 
     4 
     5 from logilab.common.testlib import TestCase, unittest_main
     5 from logilab.common.testlib import TestCase, unittest_main
     6 
     6 
     7 from cubicweb.server.hooksmanager import HooksManager, Hook
     7 from cubicweb.server.hooksmanager import HooksManager, Hook
     8 from cubicweb.devtools import TestServerConfiguration
     8 from cubicweb.devtools import TestServerConfiguration
     9 from cubicweb.devtools.apptest import RepositoryBasedTC
     9 from cubicweb.devtools.testlib import CubicWebTC
    10 
    10 
    11 class HookCalled(Exception): pass
    11 class HookCalled(Exception): pass
    12 
    12 
    13 config = TestServerConfiguration('data')
    13 config = TestServerConfiguration('data')
    14 config.bootstrap_cubes()
    14 config.bootstrap_cubes()
   142 
   142 
   143     def _after_relation_hook(self, pool, subject, r_type, object):
   143     def _after_relation_hook(self, pool, subject, r_type, object):
   144         self.called.append((subject, r_type, object))
   144         self.called.append((subject, r_type, object))
   145 
   145 
   146 
   146 
   147 class SystemHooksTC(RepositoryBasedTC):
   147 class SystemHooksTC(CubicWebTC):
   148 
   148 
   149     def test_startup_shutdown(self):
   149     def test_startup_shutdown(self):
   150         import hooks # cubicweb/server/test/data/hooks.py
   150         import hooks # cubicweb/server/test/data/hooks.py
   151         self.assertEquals(hooks.CALLED_EVENTS['server_startup'], True)
   151         self.assertEquals(hooks.CALLED_EVENTS['server_startup'], True)
   152         # don't actually call repository.shutdown !
   152         # don't actually call repository.shutdown !
   166 class MyHook(Hook):
   166 class MyHook(Hook):
   167     schema = schema # set for actual hooks at registration time
   167     schema = schema # set for actual hooks at registration time
   168     events = ('whatever', 'another')
   168     events = ('whatever', 'another')
   169     accepts = ('Societe', 'Division')
   169     accepts = ('Societe', 'Division')
   170 
   170 
   171 class HookTC(RepositoryBasedTC):
   171 class HookTC(CubicWebTC):
   172     def test_inheritance(self):
   172     def test_inheritance(self):
   173         self.assertEquals(list(MyHook.register_to()),
   173         self.assertEquals(list(MyHook.register_to()),
   174                           zip(repeat('whatever'), ('Societe', 'Division', 'SubDivision'))
   174                           zip(repeat('whatever'), ('Societe', 'Division', 'SubDivision'))
   175                           + zip(repeat('another'), ('Societe', 'Division', 'SubDivision')))
   175                           + zip(repeat('another'), ('Societe', 'Division', 'SubDivision')))
   176 
   176