|
@@ -0,0 +1,43 @@
|
|
1
|
+#-*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+import unittest
|
|
4
|
+from unittest.mock import MagicMock
|
|
5
|
+
|
|
6
|
+from lodel.plugin.plugins import Plugin, PluginError
|
|
7
|
+from lodel.plugin.hooks import LodelHook
|
|
8
|
+
|
|
9
|
+testhook = 'are_we_sure_that_this_name_is_uniq'
|
|
10
|
+
|
|
11
|
+class HookTestCase(unittest.TestCase):
|
|
12
|
+
|
|
13
|
+ def setUp(self):
|
|
14
|
+ LodelHook.__reset__()
|
|
15
|
+
|
|
16
|
+ def test_registration(self):
|
|
17
|
+ """ Testing hook registration using decorator (checking using hook_list() """
|
|
18
|
+ hook_list = LodelHook.hook_list(testhook)
|
|
19
|
+ self.assertEqual({}, hook_list)
|
|
20
|
+ #hook_registration
|
|
21
|
+ @LodelHook(testhook,42)
|
|
22
|
+ def funny_fun_test_hook(hook_name, caller, payload):
|
|
23
|
+ pass
|
|
24
|
+ hook_list = LodelHook.hook_list(testhook)
|
|
25
|
+ self.assertEqual({testhook: [(funny_fun_test_hook, 42)]}, hook_list)
|
|
26
|
+
|
|
27
|
+ def test_call(self):
|
|
28
|
+ """ Testing LodelHook.call_hook() """
|
|
29
|
+ #manual registration using a mock
|
|
30
|
+ mmock = MagicMock(return_value = '4242')
|
|
31
|
+ mmock.__name__ = 'mmock'
|
|
32
|
+ hooking = LodelHook(testhook, 1337)
|
|
33
|
+ hooking(mmock)
|
|
34
|
+ res = LodelHook.call_hook(testhook, 'Caller', 'payload')
|
|
35
|
+ #Check returned value
|
|
36
|
+ self.assertEqual(
|
|
37
|
+ res,
|
|
38
|
+ '4242',
|
|
39
|
+ 'Expected value was "4242" but found %s' % res)
|
|
40
|
+ #Checks call
|
|
41
|
+ mmock.assert_called_once_with(testhook, 'Caller', 'payload')
|
|
42
|
+
|
|
43
|
+
|