author | Rémi Cardona <remi.cardona@logilab.fr> |
Tue, 15 Dec 2015 14:12:59 +0100 | |
changeset 10981 | 45bc791275b4 |
parent 10907 | 9ae707db5265 |
permissions | -rw-r--r-- |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
1 |
# copyright 2003-2014 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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5561
58b05c314443
[selectors] ensure adaptable('IDownloadable') takes precedence over implements('Any')
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
18 |
"""unit tests for selectors mechanism""" |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
19 |
|
6348
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
20 |
from operator import eq, lt, le, gt |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
21 |
from contextlib import contextmanager |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
22 |
|
10884
8a51e160026a
[py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10827
diff
changeset
|
23 |
from six.moves import range |
8a51e160026a
[py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10827
diff
changeset
|
24 |
|
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
25 |
from logilab.common.testlib import TestCase, unittest_main |
9582
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9152
diff
changeset
|
26 |
from logilab.common.decorators import clear_cache |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
27 |
|
5561
58b05c314443
[selectors] ensure adaptable('IDownloadable') takes precedence over implements('Any')
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
28 |
from cubicweb import Binary |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
29 |
from cubicweb.devtools.testlib import CubicWebTC |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7986
diff
changeset
|
30 |
from cubicweb.predicates import (is_instance, adaptable, match_kwargs, match_user_groups, |
10827
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
31 |
multi_lines_rset, score_entity, is_in_state, |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
32 |
rql_condition, relation_possible, match_form_params, |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
33 |
paginated_rset) |
8220
e4ea285510e5
[test] fix test broken by selectors/predicates changes coming with the move of registry to lgc
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8190
diff
changeset
|
34 |
from cubicweb.selectors import on_transition # XXX on_transition is deprecated |
8858
51fdbbbd07b2
[predicates] fix 'adaptable' implementation, used to return 0 on a rset with individualy adaptable entities of different types. Closes #2709663
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8220
diff
changeset
|
35 |
from cubicweb.view import EntityAdapter |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
36 |
from cubicweb.web import action |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
37 |
|
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
38 |
|
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
39 |
|
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
40 |
class ImplementsTC(CubicWebTC): |
779
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
41 |
def test_etype_priority(self): |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
42 |
with self.admin_access.web_request() as req: |
10704
73367a56ee41
[py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10529
diff
changeset
|
43 |
f = req.create_entity('FakeFile', data_name=u'hop.txt', data=Binary(b'hop'), |
10529
747eded13c68
[test] use FakeFile instead of File in test_fulltextindex
Julien Cristau <julien.cristau@logilab.fr>
parents:
10476
diff
changeset
|
44 |
data_format=u'text/plain') |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
45 |
rset = f.as_rset() |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
46 |
anyscore = is_instance('Any')(f.__class__, req, rset=rset) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
47 |
idownscore = adaptable('IDownloadable')(f.__class__, req, rset=rset) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
48 |
self.assertTrue(idownscore > anyscore, (idownscore, anyscore)) |
10529
747eded13c68
[test] use FakeFile instead of File in test_fulltextindex
Julien Cristau <julien.cristau@logilab.fr>
parents:
10476
diff
changeset
|
49 |
filescore = is_instance('FakeFile')(f.__class__, req, rset=rset) |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
50 |
self.assertTrue(filescore > idownscore, (filescore, idownscore)) |
1473 | 51 |
|
52 |
def test_etype_inheritance_no_yams_inheritance(self): |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
53 |
cls = self.vreg['etypes'].etype_class('Personne') |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
54 |
with self.admin_access.web_request() as req: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
55 |
self.assertFalse(is_instance('Societe').score_class(cls, req)) |
1473 | 56 |
|
6046
3fd4a34c4a09
[selectors] fix is_instance bug w/ parent classes. Also slight performance enhancements by changing what's returned by vreg['etypes'].parent_classes method (dedicated for this usage...) and removing no more necessary methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
57 |
def test_yams_inheritance(self): |
3fd4a34c4a09
[selectors] fix is_instance bug w/ parent classes. Also slight performance enhancements by changing what's returned by vreg['etypes'].parent_classes method (dedicated for this usage...) and removing no more necessary methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
58 |
cls = self.vreg['etypes'].etype_class('Transition') |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
59 |
with self.admin_access.web_request() as req: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
60 |
self.assertEqual(is_instance('BaseTransition').score_class(cls, req), |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
61 |
3) |
6046
3fd4a34c4a09
[selectors] fix is_instance bug w/ parent classes. Also slight performance enhancements by changing what's returned by vreg['etypes'].parent_classes method (dedicated for this usage...) and removing no more necessary methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
62 |
|
7982
77ed9b2fc9a5
[selectors] EClassSelector (eg is_instance & all) should check for None value (possible w/ outer join) when a row is specified. Closes #2033165
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7617
diff
changeset
|
63 |
def test_outer_join(self): |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
64 |
with self.admin_access.web_request() as req: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
65 |
rset = req.execute('Any U,B WHERE B? bookmarked_by U, U login "anon"') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
66 |
self.assertEqual(is_instance('Bookmark')(None, req, rset=rset, row=0, col=1), |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
67 |
0) |
7982
77ed9b2fc9a5
[selectors] EClassSelector (eg is_instance & all) should check for None value (possible w/ outer join) when a row is specified. Closes #2033165
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7617
diff
changeset
|
68 |
|
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
69 |
|
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
70 |
class WorkflowSelectorTC(CubicWebTC): |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
71 |
|
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
72 |
def setUp(self): |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
73 |
super(WorkflowSelectorTC, self).setUp() |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
74 |
# enable debug mode to state/transition validation on the fly |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
75 |
self.vreg.config.debugmode = True |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
76 |
|
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
77 |
def tearDown(self): |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
78 |
self.vreg.config.debugmode = False |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
79 |
super(WorkflowSelectorTC, self).tearDown() |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
80 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
81 |
def setup_database(self): |
9668
501f14e095d1
[test] Use RepoAccess.shell() in unittest_predicates
Julien Cristau <julien.cristau@logilab.fr>
parents:
9653
diff
changeset
|
82 |
with self.admin_access.shell() as shell: |
501f14e095d1
[test] Use RepoAccess.shell() in unittest_predicates
Julien Cristau <julien.cristau@logilab.fr>
parents:
9653
diff
changeset
|
83 |
wf = shell.add_workflow("wf_test", 'StateFull', default=True) |
501f14e095d1
[test] Use RepoAccess.shell() in unittest_predicates
Julien Cristau <julien.cristau@logilab.fr>
parents:
9653
diff
changeset
|
84 |
created = wf.add_state('created', initial=True) |
501f14e095d1
[test] Use RepoAccess.shell() in unittest_predicates
Julien Cristau <julien.cristau@logilab.fr>
parents:
9653
diff
changeset
|
85 |
validated = wf.add_state('validated') |
501f14e095d1
[test] Use RepoAccess.shell() in unittest_predicates
Julien Cristau <julien.cristau@logilab.fr>
parents:
9653
diff
changeset
|
86 |
abandoned = wf.add_state('abandoned') |
501f14e095d1
[test] Use RepoAccess.shell() in unittest_predicates
Julien Cristau <julien.cristau@logilab.fr>
parents:
9653
diff
changeset
|
87 |
wf.add_transition('validate', created, validated, ('managers',)) |
501f14e095d1
[test] Use RepoAccess.shell() in unittest_predicates
Julien Cristau <julien.cristau@logilab.fr>
parents:
9653
diff
changeset
|
88 |
wf.add_transition('forsake', (created, validated,), abandoned, ('managers',)) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
89 |
|
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
90 |
@contextmanager |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
91 |
def statefull_stuff(self): |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
92 |
with self.admin_access.web_request() as req: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
93 |
wf_entity = req.create_entity('StateFull', name=u'') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
94 |
rset = wf_entity.as_rset() |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
95 |
adapter = wf_entity.cw_adapt_to('IWorkflowable') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
96 |
req.cnx.commit() |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
97 |
self.assertEqual(adapter.state, 'created') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
98 |
yield req, wf_entity, rset, adapter |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
99 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
100 |
def test_is_in_state(self): |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
101 |
with self.statefull_stuff() as (req, wf_entity, rset, adapter): |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
102 |
for state in ('created', 'validated', 'abandoned'): |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
103 |
selector = is_in_state(state) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
104 |
self.assertEqual(selector(None, req, rset=rset), |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
105 |
state=="created") |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
106 |
|
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
107 |
adapter.fire_transition('validate') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
108 |
req.cnx.commit(); wf_entity.cw_clear_all_caches() |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
109 |
self.assertEqual(adapter.state, 'validated') |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
110 |
|
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
111 |
clear_cache(rset, 'get_entity') |
9582
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9152
diff
changeset
|
112 |
|
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
113 |
selector = is_in_state('created') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
114 |
self.assertEqual(selector(None, req, rset=rset), 0) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
115 |
selector = is_in_state('validated') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
116 |
self.assertEqual(selector(None, req, rset=rset), 1) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
117 |
selector = is_in_state('validated', 'abandoned') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
118 |
self.assertEqual(selector(None, req, rset=rset), 1) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
119 |
selector = is_in_state('abandoned') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
120 |
self.assertEqual(selector(None, req, rset=rset), 0) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
121 |
|
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
122 |
adapter.fire_transition('forsake') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
123 |
req.cnx.commit(); wf_entity.cw_clear_all_caches() |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
124 |
self.assertEqual(adapter.state, 'abandoned') |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
125 |
|
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
126 |
clear_cache(rset, 'get_entity') |
9582
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9152
diff
changeset
|
127 |
|
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
128 |
selector = is_in_state('created') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
129 |
self.assertEqual(selector(None, req, rset=rset), 0) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
130 |
selector = is_in_state('validated') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
131 |
self.assertEqual(selector(None, req, rset=rset), 0) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
132 |
selector = is_in_state('validated', 'abandoned') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
133 |
self.assertEqual(selector(None, req, rset=rset), 1) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
134 |
self.assertEqual(adapter.state, 'abandoned') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
135 |
self.assertEqual(selector(None, req, rset=rset), 1) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
136 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
137 |
def test_is_in_state_unvalid_names(self): |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
138 |
with self.statefull_stuff() as (req, wf_entity, rset, adapter): |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
139 |
selector = is_in_state("unknown") |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
140 |
with self.assertRaises(ValueError) as cm: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
141 |
selector(None, req, rset=rset) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
142 |
self.assertEqual(str(cm.exception), |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
143 |
"wf_test: unknown state(s): unknown") |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
144 |
selector = is_in_state("weird", "unknown", "created", "weird") |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
145 |
with self.assertRaises(ValueError) as cm: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
146 |
selector(None, req, rset=rset) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
147 |
self.assertEqual(str(cm.exception), |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
148 |
"wf_test: unknown state(s): unknown,weird") |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
149 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
150 |
def test_on_transition(self): |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
151 |
with self.statefull_stuff() as (req, wf_entity, rset, adapter): |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
152 |
for transition in ('validate', 'forsake'): |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
153 |
selector = on_transition(transition) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
154 |
self.assertEqual(selector(None, req, rset=rset), 0) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
155 |
|
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
156 |
adapter.fire_transition('validate') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
157 |
req.cnx.commit(); wf_entity.cw_clear_all_caches() |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
158 |
self.assertEqual(adapter.state, 'validated') |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
159 |
|
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
160 |
clear_cache(rset, 'get_entity') |
9582
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9152
diff
changeset
|
161 |
|
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
162 |
selector = on_transition("validate") |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
163 |
self.assertEqual(selector(None, req, rset=rset), 1) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
164 |
selector = on_transition("validate", "forsake") |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
165 |
self.assertEqual(selector(None, req, rset=rset), 1) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
166 |
selector = on_transition("forsake") |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
167 |
self.assertEqual(selector(None, req, rset=rset), 0) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
168 |
|
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
169 |
adapter.fire_transition('forsake') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
170 |
req.cnx.commit(); wf_entity.cw_clear_all_caches() |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
171 |
self.assertEqual(adapter.state, 'abandoned') |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
172 |
|
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
173 |
clear_cache(rset, 'get_entity') |
9582
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9152
diff
changeset
|
174 |
|
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
175 |
selector = on_transition("validate") |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
176 |
self.assertEqual(selector(None, req, rset=rset), 0) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
177 |
selector = on_transition("validate", "forsake") |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
178 |
self.assertEqual(selector(None, req, rset=rset), 1) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
179 |
selector = on_transition("forsake") |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
180 |
self.assertEqual(selector(None, req, rset=rset), 1) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
181 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
182 |
def test_on_transition_unvalid_names(self): |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
183 |
with self.statefull_stuff() as (req, wf_entity, rset, adapter): |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
184 |
selector = on_transition("unknown") |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
185 |
with self.assertRaises(ValueError) as cm: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
186 |
selector(None, req, rset=rset) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
187 |
self.assertEqual(str(cm.exception), |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
188 |
"wf_test: unknown transition(s): unknown") |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
189 |
selector = on_transition("weird", "unknown", "validate", "weird") |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
190 |
with self.assertRaises(ValueError) as cm: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
191 |
selector(None, req, rset=rset) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
192 |
self.assertEqual(str(cm.exception), |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
193 |
"wf_test: unknown transition(s): unknown,weird") |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
194 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
195 |
def test_on_transition_with_no_effect(self): |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
196 |
"""selector will not be triggered with `change_state()`""" |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
197 |
with self.statefull_stuff() as (req, wf_entity, rset, adapter): |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
198 |
adapter.change_state('validated') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
199 |
req.cnx.commit(); wf_entity.cw_clear_all_caches() |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
200 |
self.assertEqual(adapter.state, 'validated') |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
201 |
|
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
202 |
selector = on_transition("validate") |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
203 |
self.assertEqual(selector(None, req, rset=rset), 0) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
204 |
selector = on_transition("validate", "forsake") |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
205 |
self.assertEqual(selector(None, req, rset=rset), 0) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
206 |
selector = on_transition("forsake") |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
207 |
self.assertEqual(selector(None, req, rset=rset), 0) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
208 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
209 |
|
7617
be5f68f9314e
[selectors, test] remove duplicated test and add some for relation_possible selector w/ rqlst
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
210 |
class RelationPossibleTC(CubicWebTC): |
be5f68f9314e
[selectors, test] remove duplicated test and add some for relation_possible selector w/ rqlst
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
211 |
|
be5f68f9314e
[selectors, test] remove duplicated test and add some for relation_possible selector w/ rqlst
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
212 |
def test_rqlst_1(self): |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
213 |
with self.admin_access.web_request() as req: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
214 |
selector = relation_possible('in_group') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
215 |
select = self.vreg.parse(req, 'Any X WHERE X is CWUser').children[0] |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
216 |
score = selector(None, req, rset=1, |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
217 |
select=select, filtered_variable=select.defined_vars['X']) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
218 |
self.assertEqual(score, 1) |
7617
be5f68f9314e
[selectors, test] remove duplicated test and add some for relation_possible selector w/ rqlst
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
219 |
|
be5f68f9314e
[selectors, test] remove duplicated test and add some for relation_possible selector w/ rqlst
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
220 |
def test_rqlst_2(self): |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
221 |
with self.admin_access.web_request() as req: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
222 |
selector = relation_possible('in_group') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
223 |
select = self.vreg.parse(req, 'Any 1, COUNT(X) WHERE X is CWUser, X creation_date XD, ' |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
224 |
'Y creation_date YD, Y is CWGroup ' |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
225 |
'HAVING DAY(XD)=DAY(YD)').children[0] |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
226 |
score = selector(None, req, rset=1, |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
227 |
select=select, filtered_variable=select.defined_vars['X']) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
228 |
self.assertEqual(score, 1) |
7617
be5f68f9314e
[selectors, test] remove duplicated test and add some for relation_possible selector w/ rqlst
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
229 |
|
9152
b0155bfd4e17
Protect against crash in the `relation_possible` predicate with ambiguous relations.
Florent Cayre <florent.cayre@logilab.fr>
parents:
8866
diff
changeset
|
230 |
def test_ambiguous(self): |
b0155bfd4e17
Protect against crash in the `relation_possible` predicate with ambiguous relations.
Florent Cayre <florent.cayre@logilab.fr>
parents:
8866
diff
changeset
|
231 |
# Ambiguous relations are : |
b0155bfd4e17
Protect against crash in the `relation_possible` predicate with ambiguous relations.
Florent Cayre <florent.cayre@logilab.fr>
parents:
8866
diff
changeset
|
232 |
# (Service, fabrique_par, Personne) and (Produit, fabrique_par, Usine) |
b0155bfd4e17
Protect against crash in the `relation_possible` predicate with ambiguous relations.
Florent Cayre <florent.cayre@logilab.fr>
parents:
8866
diff
changeset
|
233 |
# There used to be a crash here with a bad rdef choice in the strict |
b0155bfd4e17
Protect against crash in the `relation_possible` predicate with ambiguous relations.
Florent Cayre <florent.cayre@logilab.fr>
parents:
8866
diff
changeset
|
234 |
# checking case. |
b0155bfd4e17
Protect against crash in the `relation_possible` predicate with ambiguous relations.
Florent Cayre <florent.cayre@logilab.fr>
parents:
8866
diff
changeset
|
235 |
selector = relation_possible('fabrique_par', role='object', |
b0155bfd4e17
Protect against crash in the `relation_possible` predicate with ambiguous relations.
Florent Cayre <florent.cayre@logilab.fr>
parents:
8866
diff
changeset
|
236 |
target_etype='Personne', strict=True) |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
237 |
with self.admin_access.web_request() as req: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
238 |
usine = req.create_entity('Usine', lieu=u'here') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
239 |
score = selector(None, req, rset=usine.as_rset()) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
240 |
self.assertEqual(0, score) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
241 |
|
7617
be5f68f9314e
[selectors, test] remove duplicated test and add some for relation_possible selector w/ rqlst
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7387
diff
changeset
|
242 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
243 |
class MatchUserGroupsTC(CubicWebTC): |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
244 |
def test_owners_group(self): |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
245 |
"""tests usage of 'owners' group with match_user_group""" |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
246 |
class SomeAction(action.Action): |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2773
diff
changeset
|
247 |
__regid__ = 'yo' |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
248 |
category = 'foo' |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
249 |
__select__ = match_user_groups('owners') |
1640 | 250 |
self.vreg._loadedmods[__name__] = {} |
4491
a0f48c31b58a
kill register_appobject_class method, simplifying autoregistration. Update test accordingly (test which manually registers object should also properly call there __register__ method). Drop the disable-appobjects config file entry: no one used it since its introduction years ago.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
251 |
self.vreg.register(SomeAction) |
4490
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
252 |
SomeAction.__registered__(self.vreg['actions']) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7617
diff
changeset
|
253 |
self.assertTrue(SomeAction in self.vreg['actions']['yo'], self.vreg['actions']) |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
254 |
try: |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
255 |
with self.admin_access.web_request() as req: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
256 |
self.create_user(req, 'john') |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
257 |
# login as a simple user |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
258 |
john_access = self.new_access('john') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
259 |
with john_access.web_request() as req: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
260 |
# it should not be possible to use SomeAction not owned objects |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
261 |
rset = req.execute('Any G WHERE G is CWGroup, G name "managers"') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
262 |
self.assertFalse('yo' in dict(self.pactions(req, rset))) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
263 |
# insert a new card, and check that we can use SomeAction on our object |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
264 |
req.execute('INSERT Card C: C title "zoubidou"') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
265 |
req.cnx.commit() |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
266 |
with john_access.web_request() as req: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
267 |
rset = req.execute('Card C WHERE C title "zoubidou"') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
268 |
self.assertTrue('yo' in dict(self.pactions(req, rset)), self.pactions(req, rset)) |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
269 |
# make sure even managers can't use the action |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
270 |
with self.admin_access.web_request() as req: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
271 |
rset = req.execute('Card C WHERE C title "zoubidou"') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
272 |
self.assertFalse('yo' in dict(self.pactions(req, rset))) |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
273 |
finally: |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2773
diff
changeset
|
274 |
del self.vreg[SomeAction.__registry__][SomeAction.__regid__] |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
275 |
|
6348
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
276 |
|
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
277 |
class MultiLinesRsetTC(CubicWebTC): |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
278 |
def setup_database(self): |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
279 |
with self.admin_access.web_request() as req: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
280 |
req.execute('INSERT CWGroup G: G name "group1"') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
281 |
req.execute('INSERT CWGroup G: G name "group2"') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
282 |
req.cnx.commit() |
6348
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
283 |
|
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
284 |
def test_default_op_in_selector(self): |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
285 |
with self.admin_access.web_request() as req: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
286 |
rset = req.execute('Any G WHERE G is CWGroup') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
287 |
expected = len(rset) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
288 |
selector = multi_lines_rset(expected) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
289 |
self.assertEqual(selector(None, req, rset=rset), 1) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
290 |
self.assertEqual(selector(None, req, None), 0) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
291 |
selector = multi_lines_rset(expected + 1) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
292 |
self.assertEqual(selector(None, req, rset=rset), 0) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
293 |
self.assertEqual(selector(None, req, None), 0) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
294 |
selector = multi_lines_rset(expected - 1) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
295 |
self.assertEqual(selector(None, req, rset=rset), 0) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
296 |
self.assertEqual(selector(None, req, None), 0) |
6348
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
297 |
|
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
298 |
def test_without_rset(self): |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
299 |
with self.admin_access.web_request() as req: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
300 |
rset = req.execute('Any G WHERE G is CWGroup') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
301 |
expected = len(rset) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
302 |
selector = multi_lines_rset(expected) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
303 |
self.assertEqual(selector(None, req, None), 0) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
304 |
selector = multi_lines_rset(expected + 1) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
305 |
self.assertEqual(selector(None, req, None), 0) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
306 |
selector = multi_lines_rset(expected - 1) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
307 |
self.assertEqual(selector(None, req, None), 0) |
6348
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
308 |
|
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
309 |
def test_with_operators(self): |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
310 |
with self.admin_access.web_request() as req: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
311 |
rset = req.execute('Any G WHERE G is CWGroup') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
312 |
expected = len(rset) |
6348
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
313 |
|
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
314 |
# Format 'expected', 'operator', 'assert' |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
315 |
testdata = (( expected, eq, 1), |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
316 |
( expected+1, eq, 0), |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
317 |
( expected-1, eq, 0), |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
318 |
( expected, le, 1), |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
319 |
( expected+1, le, 1), |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
320 |
( expected-1, le, 0), |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
321 |
( expected-1, gt, 1), |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
322 |
( expected, gt, 0), |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
323 |
( expected+1, gt, 0), |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
324 |
( expected+1, lt, 1), |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
325 |
( expected, lt, 0), |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
326 |
( expected-1, lt, 0)) |
6348
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
327 |
|
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
328 |
for (expected, operator, assertion) in testdata: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
329 |
selector = multi_lines_rset(expected, operator) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
330 |
yield self.assertEqual, selector(None, req, rset=rset), assertion |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
331 |
|
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
332 |
|
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
333 |
class MatchKwargsTC(TestCase): |
6348
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
334 |
|
7955
f4c97d3c8b93
[selectors]Â match_kwargs and match_form_params selectors both accept a new `once_is_enough` argument (closes #1990438)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
335 |
def test_match_kwargs_default(self): |
f4c97d3c8b93
[selectors]Â match_kwargs and match_form_params selectors both accept a new `once_is_enough` argument (closes #1990438)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
336 |
selector = match_kwargs( set( ('a', 'b') ) ) |
f4c97d3c8b93
[selectors]Â match_kwargs and match_form_params selectors both accept a new `once_is_enough` argument (closes #1990438)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
337 |
self.assertEqual(selector(None, None, a=1, b=2), 2) |
f4c97d3c8b93
[selectors]Â match_kwargs and match_form_params selectors both accept a new `once_is_enough` argument (closes #1990438)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
338 |
self.assertEqual(selector(None, None, a=1), 0) |
f4c97d3c8b93
[selectors]Â match_kwargs and match_form_params selectors both accept a new `once_is_enough` argument (closes #1990438)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
339 |
self.assertEqual(selector(None, None, c=1), 0) |
f4c97d3c8b93
[selectors]Â match_kwargs and match_form_params selectors both accept a new `once_is_enough` argument (closes #1990438)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
340 |
self.assertEqual(selector(None, None, a=1, c=1), 0) |
f4c97d3c8b93
[selectors]Â match_kwargs and match_form_params selectors both accept a new `once_is_enough` argument (closes #1990438)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
341 |
|
f4c97d3c8b93
[selectors]Â match_kwargs and match_form_params selectors both accept a new `once_is_enough` argument (closes #1990438)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
342 |
def test_match_kwargs_any(self): |
f4c97d3c8b93
[selectors]Â match_kwargs and match_form_params selectors both accept a new `once_is_enough` argument (closes #1990438)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
343 |
selector = match_kwargs( set( ('a', 'b') ), mode='any') |
f4c97d3c8b93
[selectors]Â match_kwargs and match_form_params selectors both accept a new `once_is_enough` argument (closes #1990438)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
344 |
self.assertEqual(selector(None, None, a=1, b=2), 2) |
f4c97d3c8b93
[selectors]Â match_kwargs and match_form_params selectors both accept a new `once_is_enough` argument (closes #1990438)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
345 |
self.assertEqual(selector(None, None, a=1), 1) |
f4c97d3c8b93
[selectors]Â match_kwargs and match_form_params selectors both accept a new `once_is_enough` argument (closes #1990438)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
346 |
self.assertEqual(selector(None, None, c=1), 0) |
f4c97d3c8b93
[selectors]Â match_kwargs and match_form_params selectors both accept a new `once_is_enough` argument (closes #1990438)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
347 |
self.assertEqual(selector(None, None, a=1, c=1), 1) |
f4c97d3c8b93
[selectors]Â match_kwargs and match_form_params selectors both accept a new `once_is_enough` argument (closes #1990438)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
348 |
|
6348
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
349 |
|
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
350 |
class ScoreEntityTC(CubicWebTC): |
6869
900cb9b1b687
[tests] new unit tests about score_entity selector (inscore machinery)
Julien Jehannet <julien@smaf.org>
parents:
6348
diff
changeset
|
351 |
|
900cb9b1b687
[tests] new unit tests about score_entity selector (inscore machinery)
Julien Jehannet <julien@smaf.org>
parents:
6348
diff
changeset
|
352 |
def test_intscore_entity_selector(self): |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
353 |
with self.admin_access.web_request() as req: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
354 |
rset = req.execute('Any E WHERE E eid 1') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
355 |
selector = score_entity(lambda x: None) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
356 |
self.assertEqual(selector(None, req, rset=rset), 0) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
357 |
selector = score_entity(lambda x: "something") |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
358 |
self.assertEqual(selector(None, req, rset=rset), 1) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
359 |
selector = score_entity(lambda x: object) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
360 |
self.assertEqual(selector(None, req, rset=rset), 1) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
361 |
rset = req.execute('Any G LIMIT 2 WHERE G is CWGroup') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
362 |
selector = score_entity(lambda x: 10) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
363 |
self.assertEqual(selector(None, req, rset=rset), 20) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
364 |
selector = score_entity(lambda x: 10, mode='any') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
365 |
self.assertEqual(selector(None, req, rset=rset), 10) |
6869
900cb9b1b687
[tests] new unit tests about score_entity selector (inscore machinery)
Julien Jehannet <julien@smaf.org>
parents:
6348
diff
changeset
|
366 |
|
7345
b9eaad6e34c3
[selectors] test/fix rql_condition to make it works when entity is specified via 'entity' keyword argument instead of rset, row and col
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
367 |
def test_rql_condition_entity(self): |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
368 |
with self.admin_access.web_request() as req: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
369 |
selector = rql_condition('X identity U') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
370 |
rset = req.user.as_rset() |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
371 |
self.assertEqual(selector(None, req, rset=rset), 1) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
372 |
self.assertEqual(selector(None, req, entity=req.user), 1) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
373 |
self.assertEqual(selector(None, req), 0) |
6869
900cb9b1b687
[tests] new unit tests about score_entity selector (inscore machinery)
Julien Jehannet <julien@smaf.org>
parents:
6348
diff
changeset
|
374 |
|
7362
b9813c9d32ac
[selectors] enhance rql_condition to make it usable as a condition on request's user
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7345
diff
changeset
|
375 |
def test_rql_condition_user(self): |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
376 |
with self.admin_access.web_request() as req: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
377 |
selector = rql_condition('U login "admin"', user_condition=True) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
378 |
self.assertEqual(selector(None, req), 1) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
379 |
selector = rql_condition('U login "toto"', user_condition=True) |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
380 |
self.assertEqual(selector(None, req), 0) |
7362
b9813c9d32ac
[selectors] enhance rql_condition to make it usable as a condition on request's user
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7345
diff
changeset
|
381 |
|
8858
51fdbbbd07b2
[predicates] fix 'adaptable' implementation, used to return 0 on a rset with individualy adaptable entities of different types. Closes #2709663
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8220
diff
changeset
|
382 |
|
51fdbbbd07b2
[predicates] fix 'adaptable' implementation, used to return 0 on a rset with individualy adaptable entities of different types. Closes #2709663
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8220
diff
changeset
|
383 |
class AdaptablePredicateTC(CubicWebTC): |
51fdbbbd07b2
[predicates] fix 'adaptable' implementation, used to return 0 on a rset with individualy adaptable entities of different types. Closes #2709663
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8220
diff
changeset
|
384 |
|
51fdbbbd07b2
[predicates] fix 'adaptable' implementation, used to return 0 on a rset with individualy adaptable entities of different types. Closes #2709663
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8220
diff
changeset
|
385 |
def test_multiple_entity_types_rset(self): |
51fdbbbd07b2
[predicates] fix 'adaptable' implementation, used to return 0 on a rset with individualy adaptable entities of different types. Closes #2709663
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8220
diff
changeset
|
386 |
class CWUserIWhatever(EntityAdapter): |
51fdbbbd07b2
[predicates] fix 'adaptable' implementation, used to return 0 on a rset with individualy adaptable entities of different types. Closes #2709663
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8220
diff
changeset
|
387 |
__regid__ = 'IWhatever' |
51fdbbbd07b2
[predicates] fix 'adaptable' implementation, used to return 0 on a rset with individualy adaptable entities of different types. Closes #2709663
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8220
diff
changeset
|
388 |
__select__ = is_instance('CWUser') |
51fdbbbd07b2
[predicates] fix 'adaptable' implementation, used to return 0 on a rset with individualy adaptable entities of different types. Closes #2709663
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8220
diff
changeset
|
389 |
class CWGroupIWhatever(EntityAdapter): |
51fdbbbd07b2
[predicates] fix 'adaptable' implementation, used to return 0 on a rset with individualy adaptable entities of different types. Closes #2709663
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8220
diff
changeset
|
390 |
__regid__ = 'IWhatever' |
51fdbbbd07b2
[predicates] fix 'adaptable' implementation, used to return 0 on a rset with individualy adaptable entities of different types. Closes #2709663
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8220
diff
changeset
|
391 |
__select__ = is_instance('CWGroup') |
51fdbbbd07b2
[predicates] fix 'adaptable' implementation, used to return 0 on a rset with individualy adaptable entities of different types. Closes #2709663
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8220
diff
changeset
|
392 |
with self.temporary_appobjects(CWUserIWhatever, CWGroupIWhatever): |
9653
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
393 |
with self.admin_access.web_request() as req: |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
394 |
selector = adaptable('IWhatever') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
395 |
rset = req.execute('Any X WHERE X is IN(CWGroup, CWUser)') |
ac723e09704f
[test] update unittest_predicates to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
396 |
self.assertTrue(selector(None, req, rset=rset)) |
8858
51fdbbbd07b2
[predicates] fix 'adaptable' implementation, used to return 0 on a rset with individualy adaptable entities of different types. Closes #2709663
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8220
diff
changeset
|
397 |
|
10476
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
398 |
|
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
399 |
class MatchFormParamsTC(CubicWebTC): |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
400 |
"""tests for match_form_params predicate""" |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
401 |
|
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
402 |
def test_keyonly_match(self): |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
403 |
"""test standard usage: ``match_form_params('param1', 'param2')`` |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
404 |
|
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
405 |
``param1`` and ``param2`` must be specified in request's form. |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
406 |
""" |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
407 |
web_request = self.admin_access.web_request |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
408 |
vid_selector = match_form_params('vid') |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
409 |
vid_subvid_selector = match_form_params('vid', 'subvid') |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
410 |
# no parameter => KO,KO |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
411 |
with web_request() as req: |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
412 |
self.assertEqual(vid_selector(None, req), 0) |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
413 |
self.assertEqual(vid_subvid_selector(None, req), 0) |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
414 |
# one expected parameter found => OK,KO |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
415 |
with web_request(vid='foo') as req: |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
416 |
self.assertEqual(vid_selector(None, req), 1) |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
417 |
self.assertEqual(vid_subvid_selector(None, req), 0) |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
418 |
# all expected parameters found => OK,OK |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
419 |
with web_request(vid='foo', subvid='bar') as req: |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
420 |
self.assertEqual(vid_selector(None, req), 1) |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
421 |
self.assertEqual(vid_subvid_selector(None, req), 2) |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
422 |
|
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
423 |
def test_keyvalue_match_one_parameter(self): |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
424 |
"""test dict usage: ``match_form_params(param1=value1)`` |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
425 |
|
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
426 |
``param1`` must be specified in the request's form and its value |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
427 |
must be ``value1``. |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
428 |
""" |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
429 |
web_request = self.admin_access.web_request |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
430 |
# test both positional and named parameters |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
431 |
vid_selector = match_form_params(vid='foo') |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
432 |
# no parameter => should fail |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
433 |
with web_request() as req: |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
434 |
self.assertEqual(vid_selector(None, req), 0) |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
435 |
# expected parameter found with expected value => OK |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
436 |
with web_request(vid='foo', subvid='bar') as req: |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
437 |
self.assertEqual(vid_selector(None, req), 1) |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
438 |
# expected parameter found but value is incorrect => KO |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
439 |
with web_request(vid='bar') as req: |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
440 |
self.assertEqual(vid_selector(None, req), 0) |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
441 |
|
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
442 |
def test_keyvalue_match_two_parameters(self): |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
443 |
"""test dict usage: ``match_form_params(param1=value1, param2=value2)`` |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
444 |
|
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
445 |
``param1`` and ``param2`` must be specified in the request's form and |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
446 |
their respective value must be ``value1`` and ``value2``. |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
447 |
""" |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
448 |
web_request = self.admin_access.web_request |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
449 |
vid_subvid_selector = match_form_params(vid='list', subvid='tsearch') |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
450 |
# missing one expected parameter => KO |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
451 |
with web_request(vid='list') as req: |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
452 |
self.assertEqual(vid_subvid_selector(None, req), 0) |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
453 |
# expected parameters found but values are incorrect => KO |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
454 |
with web_request(vid='list', subvid='foo') as req: |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
455 |
self.assertEqual(vid_subvid_selector(None, req), 0) |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
456 |
# expected parameters found and values are correct => OK |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
457 |
with web_request(vid='list', subvid='tsearch') as req: |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
458 |
self.assertEqual(vid_subvid_selector(None, req), 2) |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
459 |
|
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
460 |
def test_keyvalue_multiple_match(self): |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
461 |
"""test dict usage with multiple values |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
462 |
|
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
463 |
i.e. as in ``match_form_params(param1=('value1', 'value2'))`` |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
464 |
|
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
465 |
``param1`` must be specified in the request's form and its value |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
466 |
must be either ``value1`` or ``value2``. |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
467 |
""" |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
468 |
web_request = self.admin_access.web_request |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
469 |
vid_subvid_selector = match_form_params(vid='list', subvid=('tsearch', 'listitem')) |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
470 |
# expected parameters found and values correct => OK |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
471 |
with web_request(vid='list', subvid='tsearch') as req: |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
472 |
self.assertEqual(vid_subvid_selector(None, req), 2) |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
473 |
with web_request(vid='list', subvid='listitem') as req: |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
474 |
self.assertEqual(vid_subvid_selector(None, req), 2) |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
475 |
# expected parameters found but values are incorrect => OK |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
476 |
with web_request(vid='list', subvid='foo') as req: |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
477 |
self.assertEqual(vid_subvid_selector(None, req), 0) |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
478 |
|
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
479 |
def test_invalid_calls(self): |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
480 |
"""checks invalid calls raise a ValueError""" |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
481 |
# mixing named and positional arguments should fail |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
482 |
with self.assertRaises(ValueError) as cm: |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
483 |
match_form_params('list', x='1', y='2') |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
484 |
self.assertEqual(str(cm.exception), |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
485 |
"match_form_params() can't be called with both " |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
486 |
"positional and named arguments") |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
487 |
# using a dict as first and unique argument should fail |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
488 |
with self.assertRaises(ValueError) as cm: |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
489 |
match_form_params({'x': 1}) |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
490 |
self.assertEqual(str(cm.exception), |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
491 |
"match_form_params() positional arguments must be strings") |
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
492 |
|
10884
8a51e160026a
[py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10827
diff
changeset
|
493 |
|
10827
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
494 |
class PaginatedTC(CubicWebTC): |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
495 |
"""tests for paginated_rset predicate""" |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
496 |
|
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
497 |
def setup_database(self): |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
498 |
with self.admin_access.repo_cnx() as cnx: |
10884
8a51e160026a
[py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10827
diff
changeset
|
499 |
for i in range(30): |
10896
ac64eeddd50a
[test] Add missing u''
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10884
diff
changeset
|
500 |
cnx.create_entity('CWGroup', name=u"group%d" % i) |
10827
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
501 |
cnx.commit() |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
502 |
|
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
503 |
def test_paginated_rset(self): |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
504 |
default_nb_pages = 1 |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
505 |
web_request = self.admin_access.web_request |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
506 |
with web_request() as req: |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
507 |
rset = req.execute('Any G WHERE G is CWGroup') |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
508 |
self.assertEqual(len(rset), 34) |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
509 |
with web_request(vid='list', page_size='10') as req: |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
510 |
self.assertEqual(paginated_rset()(None, req, rset), default_nb_pages) |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
511 |
with web_request(vid='list', page_size='20') as req: |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
512 |
self.assertEqual(paginated_rset()(None, req, rset), default_nb_pages) |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
513 |
with web_request(vid='list', page_size='50') as req: |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
514 |
self.assertEqual(paginated_rset()(None, req, rset), 0) |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
515 |
with web_request(vid='list', page_size='10/') as req: |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
516 |
self.assertEqual(paginated_rset()(None, req, rset), 0) |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
517 |
with web_request(vid='list', page_size='.1') as req: |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
518 |
self.assertEqual(paginated_rset()(None, req, rset), 0) |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
519 |
with web_request(vid='list', page_size='not_an_int') as req: |
768d332de17b
[test] test page_size problem (related to #8123231)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
10704
diff
changeset
|
520 |
self.assertEqual(paginated_rset()(None, req, rset), 0) |
10476
62251bfdfd79
[predicates] ExpectedValuePredicate now accepts a dict parameter
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
9668
diff
changeset
|
521 |
|
10884
8a51e160026a
[py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10827
diff
changeset
|
522 |
|
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
523 |
if __name__ == '__main__': |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
524 |
unittest_main() |