test/unittest_selectors.py
changeset 5561 58b05c314443
parent 5426 0d4853a6e5ee
child 5877 0c7b7b76a84f
equal deleted inserted replaced
5559:6b183d860295 5561:58b05c314443
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    14 # details.
    14 # details.
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """unit tests for selectors mechanism
    18 """unit tests for selectors mechanism"""
    19 
       
    20 """
       
    21 
    19 
    22 from logilab.common.testlib import TestCase, unittest_main
    20 from logilab.common.testlib import TestCase, unittest_main
    23 
    21 
       
    22 from cubicweb import Binary
    24 from cubicweb.devtools.testlib import CubicWebTC
    23 from cubicweb.devtools.testlib import CubicWebTC
    25 from cubicweb.appobject import Selector, AndSelector, OrSelector
    24 from cubicweb.appobject import Selector, AndSelector, OrSelector
    26 from cubicweb.selectors import implements, match_user_groups
    25 from cubicweb.selectors import implements, adaptable, match_user_groups
    27 from cubicweb.interfaces import IDownloadable
    26 from cubicweb.interfaces import IDownloadable
    28 from cubicweb.web import action
    27 from cubicweb.web import action
    29 
    28 
    30 class _1_(Selector):
    29 class _1_(Selector):
    31     def __call__(self, *args, **kwargs):
    30     def __call__(self, *args, **kwargs):
   138 
   137 
   139 
   138 
   140 class ImplementsSelectorTC(CubicWebTC):
   139 class ImplementsSelectorTC(CubicWebTC):
   141     def test_etype_priority(self):
   140     def test_etype_priority(self):
   142         req = self.request()
   141         req = self.request()
   143         cls = self.vreg['etypes'].etype_class('File')
   142         f = req.create_entity('File', data_name=u'hop.txt', data=Binary('hop'))
   144         anyscore = implements('Any').score_class(cls, req)
   143         rset = f.as_rset()
   145         idownscore = implements(IDownloadable).score_class(cls, req)
   144         anyscore = implements('Any')(f.__class__, req, rset=rset)
       
   145         idownscore = adaptable('IDownloadable')(f.__class__, req, rset=rset)
   146         self.failUnless(idownscore > anyscore, (idownscore, anyscore))
   146         self.failUnless(idownscore > anyscore, (idownscore, anyscore))
   147         filescore = implements('File').score_class(cls, req)
   147         filescore = implements('File')(f.__class__, req, rset=rset)
   148         self.failUnless(filescore > idownscore, (filescore, idownscore))
   148         self.failUnless(filescore > idownscore, (filescore, idownscore))
   149 
   149 
   150     def test_etype_inheritance_no_yams_inheritance(self):
   150     def test_etype_inheritance_no_yams_inheritance(self):
   151         cls = self.vreg['etypes'].etype_class('Personne')
   151         cls = self.vreg['etypes'].etype_class('Personne')
   152         self.failIf(implements('Societe').score_class(cls, self.request()))
   152         self.failIf(implements('Societe').score_class(cls, self.request()))