test/unittest_predicates.py
branchstable
changeset 8866 64f24ecad177
parent 8694 d901c36bcfce
parent 8858 51fdbbbd07b2
child 9152 b0155bfd4e17
equal deleted inserted replaced
8863:98c107bd6cd0 8866:64f24ecad177
     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
    24 from cubicweb.devtools.testlib import CubicWebTC
    24 from cubicweb.devtools.testlib import CubicWebTC
    25 from cubicweb.predicates import (is_instance, adaptable, match_kwargs, match_user_groups,
    25 from cubicweb.predicates import (is_instance, adaptable, match_kwargs, match_user_groups,
    26                                 multi_lines_rset, score_entity, is_in_state,
    26                                 multi_lines_rset, score_entity, is_in_state,
    27                                 rql_condition, relation_possible)
    27                                 rql_condition, relation_possible)
    28 from cubicweb.selectors import on_transition # XXX on_transition is deprecated
    28 from cubicweb.selectors import on_transition # XXX on_transition is deprecated
       
    29 from cubicweb.view import EntityAdapter
    29 from cubicweb.web import action
    30 from cubicweb.web import action
    30 
    31 
    31 
    32 
    32 
    33 
    33 class ImplementsSelectorTC(CubicWebTC):
    34 class ImplementsSelectorTC(CubicWebTC):
   334         selector = rql_condition('U login "admin"', user_condition=True)
   335         selector = rql_condition('U login "admin"', user_condition=True)
   335         self.assertEqual(selector(None, req), 1)
   336         self.assertEqual(selector(None, req), 1)
   336         selector = rql_condition('U login "toto"', user_condition=True)
   337         selector = rql_condition('U login "toto"', user_condition=True)
   337         self.assertEqual(selector(None, req), 0)
   338         self.assertEqual(selector(None, req), 0)
   338 
   339 
       
   340 
       
   341 class AdaptablePredicateTC(CubicWebTC):
       
   342 
       
   343     def test_multiple_entity_types_rset(self):
       
   344         class CWUserIWhatever(EntityAdapter):
       
   345             __regid__ = 'IWhatever'
       
   346             __select__ = is_instance('CWUser')
       
   347         class CWGroupIWhatever(EntityAdapter):
       
   348             __regid__ = 'IWhatever'
       
   349             __select__ = is_instance('CWGroup')
       
   350         with self.temporary_appobjects(CWUserIWhatever, CWGroupIWhatever):
       
   351             req = self.request()
       
   352             selector = adaptable('IWhatever')
       
   353             rset = req.execute('Any X WHERE X is IN(CWGroup, CWUser)')
       
   354             self.assertTrue(selector(None, req, rset=rset))
       
   355 
   339 if __name__ == '__main__':
   356 if __name__ == '__main__':
   340     unittest_main()
   357     unittest_main()
   341 
   358