test/unittest_selectors.py
branchstable
changeset 6869 900cb9b1b687
parent 6348 f5bd501628b0
child 6874 611aa2074a5b
equal deleted inserted replaced
6868:2d40f3c48f31 6869:900cb9b1b687
    22 
    22 
    23 from cubicweb import Binary
    23 from cubicweb import Binary
    24 from cubicweb.devtools.testlib import CubicWebTC
    24 from cubicweb.devtools.testlib import CubicWebTC
    25 from cubicweb.appobject import Selector, AndSelector, OrSelector
    25 from cubicweb.appobject import Selector, AndSelector, OrSelector
    26 from cubicweb.selectors import (is_instance, adaptable, match_user_groups,
    26 from cubicweb.selectors import (is_instance, adaptable, match_user_groups,
    27                                 multi_lines_rset)
    27                                 multi_lines_rset, score_entity)
    28 from cubicweb.interfaces import IDownloadable
    28 from cubicweb.interfaces import IDownloadable
    29 from cubicweb.web import action
    29 from cubicweb.web import action
    30 
    30 
    31 class _1_(Selector):
    31 class _1_(Selector):
    32     def __call__(self, *args, **kwargs):
    32     def __call__(self, *args, **kwargs):
   243         for (expected, operator, assertion) in testdata:
   243         for (expected, operator, assertion) in testdata:
   244             selector = multi_lines_rset(expected, operator)
   244             selector = multi_lines_rset(expected, operator)
   245             yield self.assertEqual, selector(None, self.req, self.rset), assertion
   245             yield self.assertEqual, selector(None, self.req, self.rset), assertion
   246 
   246 
   247 
   247 
       
   248 class ScoreEntitySelectorTC(CubicWebTC):
       
   249 
       
   250     def test_intscore_entity_selector(self):
       
   251         req = request()
       
   252         selector = score_entity(lambda x: None)
       
   253         rset = req.execute('Any E WHERE E eid 0')
       
   254         self.assertEqual(selector(None, req, rset), 0)
       
   255         selector = score_entity(lambda x: "something")
       
   256         self.assertEqual(selector(None, req, rset), 1)
       
   257         selector = score_entity(lambda x: object)
       
   258         self.assertEqual(selector(None, req, rset), 1)
       
   259         rset = req.execute('Any G LIMIT 2 WHERE G is CWGroup')
       
   260         selector = score_entity(lambda x: 10)
       
   261         self.assertEqual(selector(None, req, rset), 20)
       
   262         selector = score_entity(lambda x: 10, once_is_enough=True)
       
   263         self.assertEqual(selector(None, req, rset), 10)
       
   264 
       
   265 
   248 if __name__ == '__main__':
   266 if __name__ == '__main__':
   249     unittest_main()
   267     unittest_main()
   250 
   268