web/test/unittest_views_baseviews.py
branchtls-sprint
changeset 1654 57b9fd2462b8
parent 1398 5fe84a5f7035
child 1977 606923dff11b
equal deleted inserted replaced
1653:8b82227719f0 1654:57b9fd2462b8
     4 from logilab.mtconverter import html_unescape
     4 from logilab.mtconverter import html_unescape
     5 
     5 
     6 from cubicweb.devtools.apptest import EnvBasedTC
     6 from cubicweb.devtools.apptest import EnvBasedTC
     7 
     7 
     8 from cubicweb.web.htmlwidgets import TableWidget
     8 from cubicweb.web.htmlwidgets import TableWidget
     9 from cubicweb.web.views.baseviews import vid_from_rset
     9 from cubicweb.web.views import vid_from_rset
    10 
    10 
    11 def loadjson(value):
    11 def loadjson(value):
    12     return loads(html_unescape(value))
    12     return loads(html_unescape(value))
    13 
    13 
    14 class VidFromRsetTC(EnvBasedTC):
    14 class VidFromRsetTC(EnvBasedTC):
    15     
    15 
    16     def test_no_rset(self):
    16     def test_no_rset(self):
    17         req = self.request()
    17         req = self.request()
    18         self.assertEquals(vid_from_rset(req, None, self.schema), 'index')
    18         self.assertEquals(vid_from_rset(req, None, self.schema), 'index')
    19     
    19 
    20     def test_no_entity(self):
    20     def test_no_entity(self):
    21         req = self.request()
    21         req = self.request()
    22         rset = self.execute('Any X WHERE X login "blabla"')
    22         rset = self.execute('Any X WHERE X login "blabla"')
    23         self.assertEquals(vid_from_rset(req, rset, self.schema), 'noresult')
    23         self.assertEquals(vid_from_rset(req, rset, self.schema), 'noresult')
    24 
    24 
    34 
    34 
    35     def test_one_entity_eid(self):
    35     def test_one_entity_eid(self):
    36         req = self.request()
    36         req = self.request()
    37         rset = self.execute('Any X WHERE X eid 1')
    37         rset = self.execute('Any X WHERE X eid 1')
    38         self.assertEquals(vid_from_rset(req, rset, self.schema), 'primary')
    38         self.assertEquals(vid_from_rset(req, rset, self.schema), 'primary')
    39         
    39 
    40     def test_more_than_one_entity(self):
    40     def test_more_than_one_entity(self):
    41         req = self.request()
    41         req = self.request()
    42         rset = self.execute('Any X WHERE X is CWUser')
    42         rset = self.execute('Any X WHERE X is CWUser')
    43         self.assertEquals(vid_from_rset(req, rset, self.schema), 'list')
    43         self.assertEquals(vid_from_rset(req, rset, self.schema), 'list')
    44         rset = self.execute('Any X, L WHERE X login L')
    44         rset = self.execute('Any X, L WHERE X login L')
    45         self.assertEquals(vid_from_rset(req, rset, self.schema), 'list')
    45         self.assertEquals(vid_from_rset(req, rset, self.schema), 'list')
    46     
    46 
    47     def test_more_than_one_entity_by_row(self):
    47     def test_more_than_one_entity_by_row(self):
    48         req = self.request()
    48         req = self.request()
    49         rset = self.execute('Any X, G WHERE X in_group G')
    49         rset = self.execute('Any X, G WHERE X in_group G')
    50         self.assertEquals(vid_from_rset(req, rset, self.schema), 'table')
    50         self.assertEquals(vid_from_rset(req, rset, self.schema), 'table')
    51     
    51 
    52     def test_more_than_one_entity_by_row_2(self):
    52     def test_more_than_one_entity_by_row_2(self):
    53         req = self.request()
    53         req = self.request()
    54         rset = self.execute('Any X, GN WHERE X in_group G, G name GN')
    54         rset = self.execute('Any X, GN WHERE X in_group G, G name GN')
    55         self.assertEquals(vid_from_rset(req, rset, self.schema), 'table')
    55         self.assertEquals(vid_from_rset(req, rset, self.schema), 'table')
    56     
    56 
    57     def test_aggregat(self):
    57     def test_aggregat(self):
    58         req = self.request()
    58         req = self.request()
    59         rset = self.execute('Any X, COUNT(T) GROUPBY X WHERE X is T')
    59         rset = self.execute('Any X, COUNT(T) GROUPBY X WHERE X is T')
    60         self.assertEquals(vid_from_rset(req, rset, self.schema), 'table')
    60         self.assertEquals(vid_from_rset(req, rset, self.schema), 'table')
    61         rset = self.execute('Any MAX(X) WHERE X is CWUser')
    61         rset = self.execute('Any MAX(X) WHERE X is CWUser')
    79         rset = self.execute('Any X, D, CD, NOW - CD WHERE X is State, X description D, X creation_date CD, X eid %(x)s',
    79         rset = self.execute('Any X, D, CD, NOW - CD WHERE X is State, X description D, X creation_date CD, X eid %(x)s',
    80                             {'x': e.eid}, 'x')
    80                             {'x': e.eid}, 'x')
    81         req = self.request()
    81         req = self.request()
    82         view = self.vreg.select_view('table', req, rset)
    82         view = self.vreg.select_view('table', req, rset)
    83         return e, rset, view
    83         return e, rset, view
    84       
    84 
    85     def test_headers(self):
    85     def test_headers(self):
    86         self.skip('implement me')
    86         self.skip('implement me')
    87 
    87 
    88     def test_sortvalue(self):
    88     def test_sortvalue(self):
    89         e, _, view = self._prepare_entity()
    89         e, _, view = self._prepare_entity()