author | Julien Cristau <julien.cristau@logilab.fr> |
Tue, 13 Mar 2012 14:20:16 +0100 | |
branch | stable |
changeset 8301 | 1385e05afe52 |
parent 8029 | 805d4e121b65 |
child 8598 | 95b3792a8947 |
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 |
|
8023
047e62cddee0
[test, facets] fix prepare_rqlst arguments, it wasn't actually testing baserql due to name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7874
diff
changeset
|
7 |
def prepare_rqlst(self, rql='CWUser X', mainvar='X', |
047e62cddee0
[test, facets] fix prepare_rqlst arguments, it wasn't actually testing baserql due to name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7874
diff
changeset
|
8 |
expected_baserql='Any X WHERE X is CWUser', |
047e62cddee0
[test, facets] fix prepare_rqlst arguments, it wasn't actually testing baserql due to name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7874
diff
changeset
|
9 |
expected_preparedrql='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
|
10 |
req = self.request() |
7624
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
11 |
rset = self.execute(rql) |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
12 |
rqlst = rset.syntax_tree().copy() |
7624
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
13 |
filtered_variable, baserql = facet.init_facets(rset, rqlst.children[0], |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
14 |
mainvar=mainvar) |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
15 |
self.assertEqual(filtered_variable.name, mainvar) |
8023
047e62cddee0
[test, facets] fix prepare_rqlst arguments, it wasn't actually testing baserql due to name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7874
diff
changeset
|
16 |
self.assertEqual(baserql, expected_baserql) |
047e62cddee0
[test, facets] fix prepare_rqlst arguments, it wasn't actually testing baserql due to name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7874
diff
changeset
|
17 |
self.assertEqual(rqlst.as_string(), expected_preparedrql) |
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 |
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
|
19 |
|
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
20 |
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
|
21 |
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
|
22 |
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
|
23 |
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
|
24 |
filtered_variable=filtered_variable) |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
25 |
f.__regid__ = 'in_group' |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
26 |
f.rtype = 'in_group' |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
27 |
f.role = 'subject' |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
28 |
f.target_attr = 'name' |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
29 |
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
|
30 |
'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
|
31 |
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
|
32 |
'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
|
33 |
return f, groups |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
34 |
|
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
35 |
def test_relation_simple(self): |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
36 |
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
|
37 |
self.assertEqual(f.vocabulary(), |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
38 |
[(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
|
39 |
# 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
|
40 |
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
|
41 |
#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
|
42 |
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
|
43 |
[str(guests), str(managers)]) |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
44 |
# 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
|
45 |
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
|
46 |
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
|
47 |
f.add_rql_restrictions() |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
48 |
# 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
|
49 |
# 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
|
50 |
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
|
51 |
'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
|
52 |
|
7768
bd44f506ca86
closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7629
diff
changeset
|
53 |
def test_relation_multiple_and(self): |
bd44f506ca86
closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7629
diff
changeset
|
54 |
f, (guests, managers) = self._in_group_facet() |
bd44f506ca86
closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7629
diff
changeset
|
55 |
f._cw.form[f.__regid__] = [str(guests), str(managers)] |
bd44f506ca86
closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7629
diff
changeset
|
56 |
f._cw.form[f.__regid__ + '_andor'] = 'AND' |
bd44f506ca86
closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7629
diff
changeset
|
57 |
f.add_rql_restrictions() |
bd44f506ca86
closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7629
diff
changeset
|
58 |
self.assertEqual(f.select.as_string(), |
bd44f506ca86
closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7629
diff
changeset
|
59 |
'DISTINCT Any WHERE X is CWUser, X in_group A, B eid %s, X in_group B, A eid %s' % (guests, managers)) |
bd44f506ca86
closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7629
diff
changeset
|
60 |
|
bd44f506ca86
closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7629
diff
changeset
|
61 |
def test_relation_multiple_or(self): |
bd44f506ca86
closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7629
diff
changeset
|
62 |
f, (guests, managers) = self._in_group_facet() |
bd44f506ca86
closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7629
diff
changeset
|
63 |
f._cw.form[f.__regid__] = [str(guests), str(managers)] |
bd44f506ca86
closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7629
diff
changeset
|
64 |
f._cw.form[f.__regid__ + '_andor'] = 'OR' |
bd44f506ca86
closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7629
diff
changeset
|
65 |
f.add_rql_restrictions() |
bd44f506ca86
closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7629
diff
changeset
|
66 |
self.assertEqual(f.select.as_string(), |
bd44f506ca86
closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7629
diff
changeset
|
67 |
'DISTINCT Any WHERE X is CWUser, X in_group A, A eid IN(%s, %s)' % (guests, managers)) |
bd44f506ca86
closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7629
diff
changeset
|
68 |
|
6338
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
69 |
def test_relation_optional_rel(self): |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
70 |
req = self.request() |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
71 |
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
|
72 |
'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
|
73 |
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
|
74 |
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
|
75 |
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
|
76 |
|
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
77 |
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
|
78 |
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
|
79 |
filtered_variable=filtered_variable) |
6338
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
80 |
f.rtype = 'in_group' |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
81 |
f.role = 'subject' |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
82 |
f.target_attr = 'name' |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
83 |
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
|
84 |
'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
|
85 |
self.assertEqual(f.vocabulary(), |
6338
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
86 |
[(u'guests', guests), (u'managers', managers)]) |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
87 |
# 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
|
88 |
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
|
89 |
#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
|
90 |
self.assertEqual(sorted(f.possible_values()), |
6338
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
91 |
[str(guests), str(managers)]) |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
92 |
# 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
|
93 |
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
|
94 |
req.form[f.__regid__] = str(guests) |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
95 |
f.add_rql_restrictions() |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
96 |
# 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
|
97 |
# 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
|
98 |
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
|
99 |
'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
|
100 |
|
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
101 |
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
|
102 |
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
|
103 |
self.assertEqual(f.vocabulary(), |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
104 |
[(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
|
105 |
self.assertEqual(f.possible_values(), |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
106 |
[str(guests), str(managers)]) |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
107 |
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
|
108 |
self.assertEqual(f.vocabulary(), |
6417
d2361abe8505
[test] fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6380
diff
changeset
|
109 |
[(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
|
110 |
self.assertEqual(f.possible_values(), |
6417
d2361abe8505
[test] fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6380
diff
changeset
|
111 |
[str(guests), str(managers), '']) |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
112 |
f._cw.form[f.__regid__] = '' |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
113 |
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
|
114 |
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
|
115 |
'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
|
116 |
|
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
117 |
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
|
118 |
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
|
119 |
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
|
120 |
f.select.save_state() |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
121 |
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
|
122 |
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
|
123 |
'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
|
124 |
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
|
125 |
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
|
126 |
'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
|
127 |
|
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
128 |
|
6338
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
129 |
|
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
130 |
def test_relationattribute(self): |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
131 |
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
|
132 |
self.assertEqual(f.vocabulary(), |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
133 |
[(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
|
134 |
# 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
|
135 |
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
|
136 |
#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
|
137 |
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
|
138 |
['guests', 'managers']) |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
139 |
# 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
|
140 |
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
|
141 |
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
|
142 |
f.add_rql_restrictions() |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
143 |
# 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
|
144 |
# 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
|
145 |
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
|
146 |
"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
|
147 |
|
7615
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
148 |
def test_daterange(self): |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
149 |
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
|
150 |
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
|
151 |
select=rqlst.children[0], |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
152 |
filtered_variable=filtered_variable) |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
153 |
f.rtype = 'creation_date' |
7629
58f11f7dad68
[range facet] closes #1806937: simply retrieve min/max values when computing vocabulary/possible_values, this is enough
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7624
diff
changeset
|
154 |
mind, maxd = self.execute('Any MIN(CD), MAX(CD) WHERE X is CWUser, X creation_date CD')[0] |
7615
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
155 |
self.assertEqual(f.vocabulary(), |
7629
58f11f7dad68
[range facet] closes #1806937: simply retrieve min/max values when computing vocabulary/possible_values, this is enough
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7624
diff
changeset
|
156 |
[(str(mind), mind), |
58f11f7dad68
[range facet] closes #1806937: simply retrieve min/max values when computing vocabulary/possible_values, this is enough
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7624
diff
changeset
|
157 |
(str(maxd), maxd)]) |
7615
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
158 |
# 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
|
159 |
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
|
160 |
#rqlst = rset.syntax_tree() |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
161 |
self.assertEqual(f.possible_values(), |
7629
58f11f7dad68
[range facet] closes #1806937: simply retrieve min/max values when computing vocabulary/possible_values, this is enough
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7624
diff
changeset
|
162 |
[str(mind), str(maxd)]) |
7615
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
163 |
# 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
|
164 |
self.assertEqual(rqlst.as_string(), 'DISTINCT Any WHERE X is CWUser') |
7629
58f11f7dad68
[range facet] closes #1806937: simply retrieve min/max values when computing vocabulary/possible_values, this is enough
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7624
diff
changeset
|
165 |
req.form['%s_inf' % f.__regid__] = str(datetime2ticks(mind)) |
58f11f7dad68
[range facet] closes #1806937: simply retrieve min/max values when computing vocabulary/possible_values, this is enough
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7624
diff
changeset
|
166 |
req.form['%s_sup' % f.__regid__] = str(datetime2ticks(mind)) |
7615
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
167 |
f.add_rql_restrictions() |
e5ad51352eb3
[facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7612
diff
changeset
|
168 |
# 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
|
169 |
# 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
|
170 |
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
|
171 |
'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
|
172 |
'X creation_date <= "%s"' |
7629
58f11f7dad68
[range facet] closes #1806937: simply retrieve min/max values when computing vocabulary/possible_values, this is enough
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7624
diff
changeset
|
173 |
% (mind.strftime('%Y/%m/%d'), |
58f11f7dad68
[range facet] closes #1806937: simply retrieve min/max values when computing vocabulary/possible_values, this is enough
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7624
diff
changeset
|
174 |
mind.strftime('%Y/%m/%d'))) |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
175 |
|
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
176 |
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
|
177 |
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
|
178 |
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
|
179 |
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
|
180 |
filtered_variable=filtered_variable) |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
181 |
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
|
182 |
self.assertEqual(f.vocabulary(), |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
183 |
[(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
|
184 |
# 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
|
185 |
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
|
186 |
#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
|
187 |
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
|
188 |
['admin', 'anon']) |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
189 |
# 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
|
190 |
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
|
191 |
req.form[f.__regid__] = 'admin' |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
192 |
f.add_rql_restrictions() |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
193 |
# 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
|
194 |
# 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
|
195 |
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
|
196 |
"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
|
197 |
|
8029
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
198 |
def test_bitfield(self): |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
199 |
req, rset, rqlst, filtered_variable = self.prepare_rqlst( |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
200 |
'CWAttribute X WHERE X ordernum XO', |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
201 |
expected_baserql='Any X WHERE X ordernum XO, X is CWAttribute', |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
202 |
expected_preparedrql='DISTINCT Any WHERE X ordernum XO, X is CWAttribute') |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
203 |
f = facet.BitFieldFacet(req, rset=rset, |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
204 |
select=rqlst.children[0], |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
205 |
filtered_variable=filtered_variable) |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
206 |
f.choices = [('un', 1,), ('deux', 2,)] |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
207 |
f.rtype = 'ordernum' |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
208 |
self.assertEqual(f.vocabulary(), |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
209 |
[(u'deux', 2), (u'un', 1)]) |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
210 |
# ensure rqlst is left unmodified |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
211 |
self.assertEqual(rqlst.as_string(), 'DISTINCT Any WHERE X ordernum XO, X is CWAttribute') |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
212 |
#rqlst = rset.syntax_tree() |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
213 |
self.assertEqual(f.possible_values(), |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
214 |
['2', '1']) |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
215 |
# ensure rqlst is left unmodified |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
216 |
self.assertEqual(rqlst.as_string(), 'DISTINCT Any WHERE X ordernum XO, X is CWAttribute') |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
217 |
req.form[f.__regid__] = '3' |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
218 |
f.add_rql_restrictions() |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
219 |
# selection is cluttered because rqlst has been prepared for facet (it |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
220 |
# is not in real life) |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
221 |
self.assertEqual(f.select.as_string(), |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
222 |
"DISTINCT Any WHERE X ordernum XO, X is CWAttribute, X ordernum C HAVING 3 = (C & 3)") |
805d4e121b65
[ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8023
diff
changeset
|
223 |
|
7618
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
224 |
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
|
225 |
req, rset, rqlst, filtered_variable = self.prepare_rqlst() |
7874
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
226 |
class RPF(facet.RQLPathFacet): |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
227 |
path = [('X created_by U'), ('U owned_by O'), ('O login OL')] |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
228 |
filter_variable = 'O' |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
229 |
label_variable = 'OL' |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
230 |
f = RPF(req, rset=rset, select=rqlst.children[0], |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
231 |
filtered_variable=filtered_variable) |
7618
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
232 |
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
|
233 |
# 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
|
234 |
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
|
235 |
#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
|
236 |
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
|
237 |
[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
|
238 |
# 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
|
239 |
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
|
240 |
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
|
241 |
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
|
242 |
# 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
|
243 |
# 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
|
244 |
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
|
245 |
"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
|
246 |
|
7874
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
247 |
def test_rql_path_eid_no_label(self): |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
248 |
req, rset, rqlst, filtered_variable = self.prepare_rqlst() |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
249 |
class RPF(facet.RQLPathFacet): |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
250 |
path = [('X created_by U'), ('U owned_by O'), ('O login OL')] |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
251 |
filter_variable = 'O' |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
252 |
f = RPF(req, rset=rset, select=rqlst.children[0], |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
253 |
filtered_variable=filtered_variable) |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
254 |
self.assertEqual(f.vocabulary(), [(str(self.user().eid), self.user().eid),]) |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
255 |
|
7618
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
256 |
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
|
257 |
req, rset, rqlst, filtered_variable = self.prepare_rqlst() |
7874
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
258 |
class RPF(facet.RQLPathFacet): |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
259 |
path = [('X created_by U'), ('U owned_by O'), ('O login OL')] |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
260 |
filter_variable = 'OL' |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
261 |
f = RPF(req, rset=rset, select=rqlst.children[0], |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
262 |
filtered_variable=filtered_variable) |
7618
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
263 |
|
5395007c415c
[facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7615
diff
changeset
|
264 |
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
|
265 |
# 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
|
266 |
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
|
267 |
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
|
268 |
# 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
|
269 |
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
|
270 |
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
|
271 |
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
|
272 |
# 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
|
273 |
# 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
|
274 |
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
|
275 |
"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
|
276 |
|
7874
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
277 |
def test_rql_path_check_filter_label_variable(self): |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
278 |
req, rset, rqlst, filtered_variable = self.prepareg_aggregat_rqlst() |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
279 |
class RPF(facet.RQLPathFacet): |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
280 |
path = [('X created_by U'), ('U owned_by O'), ('O login OL')] |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
281 |
filter_variable = 'OL' |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
282 |
label_variable = 'OL' |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
283 |
self.assertRaises(AssertionError, RPF, req, rset=rset, |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
284 |
select=rqlst.children[0], |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
285 |
filtered_variable=filtered_variable) |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
286 |
|
7624
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
287 |
def prepareg_aggregat_rqlst(self): |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
288 |
return self.prepare_rqlst( |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
289 |
'Any 1, COUNT(X) WHERE X is CWUser, X creation_date XD, ' |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
290 |
'X modification_date XM, Y creation_date YD, Y is CWGroup ' |
8023
047e62cddee0
[test, facets] fix prepare_rqlst arguments, it wasn't actually testing baserql due to name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7874
diff
changeset
|
291 |
'HAVING DAY(XD)>=DAY(YD) AND DAY(XM)<=DAY(YD)', 'X', |
047e62cddee0
[test, facets] fix prepare_rqlst arguments, it wasn't actually testing baserql due to name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7874
diff
changeset
|
292 |
expected_baserql='Any 1,COUNT(X) WHERE X is CWUser, X creation_date XD, ' |
7624
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
293 |
'X modification_date XM, Y creation_date YD, Y is CWGroup ' |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
294 |
'HAVING DAY(XD) >= DAY(YD), DAY(XM) <= DAY(YD)', |
8023
047e62cddee0
[test, facets] fix prepare_rqlst arguments, it wasn't actually testing baserql due to name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7874
diff
changeset
|
295 |
expected_preparedrql='DISTINCT Any WHERE X is CWUser, X creation_date XD, ' |
7624
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
296 |
'X modification_date XM, Y creation_date YD, Y is CWGroup ' |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
297 |
'HAVING DAY(XD) >= DAY(YD), DAY(XM) <= DAY(YD)') |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
298 |
|
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
299 |
|
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
300 |
def test_aggregat_query_cleanup_select(self): |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
301 |
req, rset, rqlst, filtered_variable = self.prepareg_aggregat_rqlst() |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
302 |
select = rqlst.children[0] |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
303 |
facet.cleanup_select(select, filtered_variable=filtered_variable) |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
304 |
self.assertEqual(select.as_string(), |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
305 |
'DISTINCT Any WHERE X is CWUser, X creation_date XD, ' |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
306 |
'X modification_date XM, Y creation_date YD, Y is CWGroup ' |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
307 |
'HAVING DAY(XD) >= DAY(YD), DAY(XM) <= DAY(YD)') |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
308 |
|
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
309 |
def test_aggregat_query_rql_path(self): |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
310 |
req, rset, rqlst, filtered_variable = self.prepareg_aggregat_rqlst() |
7874
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
311 |
class RPF(facet.RQLPathFacet): |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
312 |
path = [('X created_by U'), ('U owned_by O'), ('O login OL')] |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
313 |
filter_variable = 'OL' |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
314 |
f = RPF(req, rset=rset, select=rqlst.children[0], |
be04706eacc9
[facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7768
diff
changeset
|
315 |
filtered_variable=filtered_variable) |
7624
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
316 |
self.assertEqual(f.vocabulary(), [(u'admin', u'admin')]) |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
317 |
self.assertEqual(f.possible_values(), ['admin']) |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
318 |
req.form[f.__regid__] = 'admin' |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
319 |
f.add_rql_restrictions() |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
320 |
self.assertEqual(f.select.as_string(), |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
321 |
"DISTINCT Any WHERE X is CWUser, X creation_date XD, " |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
322 |
"X modification_date XM, Y creation_date YD, Y is CWGroup, " |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
323 |
"X created_by G, G owned_by H, H login 'admin' " |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
324 |
"HAVING DAY(XD) >= DAY(YD), DAY(XM) <= DAY(YD)") |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
325 |
|
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
326 |
def test_aggregat_query_attribute(self): |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
327 |
req, rset, rqlst, filtered_variable = self.prepareg_aggregat_rqlst() |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
328 |
f = facet.AttributeFacet(req, rset=rset, |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
329 |
select=rqlst.children[0], |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
330 |
filtered_variable=filtered_variable) |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
331 |
f.rtype = 'login' |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
332 |
self.assertEqual(f.vocabulary(), |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
333 |
[(u'admin', u'admin'), (u'anon', u'anon')]) |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
334 |
self.assertEqual(f.possible_values(), |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
335 |
['admin', 'anon']) |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
336 |
req.form[f.__regid__] = 'admin' |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
337 |
f.add_rql_restrictions() |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
338 |
self.assertEqual(f.select.as_string(), |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
339 |
"DISTINCT Any WHERE X is CWUser, X creation_date XD, " |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
340 |
"X modification_date XM, Y creation_date YD, Y is CWGroup, X login 'admin' " |
ce020f90fb8e
[facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7618
diff
changeset
|
341 |
"HAVING DAY(XD) >= DAY(YD), DAY(XM) <= DAY(YD)") |
6433
95c40961df21
[test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
342 |
|
95c40961df21
[test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
343 |
if __name__ == '__main__': |
95c40961df21
[test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
344 |
from logilab.common.testlib import unittest_main |
95c40961df21
[test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
345 |
unittest_main() |