author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 25 Aug 2009 18:29:36 +0200 | |
branch | 3.5 |
changeset 2989 | dfb3506647e4 |
parent 1977 | 606923dff11b |
child 2773 | b2530e3e0afb |
child 4212 | ab6573088b4a |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
1 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
3 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
7 |
""" |
0 | 8 |
from cubicweb.devtools.apptest import EnvBasedTC |
408
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
9 |
from cubicweb.web.facet import insert_attr_select_relation, prepare_facets_rqlst |
0 | 10 |
|
11 |
||
12 |
class InsertAttrRelationTC(EnvBasedTC): |
|
16
a70ece4d9d1a
fix tests in web/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
13 |
|
0 | 14 |
def parse(self, query): |
15 |
rqlst = self.vreg.parse(self.session, query) |
|
16 |
select = rqlst.children[0] |
|
408
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
17 |
# XXX done in real life? |
0 | 18 |
select.remove_groups() |
408
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
19 |
return rqlst |
0 | 20 |
|
408
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
21 |
def _generate(self, rqlst, rel, role, attr): |
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
22 |
mainvar = prepare_facets_rqlst(rqlst)[0] |
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
23 |
insert_attr_select_relation(rqlst.children[0], mainvar, rel, role, attr) |
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
24 |
return rqlst.as_string() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
25 |
|
0 | 26 |
@property |
27 |
def select(self): |
|
28 |
return self.parse('Any B,(NOW - CD),S,V,U,GROUP_CONCAT(TN),VN,P,CD,BMD ' |
|
29 |
'GROUPBY B,CD,S,V,U,VN,P,BMD ' |
|
30 |
'WHERE B in_state S, B creation_date CD, ' |
|
31 |
'B modification_date BMD, T? tags B, T name TN, ' |
|
32 |
'V? bookmarked_by B, V title VN, B created_by U?, ' |
|
33 |
'B in_group P, P name "managers"') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
34 |
|
0 | 35 |
def test_1(self): |
408
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
36 |
self.assertEquals(self._generate(self.select, 'in_state', 'subject', 'name'), |
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
37 |
"DISTINCT Any A,C ORDERBY C WHERE B in_group P, P name 'managers', " |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
408
diff
changeset
|
38 |
"B in_state A, A name C, B is CWUser") |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
39 |
|
0 | 40 |
def test_2(self): |
408
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
41 |
self.assertEquals(self._generate(self.select, 'tags', 'object', 'name'), |
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
42 |
"DISTINCT Any A,C ORDERBY C WHERE B in_group P, P name 'managers', " |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
408
diff
changeset
|
43 |
"A tags B, A name C, B is CWUser") |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
44 |
|
0 | 45 |
def test_3(self): |
408
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
46 |
self.assertEquals(self._generate(self.select, 'created_by', 'subject', 'login'), |
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
47 |
"DISTINCT Any A,C ORDERBY C WHERE B in_group P, P name 'managers', " |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
408
diff
changeset
|
48 |
"B created_by A, A login C, B is CWUser") |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
49 |
|
408
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
50 |
def test_4(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
408
diff
changeset
|
51 |
self.assertEquals(self._generate(self.parse('Any X WHERE X is CWUser'), 'created_by', 'subject', 'login'), |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
408
diff
changeset
|
52 |
"DISTINCT Any A,B ORDERBY B WHERE X is CWUser, X created_by A, A login B") |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
53 |
|
408
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
54 |
def test_5(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
408
diff
changeset
|
55 |
self.assertEquals(self._generate(self.parse('Any X,L WHERE X is CWUser, X login L'), 'created_by', 'subject', 'login'), |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
408
diff
changeset
|
56 |
"DISTINCT Any A,B ORDERBY B WHERE X is CWUser, X created_by A, A login B") |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
57 |
|
0 | 58 |
def test_nonregr1(self): |
59 |
select = self.parse('Any T,V WHERE T bookmarked_by V?, ' |
|
60 |
'V in_state VS, VS name "published", T created_by U') |
|
408
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
61 |
self.assertEquals(self._generate(select, 'created_by', 'subject', 'login'), |
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
62 |
"DISTINCT Any A,B ORDERBY B WHERE T created_by U, " |
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
63 |
"T created_by A, A login B, T is Bookmark") |
0 | 64 |
|
65 |
def test_nonregr2(self): |
|
66 |
#'DISTINCT Any X,TMP,N WHERE P name TMP, X version_of P, P is Project, X is Version, not X in_state S,S name "published", X num N ORDERBY TMP,N' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
408
diff
changeset
|
67 |
select = self.parse('DISTINCT Any V,TN,L ORDERBY TN,L WHERE T nom TN, V connait T, T is Personne, V is CWUser,' |
0 | 68 |
'NOT V in_state VS, VS name "published", V login L') |
69 |
rschema = self.schema['connait'] |
|
70 |
for s, o in rschema.iter_rdefs(): |
|
71 |
rschema.set_rproperty(s, o, 'cardinality', '++') |
|
72 |
try: |
|
408
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
73 |
self.assertEquals(self._generate(select, 'in_state', 'subject', 'name'), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
408
diff
changeset
|
74 |
"DISTINCT Any A,B ORDERBY B WHERE V is CWUser, " |
408
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
75 |
"NOT V in_state VS, VS name 'published', " |
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
76 |
"V in_state A, A name B") |
0 | 77 |
finally: |
78 |
for s, o in rschema.iter_rdefs(): |
|
79 |
rschema.set_rproperty(s, o, 'cardinality', '**') |
|
80 |
||
81 |
def test_nonregr3(self): |
|
82 |
#'DISTINCT Any X,TMP,N WHERE P name TMP, X version_of P, P is Project, X is Version, not X in_state S,S name "published", X num N ORDERBY TMP,N' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
408
diff
changeset
|
83 |
select = self.parse('DISTINCT Any X, MAX(Y) GROUPBY X WHERE X is CWUser, Y is Bookmark, X in_group A') |
408
a8814ff6824e
reactivate tests and fix bug triggering removal of undesired relation (eg type restriction) in some cases
sylvain.thenault@logilab.fr
parents:
16
diff
changeset
|
84 |
self.assertEquals(self._generate(select, 'in_group', 'subject', 'name'), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
408
diff
changeset
|
85 |
"DISTINCT Any B,C ORDERBY C WHERE X is CWUser, X in_group B, B name C") |
0 | 86 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
87 |
|
0 | 88 |
if __name__ == '__main__': |
89 |
from logilab.common.testlib import unittest_main |
|
90 |
unittest_main() |