web/test/unittest_viewselector.py
changeset 2058 7ef12c03447c
parent 1977 606923dff11b
child 2439 77d8dd77acb3
equal deleted inserted replaced
2057:0a0cbccafcb5 2058:7ef12c03447c
   232     def test_select_creation_form(self):
   232     def test_select_creation_form(self):
   233         rset = None
   233         rset = None
   234         req = self.request()
   234         req = self.request()
   235         # creation form
   235         # creation form
   236         req.form['etype'] = 'CWGroup'
   236         req.form['etype'] = 'CWGroup'
   237         self.assertIsInstance(self.vreg.select_view('creation', req, rset),
   237         self.assertIsInstance(self.vreg.select('views', 'creation', req, rset=rset),
   238                               editforms.CreationFormView)
   238                               editforms.CreationFormView)
   239         del req.form['etype']
   239         del req.form['etype']
   240         # custom creation form
   240         # custom creation form
   241         class CWUserCreationForm(editforms.CreationFormView):
   241         class CWUserCreationForm(editforms.CreationFormView):
   242             __select__ = specified_etype_implements('CWUser')
   242             __select__ = specified_etype_implements('CWUser')
   243         self.vreg._loadedmods[__name__] = {}
   243         self.vreg._loadedmods[__name__] = {}
   244         self.vreg.register_vobject_class(CWUserCreationForm)
   244         self.vreg.register_vobject_class(CWUserCreationForm)
   245         req.form['etype'] = 'CWUser'
   245         req.form['etype'] = 'CWUser'
   246         self.assertIsInstance(self.vreg.select_view('creation', req, rset),
   246         self.assertIsInstance(self.vreg.select('views', 'creation', req, rset=rset),
   247                               CWUserCreationForm)
   247                               CWUserCreationForm)
   248 
   248 
   249     def test_select_view(self):
   249     def test_select_view(self):
   250         # no entity
   250         # no entity
   251         rset = None
   251         rset = None
   252         req = self.request()
   252         req = self.request()
   253         self.assertIsInstance(self.vreg.select_view('index', req, rset),
   253         self.assertIsInstance(self.vreg.select('views', 'index', req, rset=rset),
   254                              startup.IndexView)
   254                              startup.IndexView)
   255         self.failUnlessRaises(NoSelectableObject,
   255         self.failUnlessRaises(NoSelectableObject,
   256                              self.vreg.select_view, 'primary', req, rset)
   256                              self.vreg.select, 'views', 'primary', req, rset=rset)
   257         self.failUnlessRaises(NoSelectableObject,
   257         self.failUnlessRaises(NoSelectableObject,
   258                              self.vreg.select_view, 'table', req, rset)
   258                              self.vreg.select, 'views', 'table', req, rset=rset)
   259 
   259 
   260         # no entity
   260         # no entity
   261         rset, req = self.env.get_rset_and_req('Any X WHERE X eid 999999')
   261         rset, req = self.env.get_rset_and_req('Any X WHERE X eid 999999')
   262         self.failUnlessRaises(NoSelectableObject,
   262         self.failUnlessRaises(NoSelectableObject,
   263                               self.vreg.select_view, 'index', req, rset)
   263                               self.vreg.select, 'views', 'index', req, rset=rset)
   264         self.failUnlessRaises(NoSelectableObject,
   264         self.failUnlessRaises(NoSelectableObject,
   265                               self.vreg.select_view, 'creation', req, rset)
   265                               self.vreg.select, 'views', 'creation', req, rset=rset)
   266         self.failUnlessRaises(NoSelectableObject,
   266         self.failUnlessRaises(NoSelectableObject,
   267                               self.vreg.select_view, 'primary', req, rset)
   267                               self.vreg.select, 'views', 'primary', req, rset=rset)
   268         self.failUnlessRaises(NoSelectableObject,
   268         self.failUnlessRaises(NoSelectableObject,
   269                              self.vreg.select_view, 'table', req, rset)
   269                              self.vreg.select, 'views', 'table', req, rset=rset)
   270         # one entity
   270         # one entity
   271         rset, req = self.env.get_rset_and_req('CWGroup X WHERE X name "managers"')
   271         rset, req = self.env.get_rset_and_req('CWGroup X WHERE X name "managers"')
   272         self.assertIsInstance(self.vreg.select_view('primary', req, rset),
   272         self.assertIsInstance(self.vreg.select('views', 'primary', req, rset=rset),
   273                              primary.PrimaryView)
   273                              primary.PrimaryView)
   274         self.assertIsInstance(self.vreg.select_view('list', req, rset),
   274         self.assertIsInstance(self.vreg.select('views', 'list', req, rset=rset),
   275                              baseviews.ListView)
   275                              baseviews.ListView)
   276         self.assertIsInstance(self.vreg.select_view('edition', req, rset),
   276         self.assertIsInstance(self.vreg.select('views', 'edition', req, rset=rset),
   277                              editforms.EditionFormView)
   277                              editforms.EditionFormView)
   278         self.assertIsInstance(self.vreg.select_view('table', req, rset),
   278         self.assertIsInstance(self.vreg.select('views', 'table', req, rset=rset),
   279                              tableview.TableView)
   279                              tableview.TableView)
   280         self.failUnlessRaises(NoSelectableObject,
   280         self.failUnlessRaises(NoSelectableObject,
   281                               self.vreg.select_view, 'creation', req, rset)
   281                               self.vreg.select, 'views', 'creation', req, rset=rset)
   282         self.failUnlessRaises(NoSelectableObject,
   282         self.failUnlessRaises(NoSelectableObject,
   283                               self.vreg.select_view, 'index', req, rset)
   283                               self.vreg.select, 'views', 'index', req, rset=rset)
   284         # list of entities of the same type
   284         # list of entities of the same type
   285         rset, req = self.env.get_rset_and_req('CWGroup X')
   285         rset, req = self.env.get_rset_and_req('CWGroup X')
   286         self.assertIsInstance(self.vreg.select_view('primary', req, rset),
   286         self.assertIsInstance(self.vreg.select('views', 'primary', req, rset=rset),
   287                              primary.PrimaryView)
   287                              primary.PrimaryView)
   288         self.assertIsInstance(self.vreg.select_view('list', req, rset),
   288         self.assertIsInstance(self.vreg.select('views', 'list', req, rset=rset),
   289                              baseviews.ListView)
   289                              baseviews.ListView)
   290         self.assertIsInstance(self.vreg.select_view('table', req, rset),
   290         self.assertIsInstance(self.vreg.select('views', 'table', req, rset=rset),
   291                              tableview.TableView)
   291                              tableview.TableView)
   292         self.failUnlessRaises(NoSelectableObject,
   292         self.failUnlessRaises(NoSelectableObject,
   293                               self.vreg.select_view, 'creation', req, rset)
   293                               self.vreg.select, 'views', 'creation', req, rset=rset)
   294         # list of entities of different types
   294         # list of entities of different types
   295         rset, req = self.env.get_rset_and_req('Any X')
   295         rset, req = self.env.get_rset_and_req('Any X')
   296         self.assertIsInstance(self.vreg.select_view('primary', req, rset),
   296         self.assertIsInstance(self.vreg.select('views', 'primary', req, rset=rset),
   297                                   primary.PrimaryView)
   297                                   primary.PrimaryView)
   298         self.assertIsInstance(self.vreg.select_view('list', req, rset),
   298         self.assertIsInstance(self.vreg.select('views', 'list', req, rset=rset),
   299                                   baseviews.ListView)
   299                                   baseviews.ListView)
   300         self.assertIsInstance(self.vreg.select_view('table', req, rset),
   300         self.assertIsInstance(self.vreg.select('views', 'table', req, rset=rset),
   301                                   tableview.TableView)
   301                                   tableview.TableView)
   302         self.failUnlessRaises(NoSelectableObject,
   302         self.failUnlessRaises(NoSelectableObject,
   303                              self.vreg.select_view, 'creation', req, rset)
   303                              self.vreg.select, 'views', 'creation', req, rset=rset)
   304         self.failUnlessRaises(NoSelectableObject,
   304         self.failUnlessRaises(NoSelectableObject,
   305                               self.vreg.select_view, 'index', req, rset)
   305                               self.vreg.select, 'views', 'index', req, rset=rset)
   306         # whatever
   306         # whatever
   307         rset, req = self.env.get_rset_and_req('Any N, X WHERE X in_group Y, Y name N')
   307         rset, req = self.env.get_rset_and_req('Any N, X WHERE X in_group Y, Y name N')
   308         self.assertIsInstance(self.vreg.select_view('table', req, rset),
   308         self.assertIsInstance(self.vreg.select('views', 'table', req, rset=rset),
   309                                   tableview.TableView)
   309                                   tableview.TableView)
   310         self.failUnlessRaises(NoSelectableObject,
   310         self.failUnlessRaises(NoSelectableObject,
   311                               self.vreg.select_view, 'index', req, rset)
   311                               self.vreg.select, 'views', 'index', req, rset=rset)
   312         self.failUnlessRaises(NoSelectableObject,
   312         self.failUnlessRaises(NoSelectableObject,
   313                               self.vreg.select_view, 'creation', req, rset)
   313                               self.vreg.select, 'views', 'creation', req, rset=rset)
   314         self.failUnlessRaises(NoSelectableObject,
   314         self.failUnlessRaises(NoSelectableObject,
   315                              self.vreg.select_view, 'primary', req, rset)
   315                              self.vreg.select, 'views', 'primary', req, rset=rset)
   316         self.failUnlessRaises(NoSelectableObject,
   316         self.failUnlessRaises(NoSelectableObject,
   317                              self.vreg.select_view, 'list', req, rset)
   317                              self.vreg.select, 'views', 'list', req, rset=rset)
   318         self.failUnlessRaises(NoSelectableObject,
   318         self.failUnlessRaises(NoSelectableObject,
   319                              self.vreg.select_view, 'edition', req, rset)
   319                              self.vreg.select, 'views', 'edition', req, rset=rset)
   320         # mixed query
   320         # mixed query
   321         rset, req = self.env.get_rset_and_req('Any U,G WHERE U is CWUser, G is CWGroup')
   321         rset, req = self.env.get_rset_and_req('Any U,G WHERE U is CWUser, G is CWGroup')
   322         self.failUnlessRaises(NoSelectableObject,
   322         self.failUnlessRaises(NoSelectableObject,
   323                               self.vreg.select_view, 'edition', req, rset)
   323                               self.vreg.select, 'views', 'edition', req, rset=rset)
   324         self.failUnlessRaises(NoSelectableObject,
   324         self.failUnlessRaises(NoSelectableObject,
   325                               self.vreg.select_view, 'creation', req, rset)
   325                               self.vreg.select, 'views', 'creation', req, rset=rset)
   326         self.assertIsInstance(self.vreg.select_view('table', req, rset),
   326         self.assertIsInstance(self.vreg.select('views', 'table', req, rset=rset),
   327                               tableview.TableView)
   327                               tableview.TableView)
   328 
   328 
   329     def test_interface_selector(self):
   329     def test_interface_selector(self):
   330         image = self.add_entity('Image', name=u'bim.png', data=Binary('bim'))
   330         image = self.add_entity('Image', name=u'bim.png', data=Binary('bim'))
   331         # image primary view priority
   331         # image primary view priority
   332         rset, req = self.env.get_rset_and_req('Image X WHERE X name "bim.png"')
   332         rset, req = self.env.get_rset_and_req('Image X WHERE X name "bim.png"')
   333         self.assertIsInstance(self.vreg.select_view('primary', req, rset),
   333         self.assertIsInstance(self.vreg.select('views', 'primary', req, rset=rset),
   334                               idownloadable.IDownloadablePrimaryView)
   334                               idownloadable.IDownloadablePrimaryView)
   335 
   335 
   336 
   336 
   337     def test_score_entity_selector(self):
   337     def test_score_entity_selector(self):
   338         image = self.add_entity('Image', name=u'bim.png', data=Binary('bim'))
   338         image = self.add_entity('Image', name=u'bim.png', data=Binary('bim'))
   339         # image primary view priority
   339         # image primary view priority
   340         rset, req = self.env.get_rset_and_req('Image X WHERE X name "bim.png"')
   340         rset, req = self.env.get_rset_and_req('Image X WHERE X name "bim.png"')
   341         self.assertIsInstance(self.vreg.select_view('image', req, rset),
   341         self.assertIsInstance(self.vreg.select('views', 'image', req, rset=rset),
   342                               idownloadable.ImageView)
   342                               idownloadable.ImageView)
   343         fileobj = self.add_entity('File', name=u'bim.txt', data=Binary('bim'))
   343         fileobj = self.add_entity('File', name=u'bim.txt', data=Binary('bim'))
   344         # image primary view priority
   344         # image primary view priority
   345         rset, req = self.env.get_rset_and_req('File X WHERE X name "bim.txt"')
   345         rset, req = self.env.get_rset_and_req('File X WHERE X name "bim.txt"')
   346         self.assertRaises(NoSelectableObject, self.vreg.select_view, 'image', req, rset)
   346         self.assertRaises(NoSelectableObject, self.vreg.select, 'views', 'image', req, rset=rset)
   347 
   347 
   348 
   348 
   349 
   349 
   350     def _test_view(self, vid, rql, args):
   350     def _test_view(self, vid, rql, args):
   351         if rql is None:
   351         if rql is None:
   352             rset = None
   352             rset = None
   353             req = self.request()
   353             req = self.request()
   354         else:
   354         else:
   355             rset, req = self.env.get_rset_and_req(rql)
   355             rset, req = self.env.get_rset_and_req(rql)
   356         try:
   356         try:
   357             self.vreg.render('views', vid, req, rset=rset, **args)
   357             self.vreg.render(vid, req, rset=rset, **args)
   358         except:
   358         except:
   359             print vid, rset, args
   359             print vid, rset, args
   360             raise
   360             raise
   361 
   361 
   362     def test_form(self):
   362     def test_form(self):