author | Julien Tayon <julien.tayon@logilab.fr> |
Tue, 25 Feb 2020 23:22:58 +0100 | |
branch | 3.27 |
changeset 12895 | 5a9d1e64f505 |
parent 12514 | eac7f5b20f9f |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
11767
432f87a63057
flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11269
diff
changeset
|
2 |
# copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
3 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
4 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
5 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
6 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
7 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
8 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
9 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
10 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
11 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
12 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
13 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
14 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
15 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
16 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
17 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
18 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5886 | 19 |
"""unit/functional tests for cubicweb.server.hook""" |
0 | 20 |
|
11769
f5b815f67ce2
[test] Remove some usages of lgc.testlib
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11768
diff
changeset
|
21 |
import unittest |
f5b815f67ce2
[test] Remove some usages of lgc.testlib
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11768
diff
changeset
|
22 |
from logilab.common.testlib import mock_object |
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
23 |
|
11768
b8b71dd09a2c
[test] Avoid pytest discovery warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11767
diff
changeset
|
24 |
from cubicweb import devtools |
b8b71dd09a2c
[test] Avoid pytest discovery warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11767
diff
changeset
|
25 |
from cubicweb.devtools import fake |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
26 |
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
|
27 |
from cubicweb.server import hook |
3413
5cd27d2cc64f
update imports, rename test module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
28 |
from cubicweb.hooks import integrity, syncschema |
0 | 29 |
|
11767
432f87a63057
flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11269
diff
changeset
|
30 |
|
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
31 |
class OperationsTC(CubicWebTC): |
1787 | 32 |
|
0 | 33 |
def test_late_operation(self): |
9758
91f3cb7db2aa
[test/hook] use the new connection API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9548
diff
changeset
|
34 |
with self.admin_access.repo_cnx() as cnx: |
91f3cb7db2aa
[test/hook] use the new connection API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9548
diff
changeset
|
35 |
l1 = hook.LateOperation(cnx) |
91f3cb7db2aa
[test/hook] use the new connection API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9548
diff
changeset
|
36 |
l2 = hook.LateOperation(cnx) |
91f3cb7db2aa
[test/hook] use the new connection API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9548
diff
changeset
|
37 |
l3 = hook.Operation(cnx) |
91f3cb7db2aa
[test/hook] use the new connection API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9548
diff
changeset
|
38 |
self.assertEqual(cnx.pending_operations, [l3, l1, l2]) |
1787 | 39 |
|
0 | 40 |
def test_single_last_operation(self): |
9758
91f3cb7db2aa
[test/hook] use the new connection API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9548
diff
changeset
|
41 |
with self.admin_access.repo_cnx() as cnx: |
91f3cb7db2aa
[test/hook] use the new connection API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9548
diff
changeset
|
42 |
l0 = hook.SingleLastOperation(cnx) |
91f3cb7db2aa
[test/hook] use the new connection API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9548
diff
changeset
|
43 |
l1 = hook.LateOperation(cnx) |
91f3cb7db2aa
[test/hook] use the new connection API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9548
diff
changeset
|
44 |
l2 = hook.LateOperation(cnx) |
91f3cb7db2aa
[test/hook] use the new connection API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9548
diff
changeset
|
45 |
l3 = hook.Operation(cnx) |
91f3cb7db2aa
[test/hook] use the new connection API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9548
diff
changeset
|
46 |
self.assertEqual(cnx.pending_operations, [l3, l1, l2, l0]) |
91f3cb7db2aa
[test/hook] use the new connection API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9548
diff
changeset
|
47 |
l4 = hook.SingleLastOperation(cnx) |
91f3cb7db2aa
[test/hook] use the new connection API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9548
diff
changeset
|
48 |
self.assertEqual(cnx.pending_operations, [l3, l1, l2, l4]) |
1787 | 49 |
|
0 | 50 |
def test_global_operation_order(self): |
9758
91f3cb7db2aa
[test/hook] use the new connection API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9548
diff
changeset
|
51 |
with self.admin_access.repo_cnx() as cnx: |
91f3cb7db2aa
[test/hook] use the new connection API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9548
diff
changeset
|
52 |
op1 = syncschema.RDefDelOp(cnx) |
91f3cb7db2aa
[test/hook] use the new connection API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9548
diff
changeset
|
53 |
op2 = integrity._CheckORelationOp(cnx) |
91f3cb7db2aa
[test/hook] use the new connection API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9548
diff
changeset
|
54 |
op3 = syncschema.MemSchemaNotifyChanges(cnx) |
91f3cb7db2aa
[test/hook] use the new connection API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9548
diff
changeset
|
55 |
self.assertEqual([op1, op2, op3], cnx.pending_operations) |
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
56 |
|
11767
432f87a63057
flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11269
diff
changeset
|
57 |
|
432f87a63057
flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11269
diff
changeset
|
58 |
class HookCalled(Exception): |
432f87a63057
flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11269
diff
changeset
|
59 |
pass |
432f87a63057
flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11269
diff
changeset
|
60 |
|
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
61 |
|
12513
6f42f1460f99
[server/test] bootstrap config in setUpModule function
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
12036
diff
changeset
|
62 |
def setUpModule(): |
6f42f1460f99
[server/test] bootstrap config in setUpModule function
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
12036
diff
changeset
|
63 |
global config, schema |
6f42f1460f99
[server/test] bootstrap config in setUpModule function
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
12036
diff
changeset
|
64 |
config = devtools.TestServerConfiguration('data', __file__) |
6f42f1460f99
[server/test] bootstrap config in setUpModule function
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
12036
diff
changeset
|
65 |
config.bootstrap_cubes() |
6f42f1460f99
[server/test] bootstrap config in setUpModule function
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
12036
diff
changeset
|
66 |
schema = config.load_schema() |
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
67 |
|
6781
5062d86d6ffe
[unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
68 |
def tearDownModule(*args): |
4766
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
69 |
global config, schema |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
70 |
del config, schema |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
71 |
|
11767
432f87a63057
flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11269
diff
changeset
|
72 |
|
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
73 |
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
|
74 |
__regid__ = 'addany' |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
75 |
category = 'cat1' |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
76 |
events = ('before_add_entity',) |
11767
432f87a63057
flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11269
diff
changeset
|
77 |
|
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
78 |
def __call__(self): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
79 |
raise HookCalled() |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
80 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
81 |
|
11769
f5b815f67ce2
[test] Remove some usages of lgc.testlib
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11768
diff
changeset
|
82 |
class HooksRegistryTC(unittest.TestCase): |
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
83 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
84 |
def setUp(self): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
85 |
""" 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
|
86 |
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
|
87 |
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
|
88 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
89 |
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
|
90 |
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
|
91 |
events = ('before_add_entiti',) |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
92 |
with self.assertRaises(Exception) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
93 |
self.o.register(_Hook) |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
94 |
self.assertEqual(str(cm.exception), 'bad event before_add_entiti on %s._Hook' % __name__) |
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
95 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
96 |
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
|
97 |
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
|
98 |
events = None |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
99 |
with self.assertRaises(Exception) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
100 |
self.o.register(_Hook) |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
101 |
self.assertEqual(str(cm.exception), 'bad .events attribute None on %s._Hook' % __name__) |
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
102 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
103 |
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
|
104 |
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
|
105 |
events = 'before_add_entity' |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
106 |
with self.assertRaises(Exception) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
107 |
self.o.register(_Hook) |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
108 |
self.assertEqual(str(cm.exception), 'bad event b on %s._Hook' % __name__) |
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
109 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
110 |
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
|
111 |
self.o.register(AddAnyHook) |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
112 |
dis = set() |
12035
2fcb9339f69a
[devtools] Rename FakeSession into FakeConnection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
12027
diff
changeset
|
113 |
cw = fake.FakeConnection() |
7361
6baa4f430c9b
[repo test] fix test broken by c2452cd57026 by using proper fake session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
114 |
cw.is_hook_activated = lambda cls: cls.category not in dis |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
115 |
self.assertRaises(HookCalled, |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
116 |
self.o.call_hooks, 'before_add_entity', cw) |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
117 |
dis.add('cat1') |
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
118 |
self.o.call_hooks('before_add_entity', cw) # disabled hooks category, not called |
4834
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
119 |
dis.remove('cat1') |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
120 |
self.assertRaises(HookCalled, |
b718626a0e60
move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
121 |
self.o.call_hooks, 'before_add_entity', cw) |
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
122 |
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
|
123 |
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
|
124 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
125 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
126 |
class SystemHooksTC(CubicWebTC): |
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
127 |
|
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
128 |
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
|
129 |
import hooks # cubicweb/server/test/data/hooks.py |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5921
diff
changeset
|
130 |
self.assertEqual(hooks.CALLED_EVENTS['server_startup'], True) |
3414
fe6c99b96701
no more HooksManager but a HooksRegistry: update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3413
diff
changeset
|
131 |
# 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
|
132 |
self.repo.hm.call_hooks('server_shutdown', repo=self.repo) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5921
diff
changeset
|
133 |
self.assertEqual(hooks.CALLED_EVENTS['server_shutdown'], True) |
3414
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 |
|
0 | 136 |
if __name__ == '__main__': |
11769
f5b815f67ce2
[test] Remove some usages of lgc.testlib
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11768
diff
changeset
|
137 |
unittest.main() |