web/test/unittest_viewselector.py
changeset 3589 a5432f99f2d9
parent 3468 b02fa4db2868
parent 3587 5b3725f315fc
child 3735 80fb4083c29b
equal deleted inserted replaced
3536:f6c9a5df80fb 3589:a5432f99f2d9
    25 SITEACTIONS = [actions.SiteConfigurationAction,
    25 SITEACTIONS = [actions.SiteConfigurationAction,
    26                actions.ManageAction,
    26                actions.ManageAction,
    27                schema.ViewSchemaAction,
    27                schema.ViewSchemaAction,
    28                actions.SiteInfoAction,
    28                actions.SiteInfoAction,
    29                ]
    29                ]
       
    30 FOOTERACTIONS = [wdoc.ChangeLogAction,
       
    31                  wdoc.AboutAction,
       
    32                  actions.PoweredByAction]
    30 
    33 
    31 class ViewSelectorTC(CubicWebTC):
    34 class ViewSelectorTC(CubicWebTC):
    32 
    35 
    33     def setup_database(self):
    36     def setup_database(self):
    34         self.add_entity('BlogEntry', title=u"une news !", content=u"cubicweb c'est beau")
    37         self.add_entity('BlogEntry', title=u"une news !", content=u"cubicweb c'est beau")
   223     def test_possible_actions_none_rset(self):
   226     def test_possible_actions_none_rset(self):
   224         req = self.request()
   227         req = self.request()
   225         self.assertDictEqual(self.pactionsdict(req, None, skipcategories=()),
   228         self.assertDictEqual(self.pactionsdict(req, None, skipcategories=()),
   226                              {'useractions': USERACTIONS,
   229                              {'useractions': USERACTIONS,
   227                               'siteactions': SITEACTIONS,
   230                               'siteactions': SITEACTIONS,
       
   231                               'footer': FOOTERACTIONS,
   228 
   232 
   229                               })
   233                               })
   230     def test_possible_actions_no_entity(self):
   234     def test_possible_actions_no_entity(self):
   231         req = self.request()
   235         req = self.request()
   232         rset = req.execute('Any X WHERE X eid 999999')
   236         rset = req.execute('Any X WHERE X eid 999999')
   233         self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
   237         self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
   234                              {'useractions': USERACTIONS,
   238                              {'useractions': USERACTIONS,
   235                               'siteactions': SITEACTIONS,
   239                               'siteactions': SITEACTIONS,
       
   240                               'footer': FOOTERACTIONS,
   236                               })
   241                               })
   237 
   242 
   238     def test_possible_actions_same_type_entities(self):
   243     def test_possible_actions_same_type_entities(self):
   239         req = self.request()
   244         req = self.request()
   240         rset = req.execute('CWGroup X')
   245         rset = req.execute('CWGroup X')
   241         self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
   246         self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
   242                              {'useractions': USERACTIONS,
   247                              {'useractions': USERACTIONS,
   243                               'siteactions': SITEACTIONS,
   248                               'siteactions': SITEACTIONS,
       
   249                               'footer': FOOTERACTIONS,
   244                               'mainactions': [actions.MultipleEditAction],
   250                               'mainactions': [actions.MultipleEditAction],
   245                               'moreactions': [actions.DeleteAction,
   251                               'moreactions': [actions.DeleteAction,
   246                                               actions.AddNewAction],
   252                                               actions.AddNewAction],
   247                               })
   253                               })
   248 
   254 
   250         req = self.request()
   256         req = self.request()
   251         rset = req.execute('Any X')
   257         rset = req.execute('Any X')
   252         self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
   258         self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
   253                              {'useractions': USERACTIONS,
   259                              {'useractions': USERACTIONS,
   254                               'siteactions': SITEACTIONS,
   260                               'siteactions': SITEACTIONS,
       
   261                               'footer': FOOTERACTIONS,
   255                               'moreactions': [actions.DeleteAction],
   262                               'moreactions': [actions.DeleteAction],
   256                               })
   263                               })
   257 
   264 
   258     def test_possible_actions_final_entities(self):
   265     def test_possible_actions_final_entities(self):
   259         req = self.request()
   266         req = self.request()
   260         rset = req.execute('Any N, X WHERE X in_group Y, Y name N')
   267         rset = req.execute('Any N, X WHERE X in_group Y, Y name N')
   261         self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
   268         self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
   262                              {'useractions': USERACTIONS,
   269                              {'useractions': USERACTIONS,
   263                               'siteactions': SITEACTIONS})
   270                               'siteactions': SITEACTIONS,
       
   271                               'footer': FOOTERACTIONS,
       
   272                               })
   264 
   273 
   265     def test_possible_actions_eetype_cwuser_entity(self):
   274     def test_possible_actions_eetype_cwuser_entity(self):
   266         req = self.request()
   275         req = self.request()
   267         rset = req.execute('CWEType X WHERE X name "CWUser"')
   276         rset = req.execute('CWEType X WHERE X name "CWUser"')
   268         self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
   277         self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
   269                              {'useractions': USERACTIONS,
   278                              {'useractions': USERACTIONS,
   270                               'siteactions': SITEACTIONS,
   279                               'siteactions': SITEACTIONS,
       
   280                               'footer': FOOTERACTIONS,
   271                               'mainactions': [actions.ModifyAction],
   281                               'mainactions': [actions.ModifyAction],
   272                               'moreactions': [actions.ManagePermissionsAction,
   282                               'moreactions': [actions.ManagePermissionsAction,
   273                                               actions.AddRelatedActions,
   283                                               actions.AddRelatedActions,
   274                                               actions.DeleteAction,
   284                                               actions.DeleteAction,
   275                                               actions.CopyAction,
   285                                               actions.CopyAction,
   379                               self.vreg['views'].select, 'creation', req, rset=rset)
   389                               self.vreg['views'].select, 'creation', req, rset=rset)
   380         self.assertIsInstance(self.vreg['views'].select('table', req, rset=rset),
   390         self.assertIsInstance(self.vreg['views'].select('table', req, rset=rset),
   381                               tableview.TableView)
   391                               tableview.TableView)
   382 
   392 
   383     def test_interface_selector(self):
   393     def test_interface_selector(self):
   384         image = self.add_entity('Image', name=u'bim.png', data=Binary('bim'))
   394         image = self.add_entity('Image', data_name=u'bim.png', data=Binary('bim'))
   385         # image primary view priority
   395         # image primary view priority
   386         req = self.request()
   396         req = self.request()
   387         rset = req.execute('Image X WHERE X name "bim.png"')
   397         rset = req.execute('Image X WHERE X data_name "bim.png"')
   388         self.assertIsInstance(self.vreg['views'].select('primary', req, rset=rset),
   398         self.assertIsInstance(self.vreg['views'].select('primary', req, rset=rset),
   389                               idownloadable.IDownloadablePrimaryView)
   399                               idownloadable.IDownloadablePrimaryView)
   390 
   400 
   391 
   401 
   392     def test_score_entity_selector(self):
   402     def test_score_entity_selector(self):
   393         image = self.add_entity('Image', name=u'bim.png', data=Binary('bim'))
   403         image = self.add_entity('Image', data_name=u'bim.png', data=Binary('bim'))
   394         # image primary view priority
   404         # image primary view priority
   395         req = self.request()
   405         req = self.request()
   396         rset = req.execute('Image X WHERE X name "bim.png"')
   406         rset = req.execute('Image X WHERE X data_name "bim.png"')
   397         self.assertIsInstance(self.vreg['views'].select('image', req, rset=rset),
   407         self.assertIsInstance(self.vreg['views'].select('image', req, rset=rset),
   398                               idownloadable.ImageView)
   408                               idownloadable.ImageView)
   399         fileobj = self.add_entity('File', name=u'bim.txt', data=Binary('bim'))
   409         fileobj = self.add_entity('File', data_name=u'bim.txt', data=Binary('bim'))
   400         # image primary view priority
   410         # image primary view priority
   401         req = self.request()
   411         req = self.request()
   402         rset = req.execute('File X WHERE X name "bim.txt"')
   412         rset = req.execute('File X WHERE X data_name "bim.txt"')
   403         self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'image', req, rset=rset)
   413         self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'image', req, rset=rset)
   404 
   414 
   405 
   415 
   406 
   416 
   407     def _test_view(self, vid, rql, args):
   417     def _test_view(self, vid, rql, args):
   466         req = self.request()
   476         req = self.request()
   467         rset = req.execute('CWEType X WHERE X name "CWEType"')
   477         rset = req.execute('CWEType X WHERE X name "CWEType"')
   468         self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
   478         self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
   469                              {'useractions': USERACTIONS,
   479                              {'useractions': USERACTIONS,
   470                               'siteactions': SITEACTIONS,
   480                               'siteactions': SITEACTIONS,
       
   481                               'footer': FOOTERACTIONS,
   471                               'mainactions': [actions.ModifyAction],
   482                               'mainactions': [actions.ModifyAction],
   472                               'moreactions': [actions.ManagePermissionsAction,
   483                               'moreactions': [actions.ManagePermissionsAction,
   473                                               actions.AddRelatedActions,
   484                                               actions.AddRelatedActions,
   474                                               actions.DeleteAction,
   485                                               actions.DeleteAction,
   475                                               actions.CopyAction,
   486                                               actions.CopyAction,
   479         req = self.request()
   490         req = self.request()
   480         rset = req.execute('CWEType X WHERE X name "CWRType"')
   491         rset = req.execute('CWEType X WHERE X name "CWRType"')
   481         self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
   492         self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
   482                              {'useractions': USERACTIONS,
   493                              {'useractions': USERACTIONS,
   483                               'siteactions': SITEACTIONS,
   494                               'siteactions': SITEACTIONS,
       
   495                               'footer': FOOTERACTIONS,
   484                               'mainactions': [actions.ModifyAction],
   496                               'mainactions': [actions.ModifyAction],
   485                               'moreactions': [actions.ManagePermissionsAction,
   497                               'moreactions': [actions.ManagePermissionsAction,
   486                                               actions.AddRelatedActions,
   498                                               actions.AddRelatedActions,
   487                                               actions.DeleteAction,
   499                                               actions.DeleteAction,
   488                                               actions.CopyAction,
   500                                               actions.CopyAction,
   489                                               ],
       
   490                               })
   501                               })
   491 
   502 
   492 
   503 
   493 
   504 
   494 if __name__ == '__main__':
   505 if __name__ == '__main__':