Browse Source

Add a LodelHook tests, for leapi_update_* hooks calls

Yann Weber 9 years ago
parent
commit
04636f7582
2 changed files with 21 additions and 2 deletions
  1. 20
    1
      Lodel/test/tests_hooks.py
  2. 1
    1
      leapi/lecrud.py

+ 20
- 1
Lodel/test/tests_hooks.py View File

@@ -108,5 +108,24 @@ class LodelHookTestCase(unittest.TestCase):
108 108
                     call('leapi_get_post', lerel, None),
109 109
                 ]
110 110
                 callhook_mock.assert_has_calls(expected_calls, any_order = False)
111
+    
112
+    def test_leapi_update_hook(self):
113
+        """ Testing that leapi_update_* hooks get called when calling update on LeCrud child instance"""
114
+        from leapi.lecrud import _LeCrud
115
+        from dyncode import Numero, Publication, LeRelation, RelTextesPersonneAuteur
111 116
 
112
-    ## @todo Write tests for update, delete and insert hooks
117
+        call_args = {'datas':dict()}
118
+        
119
+        leo = Numero
120
+        for leo in [Numero, Publication, RelTextesPersonneAuteur]:
121
+            with patch.object(_LeCrud, 'populate', return_value = None) as osef_mock:
122
+                with patch.object(LodelHook, 'call_hook', return_value = call_args) as callhook_mock:
123
+                    inst = leo(42)
124
+                    inst.update(**call_args)
125
+                    expected_calls = [
126
+                        call('leapi_update_pre', inst, call_args),
127
+                        call('leapi_update_post', inst, False),
128
+                    ]
129
+                    callhook_mock.assert_has_calls(expected_calls, any_order = False)
130
+
131
+    ## @todo Write tests for delete and insert hooks

+ 1
- 1
leapi/lecrud.py View File

@@ -285,7 +285,7 @@ class _LeCrud(object):
285 285
         del(kwargs['self'])
286 286
         kwargs = LodelHook.call_hook('leapi_update_pre', self, kwargs)
287 287
         ret = self.__update_unsafe(**kwargs)
288
-        return ret
288
+        return LodelHook.call_hook('leapi_update_post', self, ret)
289 289
 
290 290
     ## @brief Unsafe, without hooks version of insert method
291 291
     # @see _LeCrud.update()

Loading…
Cancel
Save