482 class InlineRelHooksTC(CubicWebTC): |
482 class InlineRelHooksTC(CubicWebTC): |
483 """test relation hooks are called for inlined relations |
483 """test relation hooks are called for inlined relations |
484 """ |
484 """ |
485 def setUp(self): |
485 def setUp(self): |
486 CubicWebTC.setUp(self) |
486 CubicWebTC.setUp(self) |
487 self.hm = self.repo.hm |
|
488 CALLED[:] = () |
487 CALLED[:] = () |
489 |
488 |
490 def _after_relation_hook(self, pool, fromeid, rtype, toeid): |
489 def _after_relation_hook(self, pool, fromeid, rtype, toeid): |
491 self.called.append((fromeid, rtype, toeid)) |
490 self.called.append((fromeid, rtype, toeid)) |
492 |
491 |
498 events = ('before_add_relation', 'after_add_relation', |
497 events = ('before_add_relation', 'after_add_relation', |
499 'before_delete_relation', 'after_delete_relation') |
498 'before_delete_relation', 'after_delete_relation') |
500 def __call__(self): |
499 def __call__(self): |
501 CALLED.append((self.event, self.eidfrom, self.rtype, self.eidto)) |
500 CALLED.append((self.event, self.eidfrom, self.rtype, self.eidto)) |
502 |
501 |
503 self.hm.register(EcritParHook) |
502 self.vreg.register(EcritParHook) |
504 eidp = self.execute('INSERT Personne X: X nom "toto"')[0][0] |
503 eidp = self.execute('INSERT Personne X: X nom "toto"')[0][0] |
505 eidn = self.execute('INSERT Note X: X type "T"')[0][0] |
504 eidn = self.execute('INSERT Note X: X type "T"')[0][0] |
506 self.execute('SET N ecrit_par Y WHERE N type "T", Y nom "toto"') |
505 self.execute('SET N ecrit_par Y WHERE N type "T", Y nom "toto"') |
507 self.assertEquals(CALLED, [('before_add_relation', eidn, 'ecrit_par', eidp), |
506 self.assertEquals(CALLED, [('before_add_relation', eidn, 'ecrit_par', eidp), |
508 ('after_add_relation', eidn, 'ecrit_par', eidp)]) |
507 ('after_add_relation', eidn, 'ecrit_par', eidp)]) |