author | sylvain.thenault@logilab.fr |
Tue, 28 Apr 2009 11:22:31 +0200 | |
branch | tls-sprint |
changeset 1498 | 2c6eec0b46b9 |
parent 1398 | 5fe84a5f7035 |
child 1802 | d628defebc17 |
permissions | -rw-r--r-- |
0 | 1 |
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
|
2 |
from cubicweb.web.facet import insert_attr_select_relation, prepare_facets_rqlst |
0 | 3 |
|
4 |
||
5 |
class InsertAttrRelationTC(EnvBasedTC): |
|
16
a70ece4d9d1a
fix tests in web/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
6 |
|
0 | 7 |
def parse(self, query): |
8 |
rqlst = self.vreg.parse(self.session, query) |
|
9 |
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
|
10 |
# XXX done in real life? |
0 | 11 |
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
|
12 |
return rqlst |
0 | 13 |
|
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
|
14 |
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
|
15 |
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
|
16 |
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
|
17 |
return rqlst.as_string() |
0 | 18 |
|
19 |
@property |
|
20 |
def select(self): |
|
21 |
return self.parse('Any B,(NOW - CD),S,V,U,GROUP_CONCAT(TN),VN,P,CD,BMD ' |
|
22 |
'GROUPBY B,CD,S,V,U,VN,P,BMD ' |
|
23 |
'WHERE B in_state S, B creation_date CD, ' |
|
24 |
'B modification_date BMD, T? tags B, T name TN, ' |
|
25 |
'V? bookmarked_by B, V title VN, B created_by U?, ' |
|
26 |
'B in_group P, P name "managers"') |
|
27 |
||
28 |
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
|
29 |
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
|
30 |
"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
|
31 |
"B in_state A, A name C, B is CWUser") |
0 | 32 |
|
33 |
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
|
34 |
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
|
35 |
"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
|
36 |
"A tags B, A name C, B is CWUser") |
0 | 37 |
|
38 |
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
|
39 |
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
|
40 |
"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
|
41 |
"B created_by A, A login C, B 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
|
42 |
|
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
|
43 |
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
|
44 |
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
|
45 |
"DISTINCT Any A,B ORDERBY B WHERE X is CWUser, X created_by A, A login B") |
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 |
|
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 |
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
|
48 |
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
|
49 |
"DISTINCT Any A,B ORDERBY B WHERE X is CWUser, X created_by A, A login B") |
0 | 50 |
|
51 |
def test_nonregr1(self): |
|
52 |
select = self.parse('Any T,V WHERE T bookmarked_by V?, ' |
|
53 |
'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
|
54 |
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
|
55 |
"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
|
56 |
"T created_by A, A login B, T is Bookmark") |
0 | 57 |
|
58 |
def test_nonregr2(self): |
|
59 |
#'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
|
60 |
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 | 61 |
'NOT V in_state VS, VS name "published", V login L') |
62 |
rschema = self.schema['connait'] |
|
63 |
for s, o in rschema.iter_rdefs(): |
|
64 |
rschema.set_rproperty(s, o, 'cardinality', '++') |
|
65 |
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
|
66 |
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
|
67 |
"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
|
68 |
"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
|
69 |
"V in_state A, A name B") |
0 | 70 |
finally: |
71 |
for s, o in rschema.iter_rdefs(): |
|
72 |
rschema.set_rproperty(s, o, 'cardinality', '**') |
|
73 |
||
74 |
def test_nonregr3(self): |
|
75 |
#'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
|
76 |
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
|
77 |
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
|
78 |
"DISTINCT Any B,C ORDERBY C WHERE X is CWUser, X in_group B, B name C") |
0 | 79 |
|
80 |
||
81 |
if __name__ == '__main__': |
|
82 |
from logilab.common.testlib import unittest_main |
|
83 |
unittest_main() |