doc/book/en/devrepo/repo/hooks.rst
branchstable
changeset 6344 0cb0d8d83e4c
parent 6152 6824f8b61098
child 6366 1806148d6ce8
--- a/doc/book/en/devrepo/repo/hooks.rst	Fri Sep 24 18:37:03 2010 +0200
+++ b/doc/book/en/devrepo/repo/hooks.rst	Fri Sep 24 18:38:24 2010 +0200
@@ -58,6 +58,10 @@
 implementing `precommit_event` and other standard methods (wholly
 described in :ref:`operations_api`).
 
+.. hint::
+
+   It is a good practice, to write unit tests for each hook. See an example in :ref:`hook_test`
+
 Events
 ------
 
@@ -241,6 +245,8 @@
 
 .. sourcecode:: python
 
+    from cubicweb.server.hook import Hook, Operation, match_rtype
+
     def check_cycle(self, session, eid, rtype, role='subject'):
         parents = set([eid])
         parent = session.entity_from_eid(eid)
@@ -300,7 +306,7 @@
    class CheckSubsidiaryCycleOp(Operation):
 
        def precommit_event(self):
-           for eid in self._cw.transaction_data['subsidiary_cycle_detection']:
+           for eid in self.session.transaction_data['subsidiary_cycle_detection']:
                check_cycle(self.session, eid, self.rtype)
 
 Here, we call set_operation with a session object, a specially forged