author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Wed, 14 Oct 2009 12:43:35 +0200 | |
branch | stable |
changeset 3662 | 9eeadad82d93 |
parent 2650 | 18aec79ec3a3 |
child 2773 | b2530e3e0afb |
child 3771 | 234b003f0fe0 |
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 |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
47 |
def test_more_than_one_entity_same_type(self): |
0 | 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') |
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
50 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'adaptedlist') |
0 | 51 |
rset = self.execute('Any X, L WHERE X login L') |
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
52 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'adaptedlist') |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
53 |
|
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
54 |
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
|
55 |
req = self.request() |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
56 |
rset = self.execute('Any X WHERE X is IN (CWUser, CWGroup)') |
0 | 57 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'list') |
1654 | 58 |
|
0 | 59 |
def test_more_than_one_entity_by_row(self): |
60 |
req = self.request() |
|
61 |
rset = self.execute('Any X, G WHERE X in_group G') |
|
62 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'table') |
|
1654 | 63 |
|
0 | 64 |
def test_more_than_one_entity_by_row_2(self): |
65 |
req = self.request() |
|
66 |
rset = self.execute('Any X, GN WHERE X in_group G, G name GN') |
|
67 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'table') |
|
1654 | 68 |
|
0 | 69 |
def test_aggregat(self): |
70 |
req = self.request() |
|
71 |
rset = self.execute('Any X, COUNT(T) GROUPBY X WHERE X is T') |
|
72 |
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
|
73 |
rset = self.execute('Any MAX(X) WHERE X is CWUser') |
0 | 74 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'table') |
75 |
||
76 |
def test_subquery(self): |
|
77 |
rset = self.execute( |
|
78 |
'DISTINCT Any X,N ORDERBY N ' |
|
79 |
'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
|
80 |
' (DISTINCT Any P,N WHERE P is CWUser, P login N)' |
0 | 81 |
' UNION' |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
82 |
' (DISTINCT Any W,N WHERE W is CWGroup, W name N))') |
0 | 83 |
req = self.request() |
84 |
self.assertEquals(vid_from_rset(req, rset, self.schema), 'table') |
|
85 |
||
86 |
||
87 |
class TableViewTC(EnvBasedTC): |
|
88 |
||
89 |
def _prepare_entity(self): |
|
90 |
e = self.add_entity("State", name=u'<toto>', description=u'loo"ong blabla') |
|
91 |
rset = self.execute('Any X, D, CD, NOW - CD WHERE X is State, X description D, X creation_date CD, X eid %(x)s', |
|
92 |
{'x': e.eid}, 'x') |
|
93 |
req = self.request() |
|
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
|
94 |
view = self.vreg['views'].select('table', req, rset=rset) |
0 | 95 |
return e, rset, view |
1654 | 96 |
|
0 | 97 |
def test_headers(self): |
98 |
self.skip('implement me') |
|
99 |
||
100 |
def test_sortvalue(self): |
|
101 |
e, _, view = self._prepare_entity() |
|
102 |
expected = ['<toto>', 'loo"ong blabla'[:10], e.creation_date.strftime('%Y-%m-%d %H:%M')] |
|
103 |
got = [loadjson(view.sortvalue(0, i)) for i in xrange(3)] |
|
104 |
self.assertListEqual(got, expected) |
|
105 |
# XXX sqlite does not handle Interval correctly |
|
106 |
# value = loadjson(view.sortvalue(0, 3)) |
|
107 |
# self.assertAlmostEquals(value, rset.rows[0][3].seconds) |
|
108 |
||
109 |
def test_sortvalue_with_display_col(self): |
|
110 |
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
|
111 |
labels = view.columns_labels() |
0 | 112 |
table = TableWidget(view) |
2204
3472c5498478
use column_labels instead of rqlst.get_description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
113 |
table.columns = view.get_columns(labels, [1, 2], None, None, None, None, 0) |
0 | 114 |
expected = ['loo"ong blabla'[:10], e.creation_date.strftime('%Y-%m-%d %H:%M')] |
115 |
got = [loadjson(value) for _, value in table.itercols(0)] |
|
116 |
self.assertListEqual(got, expected) |
|
117 |
||
118 |
||
119 |
if __name__ == '__main__': |
|
120 |
unittest_main() |