|
@@ -116,7 +116,6 @@ class LodelHookTestCase(unittest.TestCase):
|
116
|
116
|
|
117
|
117
|
call_args = {'datas':dict()}
|
118
|
118
|
|
119
|
|
- leo = Numero
|
120
|
119
|
for leo in [Numero, Publication, RelTextesPersonneAuteur]:
|
121
|
120
|
with patch.object(_LeCrud, 'populate', return_value = None) as osef_mock:
|
122
|
121
|
with patch.object(LodelHook, 'call_hook', return_value = call_args) as callhook_mock:
|
|
@@ -128,4 +127,37 @@ class LodelHookTestCase(unittest.TestCase):
|
128
|
127
|
]
|
129
|
128
|
callhook_mock.assert_has_calls(expected_calls, any_order = False)
|
130
|
129
|
|
131
|
|
- ## @todo Write tests for delete and insert hooks
|
|
130
|
+ def test_leapi_delete_hooks(self):
|
|
131
|
+ """ Testing that leapi_delete_* hooks get called when calling delete on LeCrud child instance"""
|
|
132
|
+ from dyncode import Numero, Publication, LeRelation, RelTextesPersonneAuteur
|
|
133
|
+ for leo in [Numero, Publication, RelTextesPersonneAuteur]:
|
|
134
|
+ with patch.object(LodelHook, 'call_hook', return_value = None) as callhook_mock:
|
|
135
|
+ inst = leo(42)
|
|
136
|
+ inst.delete()
|
|
137
|
+ expected_calls = [
|
|
138
|
+ call('leapi_delete_pre', inst, None),
|
|
139
|
+ call('leapi_delete_post', inst, None)
|
|
140
|
+ ]
|
|
141
|
+ callhook_mock.assert_has_calls(expected_calls, any_order = False)
|
|
142
|
+
|
|
143
|
+ def test_leapi_insert_hooks(self):
|
|
144
|
+ """ Testing that leapi_insert_* hooks get called when calling insert on LeCrud child instance """
|
|
145
|
+ # Only testing with Article because datas check is anoying
|
|
146
|
+ from dyncode import Article
|
|
147
|
+ call_args = {
|
|
148
|
+ 'datas': {
|
|
149
|
+ 'titre': 'test',
|
|
150
|
+ 'soustitre': 'avec des mocks',
|
|
151
|
+ }
|
|
152
|
+ }
|
|
153
|
+
|
|
154
|
+ full_args = copy.copy(call_args)
|
|
155
|
+ full_args['classname'] = None
|
|
156
|
+
|
|
157
|
+ with patch.object(LodelHook, 'call_hook', return_value = full_args) as callhook_mock:
|
|
158
|
+ Article.insert(**call_args)
|
|
159
|
+ expected_calls = [
|
|
160
|
+ call('leapi_insert_pre', Article, full_args),
|
|
161
|
+ call('leapi_insert_post', Article, None),
|
|
162
|
+ ]
|
|
163
|
+ callhook_mock.assert_has_calls(expected_calls)
|