1 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
3 # |
|
4 # This file is part of CubicWeb. |
|
5 # |
|
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
|
7 # terms of the GNU Lesser General Public License as published by the Free |
|
8 # Software Foundation, either version 2.1 of the License, or (at your option) |
|
9 # any later version. |
|
10 # |
|
11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
|
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
14 # details. |
|
15 # |
|
16 # You should have received a copy of the GNU Lesser General Public License along |
|
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
|
18 """cubicweb.web.views.navigation unit tests""" |
|
19 |
|
20 from logilab.common.testlib import unittest_main |
|
21 |
|
22 from cubicweb.devtools.testlib import CubicWebTC |
|
23 from cubicweb.web.views.navigation import (PageNavigation, SortedNavigation, |
|
24 PageNavigationSelect) |
|
25 from cubicweb.web.views.ibreadcrumbs import BreadCrumbEntityVComponent |
|
26 |
|
27 BreadCrumbEntityVComponent.visible = True |
|
28 |
|
29 class NavigationTC(CubicWebTC): |
|
30 |
|
31 def test_navigation_selection_whatever(self): |
|
32 with self.admin_access.web_request() as req: |
|
33 rset = req.execute('Any X,N WHERE X name N') |
|
34 navcomp = self.vreg['components'].select('navigation', req, rset=rset) |
|
35 self.assertIsInstance(navcomp, PageNavigation) |
|
36 req.set_search_state('W:X:Y:Z') |
|
37 navcomp = self.vreg['components'].select('navigation', req, rset=rset) |
|
38 self.assertIsInstance(navcomp, PageNavigation) |
|
39 req.set_search_state('normal') |
|
40 |
|
41 def test_navigation_selection_ordered(self): |
|
42 with self.admin_access.web_request() as req: |
|
43 rset = req.execute('Any X,N ORDERBY N LIMIT 40 WHERE X name N') |
|
44 navcomp = self.vreg['components'].select('navigation', req, rset=rset, page_size=20) |
|
45 self.assertIsInstance(navcomp, SortedNavigation) |
|
46 req.set_search_state('W:X:Y:Z') |
|
47 navcomp = self.vreg['components'].select('navigation', req, rset=rset, page_size=20) |
|
48 self.assertIsInstance(navcomp, SortedNavigation) |
|
49 req.set_search_state('normal') |
|
50 navcomp.render() |
|
51 |
|
52 def test_navigation_selection_large_rset(self): |
|
53 with self.admin_access.web_request() as req: |
|
54 rset = req.execute('Any X,N LIMIT 120 WHERE X name N') |
|
55 navcomp = self.vreg['components'].select('navigation', req, rset=rset, page_size=20) |
|
56 self.assertIsInstance(navcomp, PageNavigationSelect) |
|
57 rset = req.execute('Any X,N ORDERBY N LIMIT 120 WHERE X name N') |
|
58 navcomp = self.vreg['components'].select('navigation', req, rset=rset, page_size=20) |
|
59 self.assertIsInstance(navcomp, PageNavigationSelect) |
|
60 |
|
61 def test_navigation_selection_not_enough_1(self): |
|
62 with self.admin_access.web_request() as req: |
|
63 rset = req.execute('Any X,N LIMIT 10 WHERE X name N') |
|
64 navcomp = self.vreg['components'].select_or_none('navigation', req, rset=rset) |
|
65 self.assertEqual(navcomp, None) |
|
66 req.set_search_state('W:X:Y:Z') |
|
67 navcomp = self.vreg['components'].select_or_none('navigation', req, rset=rset) |
|
68 self.assertEqual(navcomp, None) |
|
69 req.set_search_state('normal') |
|
70 |
|
71 def test_navigation_selection_not_enough_2(self): |
|
72 with self.admin_access.web_request() as req: |
|
73 rset = req.execute('Any N, COUNT(RDEF) GROUPBY N ORDERBY N ' |
|
74 'WHERE RDEF relation_type RT, RT name N') |
|
75 navcomp = self.vreg['components'].select('navigation', req, rset=rset) |
|
76 self.assertIsInstance(navcomp, SortedNavigation) |
|
77 req.set_search_state('W:X:Y:Z') |
|
78 navcomp = self.vreg['components'].select('navigation', req, rset=rset) |
|
79 self.assertIsInstance(navcomp, SortedNavigation) |
|
80 |
|
81 def test_navigation_selection_wrong_boundary(self): |
|
82 with self.admin_access.web_request() as req: |
|
83 rset = req.execute('Any X,N WHERE X name N') |
|
84 req.form['__start'] = 1000000 |
|
85 navcomp = self.vreg['components'].select('navigation', req, rset=rset) |
|
86 html = navcomp.render() |
|
87 |
|
88 def test_sorted_navigation_1(self): |
|
89 with self.admin_access.web_request() as req: |
|
90 rset = req.execute('Any RDEF ORDERBY RT WHERE RDEF relation_type RT') |
|
91 navcomp = self.vreg['components'].select('navigation', req, rset=rset) |
|
92 html = navcomp.render() |
|
93 |
|
94 def test_sorted_navigation_2(self): |
|
95 with self.admin_access.web_request() as req: |
|
96 rset = req.execute('Any RDEF ORDERBY RDEF WHERE RDEF relation_type RT') |
|
97 navcomp = self.vreg['components'].select('navigation', req, rset=rset) |
|
98 html = navcomp.render() |
|
99 |
|
100 def test_sorted_navigation_3(self): |
|
101 with self.admin_access.web_request() as req: |
|
102 rset = req.execute('CWAttribute RDEF ORDERBY RDEF') |
|
103 navcomp = self.vreg['components'].select('navigation', req, rset=rset) |
|
104 html = navcomp.render() |
|
105 |
|
106 def test_sorted_navigation_4(self): |
|
107 with self.admin_access.web_request() as req: |
|
108 rset = req.execute('Any RDEF ORDERBY N ' |
|
109 'WHERE RDEF relation_type RT, RT name N') |
|
110 navcomp = self.vreg['components'].select('navigation', req, rset=rset) |
|
111 html = navcomp.render() |
|
112 |
|
113 def test_sorted_navigation_5(self): |
|
114 with self.admin_access.web_request() as req: |
|
115 rset = req.execute('Any N, COUNT(RDEF) GROUPBY N ORDERBY N ' |
|
116 'WHERE RDEF relation_type RT, RT name N') |
|
117 navcomp = self.vreg['components'].select('navigation', rset.req, rset=rset) |
|
118 html = navcomp.render() |
|
119 |
|
120 |
|
121 |
|
122 if __name__ == '__main__': |
|
123 unittest_main() |
|