author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 26 Aug 2010 11:35:02 +0200 | |
branch | stable |
changeset 6160 | 12038ca95f0f |
parent 5940 | 0e3ae19b181a |
child 6340 | 470d8e828fda |
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 |
|
0 | 19 |
from logilab.common.testlib import unittest_main |
20 |
from logilab.mtconverter import html_unescape |
|
21 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
22 |
from cubicweb.devtools.testlib import CubicWebTC |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
23 |
from cubicweb.utils import json |
0 | 24 |
from cubicweb.web.htmlwidgets import TableWidget |
1654 | 25 |
from cubicweb.web.views import vid_from_rset |
0 | 26 |
|
27 |
def loadjson(value): |
|
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
28 |
return json.loads(html_unescape(value)) |
0 | 29 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
30 |
class VidFromRsetTC(CubicWebTC): |
1654 | 31 |
|
0 | 32 |
def test_no_rset(self): |
33 |
req = self.request() |
|
34 |
self.assertEquals(vid_from_rset(req, None, self.schema), 'index') |
|
1654 | 35 |
|
0 | 36 |
def test_no_entity(self): |
37 |
req = self.request() |
|
38 |
rset = self.execute('Any X WHERE X login "blabla"') |
|
39 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'noresult') |
|
40 |
||
41 |
def test_one_entity(self): |
|
42 |
req = self.request() |
|
43 |
rset = self.execute('Any X WHERE X login "admin"') |
|
44 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'primary') |
|
45 |
rset = self.execute('Any X, L WHERE X login "admin", X login L') |
|
46 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'primary') |
|
47 |
req.search_state = ('pasnormal',) |
|
48 |
rset = self.execute('Any X WHERE X login "admin"') |
|
49 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'outofcontext-search') |
|
50 |
||
51 |
def test_one_entity_eid(self): |
|
52 |
req = self.request() |
|
53 |
rset = self.execute('Any X WHERE X eid 1') |
|
54 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'primary') |
|
1654 | 55 |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
56 |
def test_more_than_one_entity_same_type(self): |
0 | 57 |
req = self.request() |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
58 |
rset = self.execute('Any X WHERE X is CWUser') |
4494
ccb7fce7297b
AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
59 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'sameetypelist') |
0 | 60 |
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
|
61 |
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
|
62 |
|
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
63 |
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
|
64 |
req = self.request() |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
65 |
rset = self.execute('Any X WHERE X is IN (CWUser, CWGroup)') |
0 | 66 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'list') |
1654 | 67 |
|
0 | 68 |
def test_more_than_one_entity_by_row(self): |
69 |
req = self.request() |
|
70 |
rset = self.execute('Any X, G WHERE X in_group G') |
|
71 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'table') |
|
1654 | 72 |
|
0 | 73 |
def test_more_than_one_entity_by_row_2(self): |
74 |
req = self.request() |
|
75 |
rset = self.execute('Any X, GN WHERE X in_group G, G name GN') |
|
76 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'table') |
|
1654 | 77 |
|
0 | 78 |
def test_aggregat(self): |
79 |
req = self.request() |
|
80 |
rset = self.execute('Any X, COUNT(T) GROUPBY X WHERE X is T') |
|
81 |
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
|
82 |
rset = self.execute('Any MAX(X) WHERE X is CWUser') |
0 | 83 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'table') |
84 |
||
85 |
def test_subquery(self): |
|
86 |
rset = self.execute( |
|
87 |
'DISTINCT Any X,N ORDERBY N ' |
|
88 |
'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
|
89 |
' (DISTINCT Any P,N WHERE P is CWUser, P login N)' |
0 | 90 |
' UNION' |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
91 |
' (DISTINCT Any W,N WHERE W is CWGroup, W name N))') |
0 | 92 |
req = self.request() |
93 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'table') |
|
94 |
||
95 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
96 |
class TableViewTC(CubicWebTC): |
0 | 97 |
|
98 |
def _prepare_entity(self): |
|
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
99 |
req = self.request() |
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
100 |
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
|
101 |
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
|
102 |
{'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
|
103 |
view = self.vreg['views'].select('table', req, rset=rset) |
0 | 104 |
return e, rset, view |
1654 | 105 |
|
0 | 106 |
def test_headers(self): |
107 |
self.skip('implement me') |
|
108 |
||
109 |
def test_sortvalue(self): |
|
110 |
e, _, view = self._prepare_entity() |
|
3771 | 111 |
expected = ['<toto>', 'loo"ong blabla'[:10], e.creation_date.strftime('%Y/%m/%d %H:%M:%S')] |
0 | 112 |
got = [loadjson(view.sortvalue(0, i)) for i in xrange(3)] |
113 |
self.assertListEqual(got, expected) |
|
114 |
# XXX sqlite does not handle Interval correctly |
|
115 |
# value = loadjson(view.sortvalue(0, 3)) |
|
116 |
# self.assertAlmostEquals(value, rset.rows[0][3].seconds) |
|
117 |
||
118 |
def test_sortvalue_with_display_col(self): |
|
119 |
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
|
120 |
labels = view.columns_labels() |
0 | 121 |
table = TableWidget(view) |
2204
3472c5498478
use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
122 |
table.columns = view.get_columns(labels, [1, 2], None, None, None, None, 0) |
3771 | 123 |
expected = ['loo"ong blabla'[:10], e.creation_date.strftime('%Y/%m/%d %H:%M:%S')] |
0 | 124 |
got = [loadjson(value) for _, value in table.itercols(0)] |
125 |
self.assertListEqual(got, expected) |
|
126 |
||
127 |
||
128 |
if __name__ == '__main__': |
|
129 |
unittest_main() |