author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
Fri, 09 Nov 2012 15:27:40 +0100 | |
changeset 8593 | 41259e1f9d48 |
parent 8544 | 3d049071957e |
child 8696 | 0bb18407c053 |
permissions | -rw-r--r-- |
8544
3d049071957e
massive copyright update to avoid clutering later patches
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7605
diff
changeset
|
1 |
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
18 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
19 |
from cubicweb.devtools.testlib import CubicWebTC |
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:
6340
diff
changeset
|
20 |
from cubicweb.web import facet |
0 | 21 |
|
22 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
23 |
class InsertAttrRelationTC(CubicWebTC): |
16
a70ece4d9d1a
fix tests in web/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
24 |
|
0 | 25 |
def parse(self, query): |
26 |
rqlst = self.vreg.parse(self.session, query) |
|
27 |
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
|
28 |
return rqlst |
0 | 29 |
|
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
|
30 |
def _generate(self, rqlst, rel, role, attr): |
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:
6340
diff
changeset
|
31 |
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:
6340
diff
changeset
|
32 |
filtered_variable = facet.get_filtered_variable(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:
6340
diff
changeset
|
33 |
facet.prepare_select(select, filtered_variable) |
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:
6340
diff
changeset
|
34 |
facet.insert_attr_select_relation(select, filtered_variable, |
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:
6340
diff
changeset
|
35 |
rel, role, attr) |
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 |
return rqlst.as_string() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
37 |
|
0 | 38 |
@property |
39 |
def select(self): |
|
40 |
return self.parse('Any B,(NOW - CD),S,V,U,GROUP_CONCAT(TN),VN,P,CD,BMD ' |
|
41 |
'GROUPBY B,CD,S,V,U,VN,P,BMD ' |
|
42 |
'WHERE B in_state S, B creation_date CD, ' |
|
43 |
'B modification_date BMD, T? tags B, T name TN, ' |
|
44 |
'V? bookmarked_by B, V title VN, B created_by U?, ' |
|
45 |
'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
|
46 |
|
0 | 47 |
def test_1(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5623
diff
changeset
|
48 |
self.assertEqual(self._generate(self.select, 'in_state', 'subject', 'name'), |
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
|
49 |
"DISTINCT Any A,C ORDERBY C WHERE B in_group P, P name 'managers', " |
5623
a01aa5b26e66
[test] update test to follow recent navigation/facets fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
50 |
"B in_state A, B is CWUser, A name C") |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
51 |
|
0 | 52 |
def test_2(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5623
diff
changeset
|
53 |
self.assertEqual(self._generate(self.select, 'tags', 'object', 'name'), |
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 |
"DISTINCT Any A,C ORDERBY C WHERE B in_group P, P name 'managers', " |
5623
a01aa5b26e66
[test] update test to follow recent navigation/facets fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
55 |
"A tags B, B is CWUser, A name C") |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
56 |
|
0 | 57 |
def test_3(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5623
diff
changeset
|
58 |
self.assertEqual(self._generate(self.select, 'created_by', 'subject', 'login'), |
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
|
59 |
"DISTINCT Any A,C ORDERBY C WHERE B in_group P, P name 'managers', " |
5623
a01aa5b26e66
[test] update test to follow recent navigation/facets fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
60 |
"B created_by A, B is CWUser, A login C") |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
61 |
|
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
|
62 |
def test_4(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5623
diff
changeset
|
63 |
self.assertEqual(self._generate(self.parse('Any X WHERE X is CWUser'), 'created_by', 'subject', 'login'), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
408
diff
changeset
|
64 |
"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
|
65 |
|
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 |
def test_5(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5623
diff
changeset
|
67 |
self.assertEqual(self._generate(self.parse('Any X,L WHERE X is CWUser, X login L'), 'created_by', 'subject', 'login'), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
408
diff
changeset
|
68 |
"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
|
69 |
|
0 | 70 |
def test_nonregr1(self): |
71 |
select = self.parse('Any T,V WHERE T bookmarked_by V?, ' |
|
72 |
'V in_state VS, VS name "published", T created_by U') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5623
diff
changeset
|
73 |
self.assertEqual(self._generate(select, 'created_by', 'subject', 'login'), |
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
|
74 |
"DISTINCT Any A,B ORDERBY B WHERE T created_by U, " |
5623
a01aa5b26e66
[test] update test to follow recent navigation/facets fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
75 |
"T created_by A, T is Bookmark, A login B") |
0 | 76 |
|
77 |
def test_nonregr2(self): |
|
78 |
#'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
|
79 |
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 | 80 |
'NOT V in_state VS, VS name "published", V login L') |
81 |
rschema = self.schema['connait'] |
|
4072
ead446e70c28
some api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
82 |
for rdefs in rschema.rdefs.values(): |
ead446e70c28
some api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
83 |
rdefs.cardinality = '++' |
0 | 84 |
try: |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5623
diff
changeset
|
85 |
self.assertEqual(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
|
86 |
"DISTINCT Any A,B ORDERBY B WHERE V is CWUser, " |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
87 |
"NOT EXISTS(V in_state VS), VS name 'published', " |
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
|
88 |
"V in_state A, A name B") |
0 | 89 |
finally: |
4072
ead446e70c28
some api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
90 |
for rdefs in rschema.rdefs.values(): |
ead446e70c28
some api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
91 |
rdefs.cardinality = '**' |
0 | 92 |
|
93 |
def test_nonregr3(self): |
|
94 |
#'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
|
95 |
select = self.parse('DISTINCT Any X, MAX(Y) GROUPBY X WHERE X is CWUser, Y is Bookmark, X in_group A') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5623
diff
changeset
|
96 |
self.assertEqual(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
|
97 |
"DISTINCT Any B,C ORDERBY C WHERE X is CWUser, X in_group B, B name C") |
0 | 98 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
99 |
|
0 | 100 |
if __name__ == '__main__': |
101 |
from logilab.common.testlib import unittest_main |
|
102 |
unittest_main() |