author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Fri, 24 Jul 2009 15:00:49 +0200 | |
changeset 2485 | ae74b46ea96c |
parent 2381 | caad2367d940 |
child 2637 | 07103211e511 |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1654
diff
changeset
|
1 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1654
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1654
diff
changeset
|
3 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1654
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1654
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1654
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1654
diff
changeset
|
7 |
""" |
0 | 8 |
from simplejson import loads |
9 |
||
10 |
from logilab.common.testlib import unittest_main |
|
11 |
from logilab.mtconverter import html_unescape |
|
12 |
||
13 |
from cubicweb.devtools.apptest import EnvBasedTC |
|
14 |
||
15 |
from cubicweb.web.htmlwidgets import TableWidget |
|
1654 | 16 |
from cubicweb.web.views import vid_from_rset |
0 | 17 |
|
18 |
def loadjson(value): |
|
19 |
return loads(html_unescape(value)) |
|
20 |
||
21 |
class VidFromRsetTC(EnvBasedTC): |
|
1654 | 22 |
|
0 | 23 |
def test_no_rset(self): |
24 |
req = self.request() |
|
25 |
self.assertEquals(vid_from_rset(req, None, self.schema), 'index') |
|
1654 | 26 |
|
0 | 27 |
def test_no_entity(self): |
28 |
req = self.request() |
|
29 |
rset = self.execute('Any X WHERE X login "blabla"') |
|
30 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'noresult') |
|
31 |
||
32 |
def test_one_entity(self): |
|
33 |
req = self.request() |
|
34 |
rset = self.execute('Any X WHERE X login "admin"') |
|
35 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'primary') |
|
36 |
rset = self.execute('Any X, L WHERE X login "admin", X login L') |
|
37 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'primary') |
|
38 |
req.search_state = ('pasnormal',) |
|
39 |
rset = self.execute('Any X WHERE X login "admin"') |
|
40 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'outofcontext-search') |
|
41 |
||
42 |
def test_one_entity_eid(self): |
|
43 |
req = self.request() |
|
44 |
rset = self.execute('Any X WHERE X eid 1') |
|
45 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'primary') |
|
1654 | 46 |
|
0 | 47 |
def test_more_than_one_entity(self): |
48 |
req = self.request() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
49 |
rset = self.execute('Any X WHERE X is CWUser') |
0 | 50 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'list') |
51 |
rset = self.execute('Any X, L WHERE X login L') |
|
52 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'list') |
|
1654 | 53 |
|
0 | 54 |
def test_more_than_one_entity_by_row(self): |
55 |
req = self.request() |
|
56 |
rset = self.execute('Any X, G WHERE X in_group G') |
|
57 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'table') |
|
1654 | 58 |
|
0 | 59 |
def test_more_than_one_entity_by_row_2(self): |
60 |
req = self.request() |
|
61 |
rset = self.execute('Any X, GN WHERE X in_group G, G name GN') |
|
62 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'table') |
|
1654 | 63 |
|
0 | 64 |
def test_aggregat(self): |
65 |
req = self.request() |
|
66 |
rset = self.execute('Any X, COUNT(T) GROUPBY X WHERE X is T') |
|
67 |
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
|
68 |
rset = self.execute('Any MAX(X) WHERE X is CWUser') |
0 | 69 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'table') |
70 |
||
71 |
def test_subquery(self): |
|
72 |
rset = self.execute( |
|
73 |
'DISTINCT Any X,N ORDERBY N ' |
|
74 |
'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
|
75 |
' (DISTINCT Any P,N WHERE P is CWUser, P login N)' |
0 | 76 |
' UNION' |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
77 |
' (DISTINCT Any W,N WHERE W is CWGroup, W name N))') |
0 | 78 |
req = self.request() |
79 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'table') |
|
80 |
||
81 |
||
82 |
class TableViewTC(EnvBasedTC): |
|
83 |
||
84 |
def _prepare_entity(self): |
|
85 |
e = self.add_entity("State", name=u'<toto>', description=u'loo"ong blabla') |
|
86 |
rset = self.execute('Any X, D, CD, NOW - CD WHERE X is State, X description D, X creation_date CD, X eid %(x)s', |
|
87 |
{'x': e.eid}, 'x') |
|
88 |
req = self.request() |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
89 |
view = self.vreg.select('views', 'table', req, rset) |
0 | 90 |
return e, rset, view |
1654 | 91 |
|
0 | 92 |
def test_headers(self): |
93 |
self.skip('implement me') |
|
94 |
||
95 |
def test_sortvalue(self): |
|
96 |
e, _, view = self._prepare_entity() |
|
97 |
expected = ['<toto>', 'loo"ong blabla'[:10], e.creation_date.strftime('%Y-%m-%d %H:%M')] |
|
98 |
got = [loadjson(view.sortvalue(0, i)) for i in xrange(3)] |
|
99 |
self.assertListEqual(got, expected) |
|
100 |
# XXX sqlite does not handle Interval correctly |
|
101 |
# value = loadjson(view.sortvalue(0, 3)) |
|
102 |
# self.assertAlmostEquals(value, rset.rows[0][3].seconds) |
|
103 |
||
104 |
def test_sortvalue_with_display_col(self): |
|
2343
5f5259e838cb
[tests] needs repair
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2204
diff
changeset
|
105 |
self.skip('XXX there is no column_labels on rset') |
0 | 106 |
e, rset, view = self._prepare_entity() |
2204
3472c5498478
use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
107 |
labels = rset.column_labels() |
0 | 108 |
table = TableWidget(view) |
2204
3472c5498478
use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
109 |
table.columns = view.get_columns(labels, [1, 2], None, None, None, None, 0) |
0 | 110 |
expected = ['loo"ong blabla'[:10], e.creation_date.strftime('%Y-%m-%d %H:%M')] |
111 |
got = [loadjson(value) for _, value in table.itercols(0)] |
|
112 |
self.assertListEqual(got, expected) |
|
113 |
||
114 |
||
115 |
if __name__ == '__main__': |
|
116 |
unittest_main() |