author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 05 Jul 2011 10:54:52 +0200 | |
changeset 7618 | 5395007c415c |
parent 7615 | e5ad51352eb3 |
child 7624 | ce020f90fb8e |
permissions | -rw-r--r-- |
7615
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
1 |
from logilab.common.date import datetime2ticks |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
2 |
from cubicweb.devtools.testlib import CubicWebTC |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
3 |
from cubicweb.web import facet |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
4 |
|
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
5 |
class BaseFacetTC(CubicWebTC): |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
6 |
|
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
7 |
def prepare_rqlst(self): |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
8 |
req = self.request() |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
9 |
rset = self.execute('CWUser X') |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
10 |
rqlst = rset.syntax_tree().copy() |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
11 |
filtered_variable, baserql = facet.init_facets(rset, rqlst.children[0]) |
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
12 |
self.assertEqual(filtered_variable.name, 'X') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6338
diff
changeset
|
13 |
self.assertEqual(baserql, 'Any X WHERE X is CWUser') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6338
diff
changeset
|
14 |
self.assertEqual(rqlst.as_string(), 'DISTINCT Any WHERE X is CWUser') |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
15 |
return req, rset, rqlst, filtered_variable |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
16 |
|
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
17 |
def _in_group_facet(self, cls=facet.RelationFacet, no_relation=False): |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
18 |
req, rset, rqlst, filtered_variable = self.prepare_rqlst() |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
19 |
cls.no_relation = no_relation |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
20 |
f = cls(req, rset=rset, select=rqlst.children[0], |
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
21 |
filtered_variable=filtered_variable) |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
22 |
f.__regid__ = 'in_group' |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
23 |
f.rtype = 'in_group' |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
24 |
f.role = 'subject' |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
25 |
f.target_attr = 'name' |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
26 |
guests, managers = [eid for eid, in self.execute('CWGroup G ORDERBY GN ' |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
27 |
'WHERE G name GN, G name IN ("guests", "managers")')] |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
28 |
groups = [eid for eid, in self.execute('CWGroup G ORDERBY GN ' |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
29 |
'WHERE G name GN, G name IN ("guests", "managers")')] |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
30 |
return f, groups |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
31 |
|
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
32 |
def test_relation_simple(self): |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
33 |
f, (guests, managers) = self._in_group_facet() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6338
diff
changeset
|
34 |
self.assertEqual(f.vocabulary(), |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
35 |
[(u'guests', guests), (u'managers', managers)]) |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
36 |
# ensure rqlst is left unmodified |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
37 |
self.assertEqual(f.select.as_string(), 'DISTINCT Any WHERE X is CWUser') |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
38 |
#rqlst = rset.syntax_tree() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6338
diff
changeset
|
39 |
self.assertEqual(f.possible_values(), |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
40 |
[str(guests), str(managers)]) |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
41 |
# ensure rqlst is left unmodified |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
42 |
self.assertEqual(f.select.as_string(), 'DISTINCT Any WHERE X is CWUser') |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
43 |
f._cw.form[f.__regid__] = str(guests) |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
44 |
f.add_rql_restrictions() |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
45 |
# selection is cluttered because rqlst has been prepared for facet (it |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
46 |
# is not in real life) |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
47 |
self.assertEqual(f.select.as_string(), |
7618
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
48 |
'DISTINCT Any WHERE X is CWUser, X in_group D, D eid %s' % guests) |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
49 |
|
6338
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
50 |
def test_relation_optional_rel(self): |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
51 |
req = self.request() |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
52 |
rset = self.execute('Any X,GROUP_CONCAT(GN) GROUPBY X ' |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
53 |
'WHERE X in_group G?, G name GN, NOT G name "users"') |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
54 |
rqlst = rset.syntax_tree().copy() |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
55 |
select = rqlst.children[0] |
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
56 |
filtered_variable, baserql = facet.init_facets(rset, select) |
6338
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
57 |
|
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
58 |
f = facet.RelationFacet(req, rset=rset, |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
59 |
select=select, |
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
60 |
filtered_variable=filtered_variable) |
6338
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
61 |
f.rtype = 'in_group' |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
62 |
f.role = 'subject' |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
63 |
f.target_attr = 'name' |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
64 |
guests, managers = [eid for eid, in self.execute('CWGroup G ORDERBY GN ' |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
65 |
'WHERE G name GN, G name IN ("guests", "managers")')] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6338
diff
changeset
|
66 |
self.assertEqual(f.vocabulary(), |
6338
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
67 |
[(u'guests', guests), (u'managers', managers)]) |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
68 |
# ensure rqlst is left unmodified |
7601
9030e8a4481e
[facets] should remove groupby from base rqlst. Closes #1796196
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6435
diff
changeset
|
69 |
self.assertEqual(rqlst.as_string(), 'DISTINCT Any WHERE X in_group G?, G name GN, NOT G name "users"') |
6338
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
70 |
#rqlst = rset.syntax_tree() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6338
diff
changeset
|
71 |
self.assertEqual(sorted(f.possible_values()), |
6338
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
72 |
[str(guests), str(managers)]) |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
73 |
# ensure rqlst is left unmodified |
7601
9030e8a4481e
[facets] should remove groupby from base rqlst. Closes #1796196
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6435
diff
changeset
|
74 |
self.assertEqual(rqlst.as_string(), 'DISTINCT Any WHERE X in_group G?, G name GN, NOT G name "users"') |
6338
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
75 |
req.form[f.__regid__] = str(guests) |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
76 |
f.add_rql_restrictions() |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
77 |
# selection is cluttered because rqlst has been prepared for facet (it |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
78 |
# is not in real life) |
7601
9030e8a4481e
[facets] should remove groupby from base rqlst. Closes #1796196
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6435
diff
changeset
|
79 |
self.assertEqual(f.select.as_string(), |
9030e8a4481e
[facets] should remove groupby from base rqlst. Closes #1796196
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6435
diff
changeset
|
80 |
'DISTINCT Any WHERE X in_group G?, G name GN, NOT G name "users", X in_group D, D eid %s' % guests) |
6338
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
81 |
|
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
82 |
def test_relation_no_relation_1(self): |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
83 |
f, (guests, managers) = self._in_group_facet(no_relation=True) |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
84 |
self.assertEqual(f.vocabulary(), |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
85 |
[(u'guests', guests), (u'managers', managers)]) |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
86 |
self.assertEqual(f.possible_values(), |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
87 |
[str(guests), str(managers)]) |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
88 |
f._cw.create_entity('CWUser', login=u'hop', upassword='toto') |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
89 |
self.assertEqual(f.vocabulary(), |
6417
d2361abe8505
[test] fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6380
diff
changeset
|
90 |
[(u'<no relation>', ''), (u'guests', guests), (u'managers', managers)]) |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
91 |
self.assertEqual(f.possible_values(), |
6417
d2361abe8505
[test] fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6380
diff
changeset
|
92 |
[str(guests), str(managers), '']) |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
93 |
f._cw.form[f.__regid__] = '' |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
94 |
f.add_rql_restrictions() |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
95 |
self.assertEqual(f.select.as_string(), |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
96 |
'DISTINCT Any WHERE X is CWUser, NOT X in_group G') |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
97 |
|
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
98 |
def test_relation_no_relation_2(self): |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
99 |
f, (guests, managers) = self._in_group_facet(no_relation=True) |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
100 |
f._cw.form[f.__regid__] = ['', guests] |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
101 |
f.select.save_state() |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
102 |
f.add_rql_restrictions() |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
103 |
self.assertEqual(f.select.as_string(), |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
104 |
'DISTINCT Any WHERE X is CWUser, (NOT X in_group B) OR (X in_group A, A eid %s)' % guests) |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
105 |
f.select.recover() |
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
106 |
self.assertEqual(f.select.as_string(), |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
107 |
'DISTINCT Any WHERE X is CWUser') |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
108 |
|
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
109 |
|
6338
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
110 |
|
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
111 |
def test_relationattribute(self): |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
112 |
f, (guests, managers) = self._in_group_facet(cls=facet.RelationAttributeFacet) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6338
diff
changeset
|
113 |
self.assertEqual(f.vocabulary(), |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
114 |
[(u'guests', u'guests'), (u'managers', u'managers')]) |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
115 |
# ensure rqlst is left unmodified |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
116 |
self.assertEqual(f.select.as_string(), 'DISTINCT Any WHERE X is CWUser') |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
117 |
#rqlst = rset.syntax_tree() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6338
diff
changeset
|
118 |
self.assertEqual(f.possible_values(), |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
119 |
['guests', 'managers']) |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
120 |
# ensure rqlst is left unmodified |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
121 |
self.assertEqual(f.select.as_string(), 'DISTINCT Any WHERE X is CWUser') |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
122 |
f._cw.form[f.__regid__] = 'guests' |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
123 |
f.add_rql_restrictions() |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
124 |
# selection is cluttered because rqlst has been prepared for facet (it |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
125 |
# is not in real life) |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
126 |
self.assertEqual(f.select.as_string(), |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
127 |
"DISTINCT Any WHERE X is CWUser, X in_group E, E name 'guests'") |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
128 |
|
7615
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
129 |
def test_daterange(self): |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
130 |
req, rset, rqlst, filtered_variable = self.prepare_rqlst() |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
131 |
f = facet.DateRangeFacet(req, rset=rset, |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
132 |
select=rqlst.children[0], |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
133 |
filtered_variable=filtered_variable) |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
134 |
f.rtype = 'creation_date' |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
135 |
dates = self.execute('Any CD ORDERBY CD WHERE X is CWUser, X creation_date CD') |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
136 |
self.assertEqual(f.vocabulary(), |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
137 |
[(str(dates[0][0]), dates[0][0]), |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
138 |
(str(dates[1][0]), dates[1][0])]) |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
139 |
# ensure rqlst is left unmodified |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
140 |
self.assertEqual(rqlst.as_string(), 'DISTINCT Any WHERE X is CWUser') |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
141 |
#rqlst = rset.syntax_tree() |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
142 |
self.assertEqual(f.possible_values(), |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
143 |
[str(dates[0][0]), str(dates[1][0])]) |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
144 |
# ensure rqlst is left unmodified |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
145 |
self.assertEqual(rqlst.as_string(), 'DISTINCT Any WHERE X is CWUser') |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
146 |
req.form['%s_inf' % f.__regid__] = str(datetime2ticks(dates[0][0])) |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
147 |
req.form['%s_sup' % f.__regid__] = str(datetime2ticks(dates[0][0])) |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
148 |
f.add_rql_restrictions() |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
149 |
# selection is cluttered because rqlst has been prepared for facet (it |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
150 |
# is not in real life) |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
151 |
self.assertEqual(f.select.as_string(), |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
152 |
'DISTINCT Any WHERE X is CWUser, X creation_date >= "%s", ' |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
153 |
'X creation_date <= "%s"' |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
154 |
% (dates[0][0].strftime('%Y/%m/%d'), |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
155 |
dates[0][0].strftime('%Y/%m/%d'))) |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
156 |
|
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
157 |
def test_attribute(self): |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
158 |
req, rset, rqlst, filtered_variable = self.prepare_rqlst() |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
159 |
f = facet.AttributeFacet(req, rset=rset, |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
160 |
select=rqlst.children[0], |
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
161 |
filtered_variable=filtered_variable) |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
162 |
f.rtype = 'login' |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6338
diff
changeset
|
163 |
self.assertEqual(f.vocabulary(), |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
164 |
[(u'admin', u'admin'), (u'anon', u'anon')]) |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
165 |
# ensure rqlst is left unmodified |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6338
diff
changeset
|
166 |
self.assertEqual(rqlst.as_string(), 'DISTINCT Any WHERE X is CWUser') |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
167 |
#rqlst = rset.syntax_tree() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6338
diff
changeset
|
168 |
self.assertEqual(f.possible_values(), |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
169 |
['admin', 'anon']) |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
170 |
# ensure rqlst is left unmodified |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6338
diff
changeset
|
171 |
self.assertEqual(rqlst.as_string(), 'DISTINCT Any WHERE X is CWUser') |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
172 |
req.form[f.__regid__] = 'admin' |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
173 |
f.add_rql_restrictions() |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
174 |
# selection is cluttered because rqlst has been prepared for facet (it |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
175 |
# is not in real life) |
7605
48abeac162fd
[facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7601
diff
changeset
|
176 |
self.assertEqual(f.select.as_string(), |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
177 |
"DISTINCT Any WHERE X is CWUser, X login 'admin'") |
6433
95c40961df21
[test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
178 |
|
7618
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
179 |
def test_rql_path_eid(self): |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
180 |
req, rset, rqlst, filtered_variable = self.prepare_rqlst() |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
181 |
facet.RQLPathFacet.path = [('X created_by U'), ('U owned_by O'), ('O login OL')] |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
182 |
f = facet.RQLPathFacet(req, rset=rset, |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
183 |
select=rqlst.children[0], |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
184 |
filtered_variable=filtered_variable) |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
185 |
f.filter_variable = 'O' |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
186 |
f.label_variable = 'OL' |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
187 |
|
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
188 |
self.assertEqual(f.vocabulary(), [(u'admin', self.user().eid),]) |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
189 |
# ensure rqlst is left unmodified |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
190 |
self.assertEqual(rqlst.as_string(), 'DISTINCT Any WHERE X is CWUser') |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
191 |
#rqlst = rset.syntax_tree() |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
192 |
self.assertEqual(f.possible_values(), |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
193 |
[str(self.user().eid),]) |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
194 |
# ensure rqlst is left unmodified |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
195 |
self.assertEqual(rqlst.as_string(), 'DISTINCT Any WHERE X is CWUser') |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
196 |
req.form[f.__regid__] = '1' |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
197 |
f.add_rql_restrictions() |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
198 |
# selection is cluttered because rqlst has been prepared for facet (it |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
199 |
# is not in real life) |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
200 |
self.assertEqual(f.select.as_string(), |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
201 |
"DISTINCT Any WHERE X is CWUser, X created_by F, F owned_by G, G eid 1") |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
202 |
|
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
203 |
def test_rql_path_attr(self): |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
204 |
req, rset, rqlst, filtered_variable = self.prepare_rqlst() |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
205 |
facet.RQLPathFacet.path = [('X created_by U'), ('U owned_by O'), ('O login OL')] |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
206 |
f = facet.RQLPathFacet(req, rset=rset, |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
207 |
select=rqlst.children[0], |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
208 |
filtered_variable=filtered_variable) |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
209 |
f.filter_variable = 'OL' |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
210 |
|
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
211 |
self.assertEqual(f.vocabulary(), [(u'admin', 'admin'),]) |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
212 |
# ensure rqlst is left unmodified |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
213 |
self.assertEqual(rqlst.as_string(), 'DISTINCT Any WHERE X is CWUser') |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
214 |
#rqlst = rset.syntax_tree() |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
215 |
self.assertEqual(f.possible_values(), ['admin',]) |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
216 |
# ensure rqlst is left unmodified |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
217 |
self.assertEqual(rqlst.as_string(), 'DISTINCT Any WHERE X is CWUser') |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
218 |
req.form[f.__regid__] = 'admin' |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
219 |
f.add_rql_restrictions() |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
220 |
# selection is cluttered because rqlst has been prepared for facet (it |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
221 |
# is not in real life) |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
222 |
self.assertEqual(f.select.as_string(), |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
223 |
"DISTINCT Any WHERE X is CWUser, X created_by G, G owned_by H, H login 'admin'") |
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
224 |
|
6433
95c40961df21
[test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
225 |
|
95c40961df21
[test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
226 |
if __name__ == '__main__': |
95c40961df21
[test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
227 |
from logilab.common.testlib import unittest_main |
95c40961df21
[test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
228 |
unittest_main() |