author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 23 Sep 2009 12:22:16 +0200 | |
changeset 3414 | fe6c99b96701 |
parent 3413 | 5cd27d2cc64f |
child 4252 | 6c4f109c2b03 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
3413
5cd27d2cc64f
update imports, rename test module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
2 |
"""unit/functional tests for cubicweb.server.hook |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
3 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
4 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
5 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
7 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
8 |
""" |
0 | 9 |
|
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
10 |
from logilab.common.testlib import TestCase, unittest_main, mock_object |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
11 |
|
3413
5cd27d2cc64f
update imports, rename test module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
12 |
|
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
13 |
from cubicweb.devtools import TestServerConfiguration |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
14 |
from cubicweb.devtools.testlib import CubicWebTC |
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
15 |
from cubicweb.selectors import implements |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
16 |
from cubicweb.server import hook |
3413
5cd27d2cc64f
update imports, rename test module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
17 |
from cubicweb.hooks import integrity, syncschema |
0 | 18 |
|
19 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
20 |
def clean_session_ops(func): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
21 |
def wrapper(self, *args, **kwargs): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
22 |
try: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
23 |
return func(self, *args, **kwargs) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
24 |
finally: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
25 |
self.session.pending_operations[:] = [] |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
26 |
return wrapper |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
27 |
|
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
28 |
class OperationsTC(CubicWebTC): |
1787 | 29 |
|
0 | 30 |
def setUp(self): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
31 |
CubicWebTC.setUp(self) |
0 | 32 |
self.hm = self.repo.hm |
1787 | 33 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
34 |
@clean_session_ops |
0 | 35 |
def test_late_operation(self): |
36 |
session = self.session |
|
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
37 |
l1 = hook.LateOperation(session) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
38 |
l2 = hook.LateOperation(session) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
39 |
l3 = hook.Operation(session) |
0 | 40 |
self.assertEquals(session.pending_operations, [l3, l1, l2]) |
1787 | 41 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
42 |
@clean_session_ops |
0 | 43 |
def test_single_last_operation(self): |
44 |
session = self.session |
|
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
45 |
l0 = hook.SingleLastOperation(session) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
46 |
l1 = hook.LateOperation(session) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
47 |
l2 = hook.LateOperation(session) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
48 |
l3 = hook.Operation(session) |
0 | 49 |
self.assertEquals(session.pending_operations, [l3, l1, l2, l0]) |
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
50 |
l4 = hook.SingleLastOperation(session) |
0 | 51 |
self.assertEquals(session.pending_operations, [l3, l1, l2, l4]) |
1787 | 52 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
53 |
@clean_session_ops |
0 | 54 |
def test_global_operation_order(self): |
55 |
session = self.session |
|
3413
5cd27d2cc64f
update imports, rename test module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
56 |
op1 = integrity._DelayedDeleteOp(session) |
5cd27d2cc64f
update imports, rename test module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
57 |
op2 = syncschema.MemSchemaRDefDel(session) |
0 | 58 |
# equivalent operation generated by op2 but replace it here by op3 so we |
59 |
# can check the result... |
|
3413
5cd27d2cc64f
update imports, rename test module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
60 |
op3 = syncschema.MemSchemaNotifyChanges(session) |
5cd27d2cc64f
update imports, rename test module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
61 |
op4 = integrity._DelayedDeleteOp(session) |
5cd27d2cc64f
update imports, rename test module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
62 |
op5 = integrity._CheckORelationOp(session) |
0 | 63 |
self.assertEquals(session.pending_operations, [op1, op2, op4, op5, op3]) |
1787 | 64 |
|
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
65 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
66 |
class HookCalled(Exception): pass |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
67 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
68 |
config = TestServerConfiguration('data') |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
69 |
config.bootstrap_cubes() |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
70 |
schema = config.load_schema() |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
71 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
72 |
class AddAnyHook(hook.Hook): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
73 |
__regid__ = 'addany' |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
74 |
category = 'cat1' |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
75 |
events = ('before_add_entity',) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
76 |
def __call__(self): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
77 |
raise HookCalled() |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
78 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
79 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
80 |
class HooksManagerTC(TestCase): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
81 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
82 |
def setUp(self): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
83 |
""" called before each test from this class """ |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
84 |
self.vreg = mock_object(config=config, schema=schema) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
85 |
self.o = hook.HooksRegistry(self.vreg) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
86 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
87 |
def test_register_bad_hook1(self): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
88 |
class _Hook(hook.Hook): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
89 |
events = ('before_add_entiti',) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
90 |
ex = self.assertRaises(Exception, self.o.register, _Hook) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
91 |
self.assertEquals(str(ex), 'bad event before_add_entiti on unittest_hook._Hook') |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
92 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
93 |
def test_register_bad_hook2(self): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
94 |
class _Hook(hook.Hook): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
95 |
events = None |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
96 |
ex = self.assertRaises(Exception, self.o.register, _Hook) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
97 |
self.assertEquals(str(ex), 'bad .events attribute None on unittest_hook._Hook') |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
98 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
99 |
def test_register_bad_hook3(self): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
100 |
class _Hook(hook.Hook): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
101 |
events = 'before_add_entity' |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
102 |
ex = self.assertRaises(Exception, self.o.register, _Hook) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
103 |
self.assertEquals(str(ex), 'bad event b on unittest_hook._Hook') |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
104 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
105 |
def test_call_hook(self): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
106 |
self.o.register(AddAnyHook) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
107 |
cw = mock_object(vreg=self.vreg) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
108 |
self.assertRaises(HookCalled, self.o.call_hooks, 'before_add_entity', cw) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
109 |
self.o.call_hooks('before_delete_entity', cw) # nothing to call |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
110 |
config.disabled_hooks_categories.add('cat1') |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
111 |
self.o.call_hooks('before_add_entity', cw) # disabled hooks category, not called |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
112 |
config.disabled_hooks_categories.remove('cat1') |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
113 |
self.assertRaises(HookCalled, self.o.call_hooks, 'before_add_entity', cw) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
114 |
self.o.unregister(AddAnyHook) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
115 |
self.o.call_hooks('before_add_entity', cw) # nothing to call |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
116 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
117 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
118 |
class SystemHooksTC(CubicWebTC): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
119 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
120 |
def test_startup_shutdown(self): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
121 |
import hooks # cubicweb/server/test/data/hooks.py |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
122 |
self.assertEquals(hooks.CALLED_EVENTS['server_startup'], True) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
123 |
# don't actually call repository.shutdown ! |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
124 |
self.repo.hm.call_hooks('server_shutdown', repo=self.repo) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
125 |
self.assertEquals(hooks.CALLED_EVENTS['server_shutdown'], True) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
126 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
127 |
def test_session_open_close(self): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
128 |
import hooks # cubicweb/server/test/data/hooks.py |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
129 |
cnx = self.login('anon') |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
130 |
self.assertEquals(hooks.CALLED_EVENTS['session_open'], 'anon') |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
131 |
cnx.close() |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
132 |
self.assertEquals(hooks.CALLED_EVENTS['session_close'], 'anon') |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
133 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
134 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
135 |
# class RelationHookTC(TestCase): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
136 |
# """testcase for relation hooks grouping""" |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
137 |
# def setUp(self): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
138 |
# """ called before each test from this class """ |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
139 |
# self.o = HooksManager(schema) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
140 |
# self.called = [] |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
141 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
142 |
# def test_before_add_relation(self): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
143 |
# """make sure before_xxx_relation hooks are called directly""" |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
144 |
# self.o.register(self._before_relation_hook, |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
145 |
# 'before_add_relation', 'concerne') |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
146 |
# self.assertEquals(self.called, []) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
147 |
# self.o.call_hooks('before_add_relation', 'concerne', 'USER', |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
148 |
# 1, 'concerne', 2) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
149 |
# self.assertEquals(self.called, [(1, 'concerne', 2)]) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
150 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
151 |
# def test_after_add_relation(self): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
152 |
# """make sure after_xxx_relation hooks are deferred""" |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
153 |
# self.o.register(self._after_relation_hook, |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
154 |
# 'after_add_relation', 'concerne') |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
155 |
# self.assertEquals(self.called, []) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
156 |
# self.o.call_hooks('after_add_relation', 'concerne', 'USER', |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
157 |
# 1, 'concerne', 2) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
158 |
# self.o.call_hooks('after_add_relation', 'concerne', 'USER', |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
159 |
# 3, 'concerne', 4) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
160 |
# self.assertEquals(self.called, [(1, 'concerne', 2), (3, 'concerne', 4)]) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
161 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
162 |
# def test_before_delete_relation(self): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
163 |
# """make sure before_xxx_relation hooks are called directly""" |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
164 |
# self.o.register(self._before_relation_hook, |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
165 |
# 'before_delete_relation', 'concerne') |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
166 |
# self.assertEquals(self.called, []) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
167 |
# self.o.call_hooks('before_delete_relation', 'concerne', 'USER', |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
168 |
# 1, 'concerne', 2) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
169 |
# self.assertEquals(self.called, [(1, 'concerne', 2)]) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
170 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
171 |
# def test_after_delete_relation(self): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
172 |
# """make sure after_xxx_relation hooks are deferred""" |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
173 |
# self.o.register(self._after_relation_hook, |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
174 |
# 'after_delete_relation', 'concerne') |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
175 |
# self.o.call_hooks('after_delete_relation', 'concerne', 'USER', |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
176 |
# 1, 'concerne', 2) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
177 |
# self.o.call_hooks('after_delete_relation', 'concerne', 'USER', |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
178 |
# 3, 'concerne', 4) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
179 |
# self.assertEquals(self.called, [(1, 'concerne', 2), (3, 'concerne', 4)]) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
180 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
181 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
182 |
# def _before_relation_hook(self, pool, subject, r_type, object): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
183 |
# self.called.append((subject, r_type, object)) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
184 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
185 |
# def _after_relation_hook(self, pool, subject, r_type, object): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
186 |
# self.called.append((subject, r_type, object)) |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
187 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
188 |
|
0 | 189 |
if __name__ == '__main__': |
190 |
unittest_main() |