cubicweb/test/unittest_rset.py
changeset 11870 3a84a79c4ed5
parent 11171 b81e543e623a
child 11874 ea1d92b677b5
equal deleted inserted replaced
11869:d8b66e3fd335 11870:3a84a79c4ed5
     1 # coding: utf-8
     1 # coding: utf-8
     2 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     4 #
     4 #
     5 # This file is part of CubicWeb.
     5 # This file is part of CubicWeb.
     6 #
     6 #
     7 # CubicWeb is free software: you can redistribute it and/or modify it under the
     7 # CubicWeb is free software: you can redistribute it and/or modify it under the
    42     """TestCase for cubicweb.rset.attr_desc_iterator"""
    42     """TestCase for cubicweb.rset.attr_desc_iterator"""
    43 
    43 
    44     def test_relations_description(self):
    44     def test_relations_description(self):
    45         """tests relations_description() function"""
    45         """tests relations_description() function"""
    46         queries = {
    46         queries = {
    47             'Any U,L,M where U is CWUser, U login L, U mail M' : [(1, 'login', 'subject'), (2, 'mail', 'subject')],
    47             'Any U,L,M where U is CWUser, U login L, U mail M': [(1, 'login', 'subject'), (2, 'mail', 'subject')],
    48             'Any U,L,M where U is CWUser, L is Foo, U mail M' : [(2, 'mail', 'subject')],
    48             'Any U,L,M where U is CWUser, L is Foo, U mail M': [(2, 'mail', 'subject')],
    49             'Any C,P where C is Company, C employs P' : [(1, 'employs', 'subject')],
    49             'Any C,P where C is Company, C employs P': [(1, 'employs', 'subject')],
    50             'Any C,P where C is Company, P employed_by P' : [],
    50             'Any C,P where C is Company, P employed_by P': [],
    51             'Any C where C is Company, C employs P' : [],
    51             'Any C where C is Company, C employs P': [],
    52             }
    52         }
    53         for rql, relations in queries.items():
    53         for rql, relations in queries.items():
    54             result = list(attr_desc_iterator(parse(rql).children[0], 0, 0))
    54             result = list(attr_desc_iterator(parse(rql).children[0], 0, 0))
    55             self.assertEqual((rql, result), (rql, relations))
    55             self.assertEqual((rql, result), (rql, relations))
    56 
    56 
    57     def test_relations_description_indexed(self):
    57     def test_relations_description_indexed(self):
    58         """tests relations_description() function"""
    58         """tests relations_description() function"""
    59         queries = {
    59         queries = {
    60             'Any C,U,P,L,M where C is Company, C employs P, U is CWUser, U login L, U mail M' :
    60             'Any C,U,P,L,M where C is Company, C employs P, U is CWUser, U login L, U mail M':
    61             {0: [(2,'employs', 'subject')], 1: [(3,'login', 'subject'), (4,'mail', 'subject')]},
    61             {0: [(2, 'employs', 'subject')],
    62             }
    62              1: [(3, 'login', 'subject'), (4, 'mail', 'subject')]},
       
    63         }
    63         for rql, results in queries.items():
    64         for rql, results in queries.items():
    64             for idx, relations in results.items():
    65             for idx, relations in results.items():
    65                 result = list(attr_desc_iterator(parse(rql).children[0], idx, idx))
    66                 result = list(attr_desc_iterator(parse(rql).children[0], idx, idx))
    66                 self.assertEqual(result, relations)
    67                 self.assertEqual(result, relations)
    67 
    68 
   282         self.assertIs(rqlst1, rqlst2)
   283         self.assertIs(rqlst1, rqlst2)
   283 
   284 
   284     def test_get_entity_simple(self):
   285     def test_get_entity_simple(self):
   285         with self.admin_access.web_request() as req:
   286         with self.admin_access.web_request() as req:
   286             req.create_entity('CWUser', login=u'adim', upassword='adim',
   287             req.create_entity('CWUser', login=u'adim', upassword='adim',
   287                                          surname=u'di mascio', firstname=u'adrien')
   288                               surname=u'di mascio', firstname=u'adrien')
   288             req.drop_entity_cache()
   289             req.drop_entity_cache()
   289             e = req.execute('Any X,T WHERE X login "adim", X surname T').get_entity(0, 0)
   290             e = req.execute('Any X,T WHERE X login "adim", X surname T').get_entity(0, 0)
   290             self.assertEqual(e.cw_attr_cache['surname'], 'di mascio')
   291             self.assertEqual(e.cw_attr_cache['surname'], 'di mascio')
   291             self.assertRaises(KeyError, e.cw_attr_cache.__getitem__, 'firstname')
   292             self.assertRaises(KeyError, e.cw_attr_cache.__getitem__, 'firstname')
   292             self.assertRaises(KeyError, e.cw_attr_cache.__getitem__, 'creation_date')
   293             self.assertRaises(KeyError, e.cw_attr_cache.__getitem__, 'creation_date')