author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Wed, 07 Jan 2009 12:25:18 +0100 | |
changeset 344 | e0d5879a613e |
parent 16 | a70ece4d9d1a |
child 408 | a8814ff6824e |
permissions | -rw-r--r-- |
0 | 1 |
from cubicweb.devtools.apptest import EnvBasedTC |
16
a70ece4d9d1a
fix tests in web/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
2 |
from cubicweb.web.views.searchrestriction import insert_attr_select_relation |
0 | 3 |
|
4 |
class ExtractFilterFieldsTC(EnvBasedTC): |
|
5 |
def test_relations_cleanup(self): |
|
16
a70ece4d9d1a
fix tests in web/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
6 |
self.skip('test needs to be updated (facet API changed)') |
0 | 7 |
# removing relation should be done in the table filter form but not |
8 |
# from the facets box |
|
9 |
rset = self.execute('Any X, S WHERE X in_state S') |
|
10 |
afielddefs, baserql, groupby, orderby = extract_filter_fields(rset, 0) |
|
11 |
afielddefs = [(getattr(r, 'r_type', r), role, type) for r, role, type, values in afielddefs] |
|
12 |
self.assertEquals(afielddefs, [('has_text', 'subject', 'rstring'), |
|
13 |
('in_state', 'subject', 'eid')]) |
|
14 |
self.assertEquals(baserql, 'DISTINCT Any X,S') |
|
15 |
self.assertEquals(groupby, '') |
|
16 |
self.assertEquals(orderby, '') |
|
17 |
# test rql st state |
|
18 |
self.assertEquals(rset.syntax_tree().as_string(), 'Any X,S WHERE X in_state S') |
|
19 |
afielddefs, baserql, groupby, orderby = extract_filter_fields(rset, 0, removerels=False) |
|
20 |
afielddefs = [(getattr(r, 'r_type', r), role, type) for r, role, type, values in afielddefs] |
|
21 |
self.assertEquals(afielddefs, [('has_text', 'subject', 'rstring'), |
|
22 |
('in_state', 'subject', 'eid')]) |
|
23 |
self.assertEquals(baserql, 'DISTINCT Any X,S WHERE X in_state S') |
|
24 |
||
25 |
||
26 |
class InsertAttrRelationTC(EnvBasedTC): |
|
16
a70ece4d9d1a
fix tests in web/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
27 |
def setUp(self): |
a70ece4d9d1a
fix tests in web/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
28 |
self.skip('test needs to be updated (facet API changed)') |
a70ece4d9d1a
fix tests in web/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
29 |
|
0 | 30 |
def parse(self, query): |
31 |
rqlst = self.vreg.parse(self.session, query) |
|
32 |
select = rqlst.children[0] |
|
33 |
select.remove_groups() |
|
34 |
return select |
|
35 |
||
36 |
def _generate(self, select, rel, var, attr): |
|
16
a70ece4d9d1a
fix tests in web/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
37 |
return insert_attr_select_relation(select, select.defined_vars[var], 'subject', rel, attr) |
0 | 38 |
|
39 |
@property |
|
40 |
def select(self): |
|
41 |
return self.parse('Any B,(NOW - CD),S,V,U,GROUP_CONCAT(TN),VN,P,CD,BMD ' |
|
42 |
'GROUPBY B,CD,S,V,U,VN,P,BMD ' |
|
43 |
'WHERE B in_state S, B creation_date CD, ' |
|
44 |
'B modification_date BMD, T? tags B, T name TN, ' |
|
45 |
'V? bookmarked_by B, V title VN, B created_by U?, ' |
|
46 |
'B in_group P, P name "managers"') |
|
47 |
||
48 |
def test_1(self): |
|
49 |
self.assertEquals(self._generate(self.select, 'in_state', 'S', 'name'), |
|
50 |
"DISTINCT Any S,A ORDERBY A WHERE B in_state S, B in_group P, " |
|
51 |
"P name 'managers', S name A, B is EUser") |
|
52 |
||
53 |
def test_2(self): |
|
54 |
self.assertEquals(self._generate(self.select, 'tags', 'T', 'name'), |
|
55 |
"DISTINCT Any T,TN ORDERBY TN WHERE T tags B, T name TN, " |
|
56 |
"B in_group P, P name 'managers', B is EUser") |
|
57 |
||
58 |
def test_3(self): |
|
59 |
self.assertEquals(self._generate(self.select, 'created_by', 'U', 'login'), |
|
60 |
"DISTINCT Any U,A ORDERBY A WHERE B created_by U, B in_group P, " |
|
61 |
"P name 'managers', U login A, B is EUser") |
|
62 |
||
63 |
def test_nonregr1(self): |
|
64 |
select = self.parse('Any T,V WHERE T bookmarked_by V?, ' |
|
65 |
'V in_state VS, VS name "published", T created_by U') |
|
66 |
self.assertEquals(self._generate(select, 'created_by', 'U', 'login'), |
|
67 |
'DISTINCT Any U,A ORDERBY A WHERE T created_by U, U login A, ' |
|
68 |
'T is Bookmark') |
|
69 |
||
70 |
def test_nonregr2(self): |
|
71 |
#'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' |
|
72 |
select = self.parse('DISTINCT Any V,TN,L ORDERBY TN,L WHERE T nom TN, V connait T, T is Personne, V is EUser,' |
|
73 |
'NOT V in_state VS, VS name "published", V login L') |
|
74 |
rschema = self.schema['connait'] |
|
75 |
for s, o in rschema.iter_rdefs(): |
|
76 |
rschema.set_rproperty(s, o, 'cardinality', '++') |
|
77 |
try: |
|
78 |
self.assertEquals(self._generate(select, 'in_state', 'VS', 'name'), |
|
79 |
"DISTINCT Any VS,A ORDERBY A WHERE V is EUser, NOT V in_state VS, VS name 'published', VS name A") |
|
80 |
finally: |
|
81 |
for s, o in rschema.iter_rdefs(): |
|
82 |
rschema.set_rproperty(s, o, 'cardinality', '**') |
|
83 |
||
84 |
def test_nonregr3(self): |
|
85 |
#'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' |
|
86 |
select = self.parse('DISTINCT Any X, MAX(Y) GROUPBY X WHERE X is EUser, Y is Bookmark, X in_group A') |
|
87 |
self.assertEquals(self._generate(select, 'in_group', 'A', 'name'), |
|
88 |
"DISTINCT Any A,B ORDERBY B WHERE X is EUser, X in_group A, A name B") |
|
89 |
||
90 |
||
91 |
if __name__ == '__main__': |
|
92 |
from logilab.common.testlib import unittest_main |
|
93 |
unittest_main() |