test/unittest_predicates.py
brancholdstable
changeset 8858 51fdbbbd07b2
parent 8220 e4ea285510e5
child 8866 64f24ecad177
equal deleted inserted replaced
8857:5d08086c3e6d 8858:51fdbbbd07b2
     1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    25 from cubicweb.devtools.testlib import CubicWebTC
    25 from cubicweb.devtools.testlib import CubicWebTC
    26 from cubicweb.predicates import (is_instance, adaptable, match_kwargs, match_user_groups,
    26 from cubicweb.predicates import (is_instance, adaptable, match_kwargs, match_user_groups,
    27                                 multi_lines_rset, score_entity, is_in_state,
    27                                 multi_lines_rset, score_entity, is_in_state,
    28                                 rql_condition, relation_possible)
    28                                 rql_condition, relation_possible)
    29 from cubicweb.selectors import on_transition # XXX on_transition is deprecated
    29 from cubicweb.selectors import on_transition # XXX on_transition is deprecated
       
    30 from cubicweb.view import EntityAdapter
    30 from cubicweb.web import action
    31 from cubicweb.web import action
    31 
    32 
    32 
    33 
    33 
    34 
    34 class ImplementsSelectorTC(CubicWebTC):
    35 class ImplementsSelectorTC(CubicWebTC):
   335         selector = rql_condition('U login "admin"', user_condition=True)
   336         selector = rql_condition('U login "admin"', user_condition=True)
   336         self.assertEqual(selector(None, req), 1)
   337         self.assertEqual(selector(None, req), 1)
   337         selector = rql_condition('U login "toto"', user_condition=True)
   338         selector = rql_condition('U login "toto"', user_condition=True)
   338         self.assertEqual(selector(None, req), 0)
   339         self.assertEqual(selector(None, req), 0)
   339 
   340 
       
   341 
       
   342 class AdaptablePredicateTC(CubicWebTC):
       
   343 
       
   344     def test_multiple_entity_types_rset(self):
       
   345         class CWUserIWhatever(EntityAdapter):
       
   346             __regid__ = 'IWhatever'
       
   347             __select__ = is_instance('CWUser')
       
   348         class CWGroupIWhatever(EntityAdapter):
       
   349             __regid__ = 'IWhatever'
       
   350             __select__ = is_instance('CWGroup')
       
   351         with self.temporary_appobjects(CWUserIWhatever, CWGroupIWhatever):
       
   352             req = self.request()
       
   353             selector = adaptable('IWhatever')
       
   354             rset = req.execute('Any X WHERE X is IN(CWGroup, CWUser)')
       
   355             self.assertTrue(selector(None, req, rset=rset))
       
   356 
   340 if __name__ == '__main__':
   357 if __name__ == '__main__':
   341     unittest_main()
   358     unittest_main()
   342 
   359