author | Sandrine Ribeau <sandrine.ribeau@logilab.fr> |
Thu, 23 Apr 2009 11:58:11 -0700 | |
changeset 1461 | 023b123ab76b |
parent 47 | 54087a269bdd |
child 1398 | 5fe84a5f7035 |
permissions | -rw-r--r-- |
0 | 1 |
"""cubicweb.web.views.navigation unit tests""" |
2 |
||
3 |
from logilab.common.testlib import unittest_main, mock_object |
|
4 |
from cubicweb.devtools.apptest import EnvBasedTC |
|
5 |
||
6 |
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
|
7 |
from cubicweb.web.views.ibreadcrumbs import BreadCrumbEntityVComponent |
0 | 8 |
|
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
16
diff
changeset
|
9 |
BreadCrumbEntityVComponent.visible = True |
0 | 10 |
|
11 |
class NavigationTC(EnvBasedTC): |
|
12 |
||
13 |
def test_navigation_selection(self): |
|
14 |
rset = self.execute('Any X,N WHERE X name N') |
|
15 |
req = self.request() |
|
16 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
17 |
self.assertIsInstance(navcomp, PageNavigation) |
|
18 |
req.set_search_state('W:X:Y:Z') |
|
19 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
20 |
self.assertIsInstance(navcomp, PageNavigation) |
|
21 |
req.set_search_state('normal') |
|
22 |
rset = self.execute('Any X,N ORDERBY N WHERE X name N') |
|
23 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
24 |
self.assertIsInstance(navcomp, SortedNavigation) |
|
25 |
req.set_search_state('W:X:Y:Z') |
|
26 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
27 |
self.assertIsInstance(navcomp, SortedNavigation) |
|
28 |
req.set_search_state('normal') |
|
16
a70ece4d9d1a
fix tests in web/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
29 |
rset = self.execute('Any X,N LIMIT 10 WHERE X name N') |
0 | 30 |
navcomp = self.vreg.select_component('navigation', req, rset) |
31 |
self.assertEquals(navcomp, None) |
|
32 |
req.set_search_state('W:X:Y:Z') |
|
33 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
34 |
self.assertEquals(navcomp, None) |
|
35 |
req.set_search_state('normal') |
|
36 |
rset = self.execute('Any N, COUNT(RDEF) GROUPBY N ORDERBY N WHERE RDEF relation_type RT, RT name N') |
|
37 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
38 |
self.assertIsInstance(navcomp, SortedNavigation) |
|
39 |
req.set_search_state('W:X:Y:Z') |
|
40 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
41 |
self.assertIsInstance(navcomp, SortedNavigation) |
|
42 |
||
43 |
||
44 |
def test_sorted_navigation(self): |
|
45 |
rset = self.execute('Any X,N ORDERBY N WHERE X name N') |
|
46 |
req = self.request() |
|
47 |
req.set_search_state('W:X:Y:Z') |
|
48 |
navcomp = self.vreg.select_component('navigation', rset.req, rset) |
|
49 |
html = navcomp.dispatch() |
|
50 |
rset = self.execute('Any RDEF ORDERBY RT WHERE RDEF relation_type RT') |
|
51 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
52 |
html = navcomp.dispatch() |
|
53 |
rset = self.execute('Any RDEF ORDERBY RDEF WHERE RDEF relation_type RT') |
|
54 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
55 |
html = navcomp.dispatch() |
|
56 |
rset = self.execute('EFRDef RDEF ORDERBY RDEF') |
|
57 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
58 |
html = navcomp.dispatch() |
|
59 |
rset = self.execute('Any RDEF ORDERBY N WHERE RDEF relation_type RT, RT name N') |
|
60 |
navcomp = self.vreg.select_component('navigation', req, rset) |
|
61 |
html = navcomp.dispatch() |
|
62 |
rset = self.execute('Any N, COUNT(RDEF) GROUPBY N ORDERBY N WHERE RDEF relation_type RT, RT name N') |
|
63 |
navcomp = self.vreg.select_component('navigation', rset.req, rset) |
|
64 |
html = navcomp.dispatch() |
|
65 |
||
66 |
||
67 |
||
68 |
class ContentNavigationTC(EnvBasedTC): |
|
69 |
||
70 |
def test_component_context(self): |
|
71 |
view = mock_object(is_primary=lambda x: True) |
|
72 |
rset = self.execute('EUser X LIMIT 1') |
|
73 |
req = self.request() |
|
74 |
objs = self.vreg.possible_vobjects('contentnavigation', req, rset, |
|
75 |
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
|
76 |
# breadcrumbs should be in headers by default |
0 | 77 |
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
|
78 |
self.failUnless('breadcrumbs' in clsids) |
0 | 79 |
objs = self.vreg.possible_vobjects('contentnavigation', req, rset, |
80 |
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
|
81 |
# breadcrumbs should _NOT_ be in footers by default |
0 | 82 |
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
|
83 |
self.failIf('breadcrumbs' in clsids) |
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
16
diff
changeset
|
84 |
self.execute('INSERT EProperty P: P pkey "contentnavigation.breadcrumbs.context", ' |
0 | 85 |
'P value "navbottom"') |
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
16
diff
changeset
|
86 |
# breadcrumbs should now be in footers |
0 | 87 |
req.cnx.commit() |
88 |
objs = self.vreg.possible_vobjects('contentnavigation', req, rset, |
|
89 |
view=view, context='navbottom') |
|
90 |
||
91 |
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
|
92 |
self.failUnless('breadcrumbs' in clsids) |
0 | 93 |
objs = self.vreg.possible_vobjects('contentnavigation', req, rset, |
94 |
view=view, context='navtop') |
|
95 |
||
96 |
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
|
97 |
self.failIf('breadcrumbs' in clsids) |
0 | 98 |
|
99 |
||
100 |
if __name__ == '__main__': |
|
101 |
unittest_main() |