1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
14 # details. |
14 # details. |
15 # |
15 # |
16 # You should have received a copy of the GNU Lesser General Public License along |
16 # You should have received a copy of the GNU Lesser General Public License along |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 """ |
|
19 |
|
20 """ |
|
21 from logilab.common.testlib import TestCase, unittest_main, mock_object |
18 from logilab.common.testlib import TestCase, unittest_main, mock_object |
22 |
19 |
23 from cubicweb.devtools.testlib import CubicWebTC |
20 from cubicweb.devtools.testlib import CubicWebTC |
24 from cubicweb.server.session import _make_description |
21 from cubicweb.server.session import _make_description, hooks_control |
25 |
22 |
26 class Variable: |
23 class Variable: |
27 def __init__(self, name): |
24 def __init__(self, name): |
28 self.name = name |
25 self.name = name |
29 self.children = [] |
26 self.children = [] |
44 def test_known_values(self): |
41 def test_known_values(self): |
45 solution = {'A': 'Int', 'B': 'CWUser'} |
42 solution = {'A': 'Int', 'B': 'CWUser'} |
46 self.assertEqual(_make_description((Function('max', 'A'), Variable('B')), {}, solution), |
43 self.assertEqual(_make_description((Function('max', 'A'), Variable('B')), {}, solution), |
47 ['Int','CWUser']) |
44 ['Int','CWUser']) |
48 |
45 |
|
46 |
49 class InternalSessionTC(CubicWebTC): |
47 class InternalSessionTC(CubicWebTC): |
50 def test_dbapi_query(self): |
48 def test_dbapi_query(self): |
51 session = self.repo.internal_session() |
49 session = self.repo.internal_session() |
52 self.assertFalse(session.running_dbapi_query) |
50 self.assertFalse(session.running_dbapi_query) |
53 session.close() |
51 session.close() |
54 |
52 |
|
53 |
|
54 class SessionTC(CubicWebTC): |
|
55 |
|
56 def test_hooks_control(self): |
|
57 session = self.session |
|
58 self.assertEqual(session.hooks_mode, session.HOOKS_ALLOW_ALL) |
|
59 self.assertEqual(session.disabled_hook_categories, set()) |
|
60 self.assertEqual(session.enabled_hook_categories, set()) |
|
61 self.assertEqual(len(session._tx_data), 1) |
|
62 with hooks_control(session, session.HOOKS_DENY_ALL, 'metadata'): |
|
63 self.assertEqual(session.hooks_mode, session.HOOKS_DENY_ALL) |
|
64 self.assertEqual(session.disabled_hook_categories, set()) |
|
65 self.assertEqual(session.enabled_hook_categories, set(('metadata',))) |
|
66 session.commit() |
|
67 self.assertEqual(session.hooks_mode, session.HOOKS_DENY_ALL) |
|
68 self.assertEqual(session.disabled_hook_categories, set()) |
|
69 self.assertEqual(session.enabled_hook_categories, set(('metadata',))) |
|
70 session.rollback() |
|
71 self.assertEqual(session.hooks_mode, session.HOOKS_DENY_ALL) |
|
72 self.assertEqual(session.disabled_hook_categories, set()) |
|
73 self.assertEqual(session.enabled_hook_categories, set(('metadata',))) |
|
74 # leaving context manager with no transaction running should reset the |
|
75 # transaction local storage (and associated pool) |
|
76 self.assertEqual(session._tx_data, {}) |
|
77 self.assertEqual(session.pool, None) |
|
78 |
55 if __name__ == '__main__': |
79 if __name__ == '__main__': |
56 unittest_main() |
80 unittest_main() |