author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 17 Feb 2011 16:46:25 +0100 | |
branch | stable |
changeset 7008 | 5d0be45ee69d |
parent 6435 | 71b2a3fe7ba1 |
child 7601 | 9030e8a4481e |
permissions | -rw-r--r-- |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
1 |
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
|
2 |
from cubicweb.web import facet |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
3 |
|
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
4 |
class BaseFacetTC(CubicWebTC): |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
5 |
|
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
6 |
def prepare_rqlst(self): |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
7 |
req = self.request() |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
8 |
rset = self.execute('CWUser X') |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
9 |
rqlst = rset.syntax_tree().copy() |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
10 |
req.vreg.rqlhelper.annotate(rqlst) |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
11 |
mainvar, baserql = facet.prepare_facets_rqlst(rqlst, rset.args) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6338
diff
changeset
|
12 |
self.assertEqual(mainvar.name, 'X') |
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') |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
15 |
return req, rset, rqlst, mainvar |
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): |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
18 |
req, rset, rqlst, mainvar = 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 |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
20 |
f = cls(req, rset=rset, rqlst=rqlst.children[0], |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
21 |
filtered_variable=mainvar) |
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 |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
37 |
self.assertEqual(f.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
|
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 |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
42 |
self.assertEqual(f.rqlst.as_string(), '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
|
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) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6338
diff
changeset
|
47 |
self.assertEqual(f.rqlst.as_string(), |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
48 |
'DISTINCT Any WHERE X is CWUser, X in_group D, D eid %s' % guests) |
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() |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
55 |
req.vreg.rqlhelper.annotate(rqlst) |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
56 |
mainvar, baserql = facet.prepare_facets_rqlst(rqlst, rset.args) |
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, |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
59 |
rqlst=rqlst.children[0], |
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
60 |
filtered_variable=mainvar) |
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 |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6338
diff
changeset
|
69 |
self.assertEqual(rqlst.as_string(), 'DISTINCT Any GROUPBY X 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 |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6338
diff
changeset
|
74 |
self.assertEqual(rqlst.as_string(), 'DISTINCT Any GROUPBY X 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) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6338
diff
changeset
|
79 |
self.assertEqual(f.rqlst.as_string(), |
6338
b520b86113e3
add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6119
diff
changeset
|
80 |
'DISTINCT Any GROUPBY X WHERE X in_group G?, G name GN, NOT G name "users", X in_group D, D eid %s' % guests) |
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() |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
95 |
self.assertEqual(f.rqlst.as_string(), |
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] |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
101 |
f.rqlst.save_state() |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
102 |
f.add_rql_restrictions() |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
103 |
self.assertEqual(f.rqlst.as_string(), |
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) |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
105 |
f.rqlst.recover() |
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
106 |
self.assertEqual(f.rqlst.as_string(), |
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 |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
116 |
self.assertEqual(f.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
|
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 |
6380
63d5dbaef999
[facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
121 |
self.assertEqual(f.rqlst.as_string(), '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
|
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) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6338
diff
changeset
|
126 |
self.assertEqual(f.rqlst.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 |
|
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
129 |
|
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
130 |
def test_attribute(self): |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
131 |
req, rset, rqlst, mainvar = self.prepare_rqlst() |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
132 |
f = facet.AttributeFacet(req, rset=rset, |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
133 |
rqlst=rqlst.children[0], |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
134 |
filtered_variable=mainvar) |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
135 |
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
|
136 |
self.assertEqual(f.vocabulary(), |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
137 |
[(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
|
138 |
# 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
|
139 |
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
|
140 |
#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
|
141 |
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
|
142 |
['admin', 'anon']) |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
143 |
# 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
|
144 |
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
|
145 |
req.form[f.__regid__] = 'admin' |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
146 |
f.add_rql_restrictions() |
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
147 |
# 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
|
148 |
# is not in real life) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6338
diff
changeset
|
149 |
self.assertEqual(f.rqlst.as_string(), |
6119
b217635d3b28
new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
150 |
"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
|
151 |
|
95c40961df21
[test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
152 |
|
95c40961df21
[test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
153 |
if __name__ == '__main__': |
95c40961df21
[test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
154 |
from logilab.common.testlib import unittest_main |
95c40961df21
[test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
155 |
unittest_main() |