author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 21 Jun 2010 16:01:15 +0200 | |
branch | stable |
changeset 5817 | e4207221f3f5 |
parent 5426 | 0d4853a6e5ee |
child 5940 | 0e3ae19b181a |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
1654
diff
changeset
|
18 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1654
diff
changeset
|
19 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1654
diff
changeset
|
20 |
""" |
0 | 21 |
from logilab.common.testlib import unittest_main |
22 |
from logilab.mtconverter import html_unescape |
|
23 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
24 |
from cubicweb.devtools.testlib import CubicWebTC |
0 | 25 |
|
26 |
from cubicweb.web.htmlwidgets import TableWidget |
|
1654 | 27 |
from cubicweb.web.views import vid_from_rset |
5389
809d3b5b3d31
[python2.6] careful: json-py provides a json package. We don't want that.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5377
diff
changeset
|
28 |
from cubicweb.web import json |
809d3b5b3d31
[python2.6] careful: json-py provides a json package. We don't want that.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5377
diff
changeset
|
29 |
loads = json.loads |
0 | 30 |
|
31 |
def loadjson(value): |
|
32 |
return loads(html_unescape(value)) |
|
33 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
34 |
class VidFromRsetTC(CubicWebTC): |
1654 | 35 |
|
0 | 36 |
def test_no_rset(self): |
37 |
req = self.request() |
|
38 |
self.assertEquals(vid_from_rset(req, None, self.schema), 'index') |
|
1654 | 39 |
|
0 | 40 |
def test_no_entity(self): |
41 |
req = self.request() |
|
42 |
rset = self.execute('Any X WHERE X login "blabla"') |
|
43 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'noresult') |
|
44 |
||
45 |
def test_one_entity(self): |
|
46 |
req = self.request() |
|
47 |
rset = self.execute('Any X WHERE X login "admin"') |
|
48 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'primary') |
|
49 |
rset = self.execute('Any X, L WHERE X login "admin", X login L') |
|
50 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'primary') |
|
51 |
req.search_state = ('pasnormal',) |
|
52 |
rset = self.execute('Any X WHERE X login "admin"') |
|
53 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'outofcontext-search') |
|
54 |
||
55 |
def test_one_entity_eid(self): |
|
56 |
req = self.request() |
|
57 |
rset = self.execute('Any X WHERE X eid 1') |
|
58 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'primary') |
|
1654 | 59 |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
60 |
def test_more_than_one_entity_same_type(self): |
0 | 61 |
req = self.request() |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
62 |
rset = self.execute('Any X WHERE X is CWUser') |
4494
ccb7fce7297b
AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
63 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'sameetypelist') |
0 | 64 |
rset = self.execute('Any X, L WHERE X login L') |
4494
ccb7fce7297b
AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
65 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'sameetypelist') |
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
66 |
|
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
67 |
def test_more_than_one_entity_diff_type(self): |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
68 |
req = self.request() |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
69 |
rset = self.execute('Any X WHERE X is IN (CWUser, CWGroup)') |
0 | 70 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'list') |
1654 | 71 |
|
0 | 72 |
def test_more_than_one_entity_by_row(self): |
73 |
req = self.request() |
|
74 |
rset = self.execute('Any X, G WHERE X in_group G') |
|
75 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'table') |
|
1654 | 76 |
|
0 | 77 |
def test_more_than_one_entity_by_row_2(self): |
78 |
req = self.request() |
|
79 |
rset = self.execute('Any X, GN WHERE X in_group G, G name GN') |
|
80 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'table') |
|
1654 | 81 |
|
0 | 82 |
def test_aggregat(self): |
83 |
req = self.request() |
|
84 |
rset = self.execute('Any X, COUNT(T) GROUPBY X WHERE X is T') |
|
85 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'table') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
86 |
rset = self.execute('Any MAX(X) WHERE X is CWUser') |
0 | 87 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'table') |
88 |
||
89 |
def test_subquery(self): |
|
90 |
rset = self.execute( |
|
91 |
'DISTINCT Any X,N ORDERBY N ' |
|
92 |
'WITH X,N BEING (' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
93 |
' (DISTINCT Any P,N WHERE P is CWUser, P login N)' |
0 | 94 |
' UNION' |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
95 |
' (DISTINCT Any W,N WHERE W is CWGroup, W name N))') |
0 | 96 |
req = self.request() |
97 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'table') |
|
98 |
||
99 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
100 |
class TableViewTC(CubicWebTC): |
0 | 101 |
|
102 |
def _prepare_entity(self): |
|
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
103 |
req = self.request() |
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
104 |
e = req.create_entity("State", name=u'<toto>', description=u'loo"ong blabla') |
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
105 |
rset = req.execute('Any X, D, CD, NOW - CD WHERE X is State, X description D, X creation_date CD, X eid %(x)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4494
diff
changeset
|
106 |
{'x': e.eid}) |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
107 |
view = self.vreg['views'].select('table', req, rset=rset) |
0 | 108 |
return e, rset, view |
1654 | 109 |
|
0 | 110 |
def test_headers(self): |
111 |
self.skip('implement me') |
|
112 |
||
113 |
def test_sortvalue(self): |
|
114 |
e, _, view = self._prepare_entity() |
|
3771 | 115 |
expected = ['<toto>', 'loo"ong blabla'[:10], e.creation_date.strftime('%Y/%m/%d %H:%M:%S')] |
0 | 116 |
got = [loadjson(view.sortvalue(0, i)) for i in xrange(3)] |
117 |
self.assertListEqual(got, expected) |
|
118 |
# XXX sqlite does not handle Interval correctly |
|
119 |
# value = loadjson(view.sortvalue(0, 3)) |
|
120 |
# self.assertAlmostEquals(value, rset.rows[0][3].seconds) |
|
121 |
||
122 |
def test_sortvalue_with_display_col(self): |
|
123 |
e, rset, view = self._prepare_entity() |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
124 |
labels = view.columns_labels() |
0 | 125 |
table = TableWidget(view) |
2204
3472c5498478
use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
126 |
table.columns = view.get_columns(labels, [1, 2], None, None, None, None, 0) |
3771 | 127 |
expected = ['loo"ong blabla'[:10], e.creation_date.strftime('%Y/%m/%d %H:%M:%S')] |
0 | 128 |
got = [loadjson(value) for _, value in table.itercols(0)] |
129 |
self.assertListEqual(got, expected) |
|
130 |
||
131 |
||
132 |
if __name__ == '__main__': |
|
133 |
unittest_main() |