author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 01 Jul 2011 11:51:04 +0200 | |
changeset 7595 | 83872394b5d9 |
parent 7387 | d240cff2d8ba |
child 7617 | be5f68f9314e |
permissions | -rw-r--r-- |
6981
d1a279ece4a0
[test] missing future import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6919
diff
changeset
|
1 |
# copyright 2003-2011 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""" |
6981
d1a279ece4a0
[test] missing future import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6919
diff
changeset
|
19 |
from __future__ import with_statement |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
20 |
|
6348
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
21 |
from operator import eq, lt, le, gt |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
22 |
from logilab.common.testlib import TestCase, unittest_main |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
23 |
|
5561
58b05c314443
[selectors] ensure adaptable('IDownloadable') takes precedence over implements('Any')
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
24 |
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
|
25 |
from cubicweb.devtools.testlib import CubicWebTC |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
26 |
from cubicweb.appobject import Selector, AndSelector, OrSelector |
6348
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
27 |
from cubicweb.selectors import (is_instance, adaptable, match_user_groups, |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
28 |
multi_lines_rset, score_entity, is_in_state, |
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
|
29 |
on_transition, rql_condition) |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
30 |
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
|
31 |
|
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
32 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
33 |
class _1_(Selector): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
34 |
def __call__(self, *args, **kwargs): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
35 |
return 1 |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
36 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
37 |
class _0_(Selector): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
38 |
def __call__(self, *args, **kwargs): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
39 |
return 0 |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
40 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
41 |
def _2_(*args, **kwargs): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
42 |
return 2 |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
43 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
44 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
45 |
class SelectorsTC(TestCase): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
46 |
def test_basic_and(self): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
47 |
selector = _1_() & _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
48 |
self.assertEqual(selector(None), 2) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
49 |
selector = _1_() & _0_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
50 |
self.assertEqual(selector(None), 0) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
51 |
selector = _0_() & _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
52 |
self.assertEqual(selector(None), 0) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
53 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
54 |
def test_basic_or(self): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
55 |
selector = _1_() | _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
56 |
self.assertEqual(selector(None), 1) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
57 |
selector = _1_() | _0_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
58 |
self.assertEqual(selector(None), 1) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
59 |
selector = _0_() | _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
60 |
self.assertEqual(selector(None), 1) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
61 |
selector = _0_() | _0_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
62 |
self.assertEqual(selector(None), 0) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
63 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
64 |
def test_selector_and_function(self): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
65 |
selector = _1_() & _2_ |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
66 |
self.assertEqual(selector(None), 3) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
67 |
selector = _2_ & _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
68 |
self.assertEqual(selector(None), 3) |
1473 | 69 |
|
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
70 |
def test_three_and(self): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
71 |
selector = _1_() & _1_() & _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
72 |
self.assertEqual(selector(None), 3) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
73 |
selector = _1_() & _0_() & _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
74 |
self.assertEqual(selector(None), 0) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
75 |
selector = _0_() & _1_() & _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
76 |
self.assertEqual(selector(None), 0) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
77 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
78 |
def test_three_or(self): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
79 |
selector = _1_() | _1_() | _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
80 |
self.assertEqual(selector(None), 1) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
81 |
selector = _1_() | _0_() | _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
82 |
self.assertEqual(selector(None), 1) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
83 |
selector = _0_() | _1_() | _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
84 |
self.assertEqual(selector(None), 1) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
85 |
selector = _0_() | _0_() | _0_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
86 |
self.assertEqual(selector(None), 0) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
87 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
88 |
def test_composition(self): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
89 |
selector = (_1_() & _1_()) & (_1_() & _1_()) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
90 |
self.failUnless(isinstance(selector, AndSelector)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
91 |
self.assertEqual(len(selector.selectors), 4) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
92 |
self.assertEqual(selector(None), 4) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
93 |
selector = (_1_() & _0_()) | (_1_() & _1_()) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
94 |
self.failUnless(isinstance(selector, OrSelector)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
95 |
self.assertEqual(len(selector.selectors), 2) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
96 |
self.assertEqual(selector(None), 2) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
97 |
|
779
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
98 |
def test_search_selectors(self): |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5561
diff
changeset
|
99 |
sel = is_instance('something') |
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5561
diff
changeset
|
100 |
self.assertIs(sel.search_selector(is_instance), sel) |
779
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
101 |
csel = AndSelector(sel, Selector()) |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5561
diff
changeset
|
102 |
self.assertIs(csel.search_selector(is_instance), sel) |
779
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
103 |
csel = AndSelector(Selector(), sel) |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5561
diff
changeset
|
104 |
self.assertIs(csel.search_selector(is_instance), sel) |
7387
d240cff2d8ba
[hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7368
diff
changeset
|
105 |
self.assertIs(csel.search_selector((AndSelector, OrSelector)), csel) |
d240cff2d8ba
[hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7368
diff
changeset
|
106 |
self.assertIs(csel.search_selector((OrSelector, AndSelector)), csel) |
d240cff2d8ba
[hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7368
diff
changeset
|
107 |
self.assertIs(csel.search_selector((is_instance, score_entity)), sel) |
d240cff2d8ba
[hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7368
diff
changeset
|
108 |
self.assertIs(csel.search_selector((score_entity, is_instance)), sel) |
1473 | 109 |
|
5373
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
110 |
def test_inplace_and(self): |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
111 |
selector = _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
112 |
selector &= _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
113 |
selector &= _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
114 |
self.assertEqual(selector(None), 3) |
5373
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
115 |
selector = _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
116 |
selector &= _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
117 |
selector &= _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
118 |
self.assertEqual(selector(None), 0) |
5373
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
119 |
selector = _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
120 |
selector &= _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
121 |
selector &= _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
122 |
self.assertEqual(selector(None), 0) |
5373
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
123 |
selector = _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
124 |
selector &= _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
125 |
selector &= _0_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
126 |
self.assertEqual(selector(None), 0) |
5373
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
127 |
|
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
128 |
def test_inplace_or(self): |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
129 |
selector = _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
130 |
selector |= _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
131 |
selector |= _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
132 |
self.assertEqual(selector(None), 1) |
5373
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
133 |
selector = _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
134 |
selector |= _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
135 |
selector |= _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
136 |
self.assertEqual(selector(None), 1) |
5373
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
137 |
selector = _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
138 |
selector |= _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
139 |
selector |= _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
140 |
self.assertEqual(selector(None), 1) |
5373
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
141 |
selector = _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
142 |
selector |= _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
143 |
selector |= _0_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
144 |
self.assertEqual(selector(None), 0) |
5373
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
145 |
|
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
146 |
|
6908
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
147 |
class IsInStateSelectorTC(CubicWebTC): |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
148 |
def setup_database(self): |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
149 |
wf = self.shell().add_workflow("testwf", 'StateFull', default=True) |
6908
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
150 |
initial = wf.add_state(u'initial', initial=True) |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
151 |
final = wf.add_state(u'final') |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
152 |
wf.add_transition(u'forward', (initial,), final) |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
153 |
|
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
154 |
def test_initial_state(self): |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
155 |
req = self.request() |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
156 |
entity = req.create_entity('StateFull') |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
157 |
selector = is_in_state(u'initial') |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
158 |
self.commit() |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
159 |
score = selector(entity.__class__, None, entity=entity) |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
160 |
self.assertEqual(score, 1) |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
161 |
|
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
162 |
def test_final_state(self): |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
163 |
req = self.request() |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
164 |
entity = req.create_entity('StateFull') |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
165 |
selector = is_in_state(u'initial') |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
166 |
self.commit() |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
167 |
entity.cw_adapt_to('IWorkflowable').fire_transition(u'forward') |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
168 |
self.commit() |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
169 |
score = selector(entity.__class__, None, entity=entity) |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
170 |
self.assertEqual(score, 0) |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
171 |
selector = is_in_state(u'final') |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
172 |
score = selector(entity.__class__, None, entity=entity) |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
173 |
self.assertEqual(score, 1) |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6885
diff
changeset
|
174 |
|
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
175 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
176 |
class ImplementsSelectorTC(CubicWebTC): |
779
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
177 |
def test_etype_priority(self): |
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
178 |
req = self.request() |
5561
58b05c314443
[selectors] ensure adaptable('IDownloadable') takes precedence over implements('Any')
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
179 |
f = req.create_entity('File', data_name=u'hop.txt', data=Binary('hop')) |
58b05c314443
[selectors] ensure adaptable('IDownloadable') takes precedence over implements('Any')
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
180 |
rset = f.as_rset() |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5561
diff
changeset
|
181 |
anyscore = is_instance('Any')(f.__class__, req, rset=rset) |
5561
58b05c314443
[selectors] ensure adaptable('IDownloadable') takes precedence over implements('Any')
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
182 |
idownscore = adaptable('IDownloadable')(f.__class__, req, rset=rset) |
779
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
183 |
self.failUnless(idownscore > anyscore, (idownscore, anyscore)) |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5561
diff
changeset
|
184 |
filescore = is_instance('File')(f.__class__, req, rset=rset) |
779
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
185 |
self.failUnless(filescore > idownscore, (filescore, idownscore)) |
1473 | 186 |
|
187 |
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
|
188 |
cls = self.vreg['etypes'].etype_class('Personne') |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5561
diff
changeset
|
189 |
self.failIf(is_instance('Societe').score_class(cls, self.request())) |
1473 | 190 |
|
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
|
191 |
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
|
192 |
cls = self.vreg['etypes'].etype_class('Transition') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
193 |
self.assertEqual(is_instance('BaseTransition').score_class(cls, self.request()), |
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
|
194 |
3) |
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
|
195 |
|
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
196 |
|
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
197 |
class WorkflowSelectorTC(CubicWebTC): |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
198 |
def _commit(self): |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
199 |
self.commit() |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
200 |
self.wf_entity.cw_clear_all_caches() |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
201 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
202 |
def setup_database(self): |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
203 |
wf = self.shell().add_workflow("wf_test", 'StateFull', default=True) |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
204 |
created = wf.add_state('created', initial=True) |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
205 |
validated = wf.add_state('validated') |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
206 |
abandoned = wf.add_state('abandoned') |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
207 |
wf.add_transition('validate', created, validated, ('managers',)) |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
208 |
wf.add_transition('forsake', (created, validated,), abandoned, ('managers',)) |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
209 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
210 |
def setUp(self): |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
211 |
super(WorkflowSelectorTC, self).setUp() |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
212 |
self.req = self.request() |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
213 |
self.wf_entity = self.req.create_entity('StateFull', name=u'') |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
214 |
self.rset = self.wf_entity.as_rset() |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
215 |
self.adapter = self.wf_entity.cw_adapt_to('IWorkflowable') |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
216 |
self._commit() |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
217 |
self.assertEqual(self.adapter.state, 'created') |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
218 |
# enable debug mode to state/transition validation on the fly |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
219 |
self.vreg.config.debugmode = True |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
220 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
221 |
def tearDown(self): |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
222 |
self.vreg.config.debugmode = False |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
223 |
super(WorkflowSelectorTC, self).tearDown() |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
224 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
225 |
def test_is_in_state(self): |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
226 |
for state in ('created', 'validated', 'abandoned'): |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
227 |
selector = is_in_state(state) |
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
|
228 |
self.assertEqual(selector(None, self.req, rset=self.rset), |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
229 |
state=="created") |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
230 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
231 |
self.adapter.fire_transition('validate') |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
232 |
self._commit() |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
233 |
self.assertEqual(self.adapter.state, 'validated') |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
234 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
235 |
selector = is_in_state('created') |
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
|
236 |
self.assertEqual(selector(None, self.req, rset=self.rset), 0) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
237 |
selector = is_in_state('validated') |
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
|
238 |
self.assertEqual(selector(None, self.req, rset=self.rset), 1) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
239 |
selector = is_in_state('validated', 'abandoned') |
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
|
240 |
self.assertEqual(selector(None, self.req, rset=self.rset), 1) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
241 |
selector = is_in_state('abandoned') |
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
|
242 |
self.assertEqual(selector(None, self.req, rset=self.rset), 0) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
243 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
244 |
self.adapter.fire_transition('forsake') |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
245 |
self._commit() |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
246 |
self.assertEqual(self.adapter.state, 'abandoned') |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
247 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
248 |
selector = is_in_state('created') |
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
|
249 |
self.assertEqual(selector(None, self.req, rset=self.rset), 0) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
250 |
selector = is_in_state('validated') |
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
|
251 |
self.assertEqual(selector(None, self.req, rset=self.rset), 0) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
252 |
selector = is_in_state('validated', 'abandoned') |
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
|
253 |
self.assertEqual(selector(None, self.req, rset=self.rset), 1) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
254 |
self.assertEqual(self.adapter.state, 'abandoned') |
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
|
255 |
self.assertEqual(selector(None, self.req, rset=self.rset), 1) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
256 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
257 |
def test_is_in_state_unvalid_names(self): |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
258 |
selector = is_in_state("unknown") |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
259 |
with self.assertRaises(ValueError) as cm: |
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
|
260 |
selector(None, self.req, rset=self.rset) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
261 |
self.assertEqual(str(cm.exception), |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
262 |
"wf_test: unknown state(s): unknown") |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
263 |
selector = is_in_state("weird", "unknown", "created", "weird") |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
264 |
with self.assertRaises(ValueError) as cm: |
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
|
265 |
selector(None, self.req, rset=self.rset) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
266 |
self.assertEqual(str(cm.exception), |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
267 |
"wf_test: unknown state(s): unknown,weird") |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
268 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
269 |
def test_on_transition(self): |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
270 |
for transition in ('validate', 'forsake'): |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
271 |
selector = on_transition(transition) |
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
|
272 |
self.assertEqual(selector(None, self.req, rset=self.rset), 0) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
273 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
274 |
self.adapter.fire_transition('validate') |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
275 |
self._commit() |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
276 |
self.assertEqual(self.adapter.state, 'validated') |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
277 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
278 |
selector = on_transition("validate") |
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
|
279 |
self.assertEqual(selector(None, self.req, rset=self.rset), 1) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
280 |
selector = on_transition("validate", "forsake") |
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
|
281 |
self.assertEqual(selector(None, self.req, rset=self.rset), 1) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
282 |
selector = on_transition("forsake") |
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
|
283 |
self.assertEqual(selector(None, self.req, rset=self.rset), 0) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
284 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
285 |
self.adapter.fire_transition('forsake') |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
286 |
self._commit() |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
287 |
self.assertEqual(self.adapter.state, 'abandoned') |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
288 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
289 |
selector = on_transition("validate") |
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
|
290 |
self.assertEqual(selector(None, self.req, rset=self.rset), 0) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
291 |
selector = on_transition("validate", "forsake") |
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
|
292 |
self.assertEqual(selector(None, self.req, rset=self.rset), 1) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
293 |
selector = on_transition("forsake") |
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
|
294 |
self.assertEqual(selector(None, self.req, rset=self.rset), 1) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
295 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
296 |
def test_on_transition_unvalid_names(self): |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
297 |
selector = on_transition("unknown") |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
298 |
with self.assertRaises(ValueError) as cm: |
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
|
299 |
selector(None, self.req, rset=self.rset) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
300 |
self.assertEqual(str(cm.exception), |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
301 |
"wf_test: unknown transition(s): unknown") |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
302 |
selector = on_transition("weird", "unknown", "validate", "weird") |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
303 |
with self.assertRaises(ValueError) as cm: |
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
|
304 |
selector(None, self.req, rset=self.rset) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
305 |
self.assertEqual(str(cm.exception), |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
306 |
"wf_test: unknown transition(s): unknown,weird") |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
307 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
308 |
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
|
309 |
"""selector will not be triggered with `change_state()`""" |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
310 |
self.adapter.change_state('validated') |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
311 |
self._commit() |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
312 |
self.assertEqual(self.adapter.state, 'validated') |
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
313 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
314 |
selector = on_transition("validate") |
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
|
315 |
self.assertEqual(selector(None, self.req, rset=self.rset), 0) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
316 |
selector = on_transition("validate", "forsake") |
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
|
317 |
self.assertEqual(selector(None, self.req, rset=self.rset), 0) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
318 |
selector = on_transition("forsake") |
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
|
319 |
self.assertEqual(selector(None, self.req, rset=self.rset), 0) |
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
320 |
|
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
321 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
322 |
class MatchUserGroupsTC(CubicWebTC): |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
323 |
def test_owners_group(self): |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
324 |
"""tests usage of 'owners' group with match_user_group""" |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
325 |
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
|
326 |
__regid__ = 'yo' |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
327 |
category = 'foo' |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
328 |
__select__ = match_user_groups('owners') |
1640 | 329 |
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
|
330 |
self.vreg.register(SomeAction) |
4490
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
331 |
SomeAction.__registered__(self.vreg['actions']) |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
332 |
self.failUnless(SomeAction in self.vreg['actions']['yo'], self.vreg['actions']) |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
333 |
try: |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
334 |
# login as a simple user |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6981
diff
changeset
|
335 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6981
diff
changeset
|
336 |
self.create_user(req, 'john') |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
337 |
self.login('john') |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
338 |
# it should not be possible to use SomeAction not owned objects |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2773
diff
changeset
|
339 |
req = self.request() |
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2773
diff
changeset
|
340 |
rset = req.execute('Any G WHERE G is CWGroup, G name "managers"') |
1640 | 341 |
self.failIf('yo' in dict(self.pactions(req, rset))) |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
342 |
# insert a new card, and check that we can use SomeAction on our object |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
343 |
self.execute('INSERT Card C: C title "zoubidou"') |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
344 |
self.commit() |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2773
diff
changeset
|
345 |
req = self.request() |
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2773
diff
changeset
|
346 |
rset = req.execute('Card C WHERE C title "zoubidou"') |
1640 | 347 |
self.failUnless('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
|
348 |
# make sure even managers can't use the action |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
349 |
self.restore_connection() |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2773
diff
changeset
|
350 |
req = self.request() |
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2773
diff
changeset
|
351 |
rset = req.execute('Card C WHERE C title "zoubidou"') |
1640 | 352 |
self.failIf('yo' in dict(self.pactions(req, rset))) |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
353 |
finally: |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2773
diff
changeset
|
354 |
del self.vreg[SomeAction.__registry__][SomeAction.__regid__] |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
355 |
|
6348
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
356 |
|
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
357 |
class MultiLinesRsetSelectorTC(CubicWebTC): |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
358 |
def setUp(self): |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
359 |
super(MultiLinesRsetSelectorTC, self).setUp() |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
360 |
self.req = self.request() |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
361 |
self.req.execute('INSERT CWGroup G: G name "group1"') |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
362 |
self.req.execute('INSERT CWGroup G: G name "group2"') |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
363 |
self.commit() |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
364 |
self.rset = self.req.execute('Any G WHERE G is CWGroup') |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
365 |
|
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
366 |
def test_default_op_in_selector(self): |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
367 |
expected = len(self.rset) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
368 |
selector = multi_lines_rset(expected) |
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
|
369 |
self.assertEqual(selector(None, self.req, rset=self.rset), 1) |
6348
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
370 |
self.assertEqual(selector(None, self.req, None), 0) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
371 |
selector = multi_lines_rset(expected + 1) |
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
|
372 |
self.assertEqual(selector(None, self.req, rset=self.rset), 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
|
373 |
self.assertEqual(selector(None, self.req, None), 0) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
374 |
selector = multi_lines_rset(expected - 1) |
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
|
375 |
self.assertEqual(selector(None, self.req, rset=self.rset), 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
|
376 |
self.assertEqual(selector(None, self.req, None), 0) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
377 |
|
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
378 |
def test_without_rset(self): |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
379 |
expected = len(self.rset) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
380 |
selector = multi_lines_rset(expected) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
381 |
self.assertEqual(selector(None, self.req, None), 0) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
382 |
selector = multi_lines_rset(expected + 1) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
383 |
self.assertEqual(selector(None, self.req, None), 0) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
384 |
selector = multi_lines_rset(expected - 1) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
385 |
self.assertEqual(selector(None, self.req, None), 0) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
386 |
|
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
387 |
def test_with_operators(self): |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
388 |
expected = len(self.rset) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
389 |
|
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
390 |
# Format 'expected', 'operator', 'assert' |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
391 |
testdata = (( expected, eq, 1), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
392 |
( expected+1, eq, 0), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
393 |
( expected-1, eq, 0), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
394 |
( expected, le, 1), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
395 |
( expected+1, le, 1), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
396 |
( expected-1, le, 0), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
397 |
( expected-1, gt, 1), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
398 |
( expected, gt, 0), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
399 |
( expected+1, gt, 0), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
400 |
( expected+1, lt, 1), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
401 |
( expected, lt, 0), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
402 |
( expected-1, lt, 0)) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
403 |
|
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
404 |
for (expected, operator, assertion) in testdata: |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
405 |
selector = multi_lines_rset(expected, operator) |
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
|
406 |
yield self.assertEqual, selector(None, self.req, rset=self.rset), assertion |
6348
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
407 |
|
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
408 |
|
6869
900cb9b1b687
[tests] new unit tests about score_entity selector (inscore machinery)
Julien Jehannet <julien@smaf.org>
parents:
6348
diff
changeset
|
409 |
class ScoreEntitySelectorTC(CubicWebTC): |
900cb9b1b687
[tests] new unit tests about score_entity selector (inscore machinery)
Julien Jehannet <julien@smaf.org>
parents:
6348
diff
changeset
|
410 |
|
900cb9b1b687
[tests] new unit tests about score_entity selector (inscore machinery)
Julien Jehannet <julien@smaf.org>
parents:
6348
diff
changeset
|
411 |
def test_intscore_entity_selector(self): |
6874
611aa2074a5b
[test] fix typo
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6869
diff
changeset
|
412 |
req = self.request() |
6885
ea4baa1d16d6
[test] fix score_entity test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6874
diff
changeset
|
413 |
rset = req.execute('Any E WHERE E eid 1') |
6869
900cb9b1b687
[tests] new unit tests about score_entity selector (inscore machinery)
Julien Jehannet <julien@smaf.org>
parents:
6348
diff
changeset
|
414 |
selector = score_entity(lambda x: None) |
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
|
415 |
self.assertEqual(selector(None, req, rset=rset), 0) |
6869
900cb9b1b687
[tests] new unit tests about score_entity selector (inscore machinery)
Julien Jehannet <julien@smaf.org>
parents:
6348
diff
changeset
|
416 |
selector = score_entity(lambda x: "something") |
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
|
417 |
self.assertEqual(selector(None, req, rset=rset), 1) |
6869
900cb9b1b687
[tests] new unit tests about score_entity selector (inscore machinery)
Julien Jehannet <julien@smaf.org>
parents:
6348
diff
changeset
|
418 |
selector = score_entity(lambda x: object) |
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
|
419 |
self.assertEqual(selector(None, req, rset=rset), 1) |
6869
900cb9b1b687
[tests] new unit tests about score_entity selector (inscore machinery)
Julien Jehannet <julien@smaf.org>
parents:
6348
diff
changeset
|
420 |
rset = req.execute('Any G LIMIT 2 WHERE G is CWGroup') |
900cb9b1b687
[tests] new unit tests about score_entity selector (inscore machinery)
Julien Jehannet <julien@smaf.org>
parents:
6348
diff
changeset
|
421 |
selector = score_entity(lambda x: 10) |
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
|
422 |
self.assertEqual(selector(None, req, rset=rset), 20) |
6869
900cb9b1b687
[tests] new unit tests about score_entity selector (inscore machinery)
Julien Jehannet <julien@smaf.org>
parents:
6348
diff
changeset
|
423 |
selector = score_entity(lambda x: 10, once_is_enough=True) |
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
|
424 |
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
|
425 |
|
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
|
426 |
def test_rql_condition_entity(self): |
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
|
427 |
req = self.request() |
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
|
428 |
selector = rql_condition('X identity U') |
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
|
429 |
rset = req.user.as_rset() |
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
|
430 |
self.assertEqual(selector(None, req, rset=rset), 1) |
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
|
431 |
self.assertEqual(selector(None, req, entity=req.user), 1) |
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
|
432 |
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
|
433 |
|
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
|
434 |
def test_rql_condition_user(self): |
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
|
435 |
req = self.request() |
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
|
436 |
selector = rql_condition('U login "admin"', user_condition=True) |
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
|
437 |
self.assertEqual(selector(None, req), 1) |
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
|
438 |
selector = rql_condition('U login "toto"', user_condition=True) |
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
|
439 |
self.assertEqual(selector(None, req), 0) |
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
|
440 |
|
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
441 |
if __name__ == '__main__': |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
442 |
unittest_main() |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
443 |