web/test/unittest_views_navigation.py
changeset 0 b97547f5f1fa
child 16 a70ece4d9d1a
equal deleted inserted replaced
-1:000000000000 0:b97547f5f1fa
       
     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
       
     7 
       
     8 from eclasstags.views import TagsBarVComponent
       
     9 TagsBarVComponent.visible = True
       
    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')
       
    29         rset = self.execute('Any X,N WHERE X name N LIMIT 10')
       
    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')
       
    76         # tagbar should be in headers by default
       
    77         clsids = set(obj.id for obj in objs)
       
    78         self.failUnless('tagsbar' in clsids)
       
    79         objs = self.vreg.possible_vobjects('contentnavigation', req, rset,
       
    80                                           view=view, context='navbottom')
       
    81         # tagbar should _NOT_ be in footers by default
       
    82         clsids = set(obj.id for obj in objs)
       
    83         self.failIf('tagsbar' in clsids)
       
    84         self.execute('INSERT EProperty P: P pkey "contentnavigation.tagsbar.context", '
       
    85                      'P value "navbottom"')
       
    86         # tagbar should now be in footers
       
    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]
       
    92         self.failUnless('tagsbar' in clsids)
       
    93         objs = self.vreg.possible_vobjects('contentnavigation', req, rset,
       
    94                                           view=view, context='navtop')
       
    95         
       
    96         clsids = [obj.id for obj in objs]
       
    97         self.failIf('tagsbar' in clsids)
       
    98         
       
    99 
       
   100 if __name__ == '__main__':
       
   101     unittest_main()