author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 28 May 2009 20:06:45 +0200 | |
changeset 1995 | ec95eaa2b711 |
parent 1977 | 606923dff11b |
child 2058 | 7ef12c03447c |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1723
diff
changeset
|
1 |
"""cubicweb.web.views.navigation unit tests |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1723
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1723
diff
changeset
|
3 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1723
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:
1723
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:
1723
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:
1723
diff
changeset
|
7 |
""" |
0 | 8 |
|
9 |
from logilab.common.testlib import unittest_main, mock_object |
|
10 |
from cubicweb.devtools.apptest import EnvBasedTC |
|
11 |
||
12 |
from cubicweb.web.views.navigation import PageNavigation, SortedNavigation |
|
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
16
diff
changeset
|
13 |
from cubicweb.web.views.ibreadcrumbs import BreadCrumbEntityVComponent |
0 | 14 |
|
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
16
diff
changeset
|
15 |
BreadCrumbEntityVComponent.visible = True |
0 | 16 |
|
17 |
class NavigationTC(EnvBasedTC): |
|
1723 | 18 |
|
0 | 19 |
def test_navigation_selection(self): |
20 |
rset = self.execute('Any X,N WHERE X name N') |
|
21 |
req = self.request() |
|
22 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
23 |
self.assertIsInstance(navcomp, PageNavigation) |
|
24 |
req.set_search_state('W:X:Y:Z') |
|
25 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
26 |
self.assertIsInstance(navcomp, PageNavigation) |
|
27 |
req.set_search_state('normal') |
|
28 |
rset = self.execute('Any X,N ORDERBY N WHERE X name N') |
|
29 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
30 |
self.assertIsInstance(navcomp, SortedNavigation) |
|
31 |
req.set_search_state('W:X:Y:Z') |
|
32 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
33 |
self.assertIsInstance(navcomp, SortedNavigation) |
|
34 |
req.set_search_state('normal') |
|
16
a70ece4d9d1a
fix tests in web/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
35 |
rset = self.execute('Any X,N LIMIT 10 WHERE X name N') |
0 | 36 |
navcomp = self.vreg.select_component('navigation', req, rset) |
37 |
self.assertEquals(navcomp, None) |
|
38 |
req.set_search_state('W:X:Y:Z') |
|
39 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
40 |
self.assertEquals(navcomp, None) |
|
41 |
req.set_search_state('normal') |
|
42 |
rset = self.execute('Any N, COUNT(RDEF) GROUPBY N ORDERBY N WHERE RDEF relation_type RT, RT name N') |
|
43 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
44 |
self.assertIsInstance(navcomp, SortedNavigation) |
|
45 |
req.set_search_state('W:X:Y:Z') |
|
46 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
47 |
self.assertIsInstance(navcomp, SortedNavigation) |
|
1723 | 48 |
|
49 |
||
0 | 50 |
def test_sorted_navigation(self): |
51 |
rset = self.execute('Any X,N ORDERBY N WHERE X name N') |
|
52 |
req = self.request() |
|
53 |
req.set_search_state('W:X:Y:Z') |
|
54 |
navcomp = self.vreg.select_component('navigation', rset.req, rset) |
|
1723 | 55 |
html = navcomp.render() |
0 | 56 |
rset = self.execute('Any RDEF ORDERBY RT WHERE RDEF relation_type RT') |
57 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
1723 | 58 |
html = navcomp.render() |
0 | 59 |
rset = self.execute('Any RDEF ORDERBY RDEF WHERE RDEF relation_type RT') |
60 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
1723 | 61 |
html = navcomp.render() |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
47
diff
changeset
|
62 |
rset = self.execute('CWAttribute RDEF ORDERBY RDEF') |
0 | 63 |
navcomp = self.vreg.select_component('navigation', req, rset) |
1723 | 64 |
html = navcomp.render() |
0 | 65 |
rset = self.execute('Any RDEF ORDERBY N WHERE RDEF relation_type RT, RT name N') |
66 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
1723 | 67 |
html = navcomp.render() |
0 | 68 |
rset = self.execute('Any N, COUNT(RDEF) GROUPBY N ORDERBY N WHERE RDEF relation_type RT, RT name N') |
69 |
navcomp = self.vreg.select_component('navigation', rset.req, rset) |
|
1723 | 70 |
html = navcomp.render() |
0 | 71 |
|
72 |
||
73 |
||
74 |
class ContentNavigationTC(EnvBasedTC): |
|
75 |
||
76 |
def test_component_context(self): |
|
77 |
view = mock_object(is_primary=lambda x: True) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
47
diff
changeset
|
78 |
rset = self.execute('CWUser X LIMIT 1') |
0 | 79 |
req = self.request() |
80 |
objs = self.vreg.possible_vobjects('contentnavigation', req, rset, |
|
81 |
view=view, context='navtop') |
|
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
16
diff
changeset
|
82 |
# breadcrumbs should be in headers by default |
0 | 83 |
clsids = set(obj.id for obj in objs) |
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
16
diff
changeset
|
84 |
self.failUnless('breadcrumbs' in clsids) |
0 | 85 |
objs = self.vreg.possible_vobjects('contentnavigation', req, rset, |
86 |
view=view, context='navbottom') |
|
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
16
diff
changeset
|
87 |
# breadcrumbs should _NOT_ be in footers by default |
0 | 88 |
clsids = set(obj.id for obj in objs) |
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
16
diff
changeset
|
89 |
self.failIf('breadcrumbs' in clsids) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
47
diff
changeset
|
90 |
self.execute('INSERT CWProperty P: P pkey "contentnavigation.breadcrumbs.context", ' |
0 | 91 |
'P value "navbottom"') |
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
16
diff
changeset
|
92 |
# breadcrumbs should now be in footers |
0 | 93 |
req.cnx.commit() |
94 |
objs = self.vreg.possible_vobjects('contentnavigation', req, rset, |
|
95 |
view=view, context='navbottom') |
|
1723 | 96 |
|
0 | 97 |
clsids = [obj.id for obj in objs] |
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
16
diff
changeset
|
98 |
self.failUnless('breadcrumbs' in clsids) |
0 | 99 |
objs = self.vreg.possible_vobjects('contentnavigation', req, rset, |
100 |
view=view, context='navtop') |
|
1723 | 101 |
|
0 | 102 |
clsids = [obj.id for obj in objs] |
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
16
diff
changeset
|
103 |
self.failIf('breadcrumbs' in clsids) |
1723 | 104 |
|
0 | 105 |
|
106 |
if __name__ == '__main__': |
|
107 |
unittest_main() |