author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
Tue, 02 Apr 2013 16:02:52 +0200 | |
changeset 8846 | f31e2d6f1b53 |
parent 8771 | 519629422391 |
child 9020 | cb87e831c183 |
child 9240 | 6356adcb652c |
permissions | -rw-r--r-- |
8554
6e5d8512b07d
[repo cleanup] drop code moved to querier by 7e264ce34cd4
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8542
diff
changeset
|
1 |
# copyright 2003-2012 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:
5197
diff
changeset
|
2 |
# 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:
5197
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5197
diff
changeset
|
4 |
# 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:
5197
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5197
diff
changeset
|
6 |
# 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:
5197
diff
changeset
|
7 |
# 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:
5197
diff
changeset
|
8 |
# 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:
5197
diff
changeset
|
9 |
# 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:
5197
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# 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:
5197
diff
changeset
|
12 |
# 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:
5197
diff
changeset
|
13 |
# 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:
5197
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5197
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5197
diff
changeset
|
16 |
# 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:
5197
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
7364
aff846ce1050
missing future import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7350
diff
changeset
|
18 |
|
5193
c9671feff5e2
[session] no way for queries from an InternalSession to be a dbapi query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
19 |
from cubicweb.devtools.testlib import CubicWebTC |
8846
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
20 |
from cubicweb.server.session import HOOKS_ALLOW_ALL, HOOKS_DENY_ALL |
0 | 21 |
|
5193
c9671feff5e2
[session] no way for queries from an InternalSession to be a dbapi query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
22 |
class InternalSessionTC(CubicWebTC): |
c9671feff5e2
[session] no way for queries from an InternalSession to be a dbapi query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
23 |
def test_dbapi_query(self): |
c9671feff5e2
[session] no way for queries from an InternalSession to be a dbapi query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
24 |
session = self.repo.internal_session() |
c9671feff5e2
[session] no way for queries from an InternalSession to be a dbapi query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
25 |
self.assertFalse(session.running_dbapi_query) |
5197
98dc05495e3e
[test] properly close session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5193
diff
changeset
|
26 |
session.close() |
5193
c9671feff5e2
[session] no way for queries from an InternalSession to be a dbapi query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
27 |
|
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
28 |
|
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
29 |
class SessionTC(CubicWebTC): |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
30 |
|
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
31 |
def test_hooks_control(self): |
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
32 |
session = self.session |
8846
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
33 |
self.assertEqual(HOOKS_ALLOW_ALL, session.hooks_mode) |
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
34 |
self.assertEqual(set(), session.disabled_hook_categories) |
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
35 |
self.assertEqual(set(), session.enabled_hook_categories) |
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
36 |
self.assertEqual(1, len(session._txs)) |
8561
77ea3eed9946
[session] promote usage of [deny|all]_all_hooks_but session methods rather than hooks_control context manager directly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8554
diff
changeset
|
37 |
with session.deny_all_hooks_but('metadata'): |
8846
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
38 |
self.assertEqual(HOOKS_DENY_ALL, session.hooks_mode) |
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
39 |
self.assertEqual(set(), session.disabled_hook_categories) |
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
40 |
self.assertEqual(set(('metadata',)), session.enabled_hook_categories) |
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
41 |
session.commit() |
8846
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
42 |
self.assertEqual(HOOKS_DENY_ALL, session.hooks_mode) |
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
43 |
self.assertEqual(set(), session.disabled_hook_categories) |
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
44 |
self.assertEqual(set(('metadata',)), session.enabled_hook_categories) |
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
45 |
session.rollback() |
8846
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
46 |
self.assertEqual(HOOKS_DENY_ALL, session.hooks_mode) |
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
47 |
self.assertEqual(set(), session.disabled_hook_categories) |
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
48 |
self.assertEqual(set(('metadata',)), session.enabled_hook_categories) |
8561
77ea3eed9946
[session] promote usage of [deny|all]_all_hooks_but session methods rather than hooks_control context manager directly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8554
diff
changeset
|
49 |
with session.allow_all_hooks_but('integrity'): |
8846
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
50 |
self.assertEqual(HOOKS_ALLOW_ALL, session.hooks_mode) |
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
51 |
self.assertEqual(set(('integrity',)), session.disabled_hook_categories) |
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
52 |
self.assertEqual(set(('metadata',)), session.enabled_hook_categories) # not changed in such case |
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
53 |
self.assertEqual(HOOKS_DENY_ALL, session.hooks_mode) |
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
54 |
self.assertEqual(set(), session.disabled_hook_categories) |
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
55 |
self.assertEqual(set(('metadata',)), session.enabled_hook_categories) |
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
56 |
# leaving context manager with no transaction running should reset the |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7364
diff
changeset
|
57 |
# transaction local storage (and associated cnxset) |
8846
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
58 |
self.assertEqual({}, session._txs) |
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
59 |
self.assertEqual(None, session.cnxset) |
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
60 |
self.assertEqual(HOOKS_ALLOW_ALL, session.hooks_mode, session.HOOKS_ALLOW_ALL) |
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
61 |
self.assertEqual(set(), session.disabled_hook_categories) |
f31e2d6f1b53
[test] use the right order in some assertEqual
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
62 |
self.assertEqual(set(), session.enabled_hook_categories) |
7350
c2452cd57026
[session] enhance session's transaction storage handling to fix cases where commit/rollback is done while in the context of hooks_control/security_enabled managers. Closes #1412648: commit or rollback during postcreate reset hooks control state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
63 |
|
7730
8d0edec31aaf
[querier] we should not insert None but skip the line when some unknown eid is detected (closes #1892491)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
64 |
|
0 | 65 |
if __name__ == '__main__': |
8561
77ea3eed9946
[session] promote usage of [deny|all]_all_hooks_but session methods rather than hooks_control context manager directly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8554
diff
changeset
|
66 |
from logilab.common.testlib import unittest_main |
0 | 67 |
unittest_main() |