author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 13 Sep 2010 14:48:29 +0200 | |
branch | stable |
changeset 6224 | 1f4beef3962d |
parent 6046 | 3fd4a34c4a09 |
child 6340 | 470d8e828fda |
permissions | -rw-r--r-- |
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
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
20 |
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
|
21 |
|
5561
58b05c314443
[selectors] ensure adaptable('IDownloadable') takes precedence over implements('Any')
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
22 |
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
|
23 |
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
|
24 |
from cubicweb.appobject import Selector, AndSelector, OrSelector |
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
|
25 |
from cubicweb.selectors import is_instance, adaptable, match_user_groups |
779
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
26 |
from cubicweb.interfaces import IDownloadable |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
27 |
from cubicweb.web import action |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
28 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
29 |
class _1_(Selector): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
30 |
def __call__(self, *args, **kwargs): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
31 |
return 1 |
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 _0_(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 0 |
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 |
def _2_(*args, **kwargs): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
38 |
return 2 |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
39 |
|
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 |
class SelectorsTC(TestCase): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
42 |
def test_basic_and(self): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
43 |
selector = _1_() & _1_() |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
44 |
self.assertEquals(selector(None), 2) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
45 |
selector = _1_() & _0_() |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
46 |
self.assertEquals(selector(None), 0) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
47 |
selector = _0_() & _1_() |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
48 |
self.assertEquals(selector(None), 0) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
49 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
50 |
def test_basic_or(self): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
51 |
selector = _1_() | _1_() |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
52 |
self.assertEquals(selector(None), 1) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
53 |
selector = _1_() | _0_() |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
54 |
self.assertEquals(selector(None), 1) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
55 |
selector = _0_() | _1_() |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
56 |
self.assertEquals(selector(None), 1) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
57 |
selector = _0_() | _0_() |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
58 |
self.assertEquals(selector(None), 0) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
59 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
60 |
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
|
61 |
selector = _1_() & _2_ |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
62 |
self.assertEquals(selector(None), 3) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
63 |
selector = _2_ & _1_() |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
64 |
self.assertEquals(selector(None), 3) |
1473 | 65 |
|
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
66 |
def test_three_and(self): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
67 |
selector = _1_() & _1_() & _1_() |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
68 |
self.assertEquals(selector(None), 3) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
69 |
selector = _1_() & _0_() & _1_() |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
70 |
self.assertEquals(selector(None), 0) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
71 |
selector = _0_() & _1_() & _1_() |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
72 |
self.assertEquals(selector(None), 0) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
73 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
74 |
def test_three_or(self): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
75 |
selector = _1_() | _1_() | _1_() |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
76 |
self.assertEquals(selector(None), 1) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
77 |
selector = _1_() | _0_() | _1_() |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
78 |
self.assertEquals(selector(None), 1) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
79 |
selector = _0_() | _1_() | _1_() |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
80 |
self.assertEquals(selector(None), 1) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
81 |
selector = _0_() | _0_() | _0_() |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
82 |
self.assertEquals(selector(None), 0) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
83 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
84 |
def test_composition(self): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
85 |
selector = (_1_() & _1_()) & (_1_() & _1_()) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
86 |
self.failUnless(isinstance(selector, AndSelector)) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
87 |
self.assertEquals(len(selector.selectors), 4) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
88 |
self.assertEquals(selector(None), 4) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
89 |
selector = (_1_() & _0_()) | (_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, OrSelector)) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
91 |
self.assertEquals(len(selector.selectors), 2) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
92 |
self.assertEquals(selector(None), 2) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
93 |
|
779
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
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
|
99 |
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
|
100 |
self.assertIs(csel.search_selector(is_instance), sel) |
1473 | 101 |
|
5373
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
102 |
def test_inplace_and(self): |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
103 |
selector = _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
104 |
selector &= _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
105 |
selector &= _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
106 |
self.assertEquals(selector(None), 3) |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
107 |
selector = _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
108 |
selector &= _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
109 |
selector &= _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
110 |
self.assertEquals(selector(None), 0) |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
111 |
selector = _0_() |
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_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
114 |
self.assertEquals(selector(None), 0) |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
115 |
selector = _0_() |
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 &= _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
118 |
self.assertEquals(selector(None), 0) |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
119 |
|
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
120 |
def test_inplace_or(self): |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
121 |
selector = _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
122 |
selector |= _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
123 |
selector |= _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
124 |
self.assertEquals(selector(None), 1) |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
125 |
selector = _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
126 |
selector |= _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
127 |
selector |= _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
128 |
self.assertEquals(selector(None), 1) |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
129 |
selector = _0_() |
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_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
132 |
self.assertEquals(selector(None), 1) |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
133 |
selector = _0_() |
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 |= _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
136 |
self.assertEquals(selector(None), 0) |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
137 |
|
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
138 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
139 |
class ImplementsSelectorTC(CubicWebTC): |
779
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
140 |
def test_etype_priority(self): |
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
141 |
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
|
142 |
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
|
143 |
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
|
144 |
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
|
145 |
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
|
146 |
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
|
147 |
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
|
148 |
self.failUnless(filescore > idownscore, (filescore, idownscore)) |
1473 | 149 |
|
150 |
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
|
151 |
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
|
152 |
self.failIf(is_instance('Societe').score_class(cls, self.request())) |
1473 | 153 |
|
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
|
154 |
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
|
155 |
cls = self.vreg['etypes'].etype_class('Transition') |
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
|
156 |
self.assertEquals(is_instance('BaseTransition').score_class(cls, self.request()), |
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
|
157 |
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
|
158 |
|
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
159 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
160 |
class MatchUserGroupsTC(CubicWebTC): |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
161 |
def test_owners_group(self): |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
162 |
"""tests usage of 'owners' group with match_user_group""" |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
163 |
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
|
164 |
__regid__ = 'yo' |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
165 |
category = 'foo' |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
166 |
__select__ = match_user_groups('owners') |
1640 | 167 |
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
|
168 |
self.vreg.register(SomeAction) |
4490
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
169 |
SomeAction.__registered__(self.vreg['actions']) |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
170 |
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
|
171 |
try: |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
172 |
# login as a simple user |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
173 |
self.create_user('john') |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
174 |
self.login('john') |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
175 |
# 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
|
176 |
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
|
177 |
rset = req.execute('Any G WHERE G is CWGroup, G name "managers"') |
1640 | 178 |
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
|
179 |
# 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
|
180 |
self.execute('INSERT Card C: C title "zoubidou"') |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
181 |
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
|
182 |
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
|
183 |
rset = req.execute('Card C WHERE C title "zoubidou"') |
1640 | 184 |
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
|
185 |
# make sure even managers can't use the action |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
186 |
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
|
187 |
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
|
188 |
rset = req.execute('Card C WHERE C title "zoubidou"') |
1640 | 189 |
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
|
190 |
finally: |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2773
diff
changeset
|
191 |
del self.vreg[SomeAction.__registry__][SomeAction.__regid__] |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
192 |
|
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
193 |
if __name__ == '__main__': |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
194 |
unittest_main() |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
195 |