cubicweb/test/unittest_entity.py
changeset 12567 26744ad37953
parent 12508 a8c1ea390400
equal deleted inserted replaced
12566:6b3523f81f42 12567:26744ad37953
    17 # You should have received a copy of the GNU Lesser General Public License along
    17 # You should have received a copy of the GNU Lesser General Public License along
    18 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    19 """unit tests for cubicweb.web.views.entities module"""
    19 """unit tests for cubicweb.web.views.entities module"""
    20 
    20 
    21 from datetime import datetime
    21 from datetime import datetime
    22 
       
    23 from six import text_type
       
    24 
    22 
    25 from logilab.common import tempattr
    23 from logilab.common import tempattr
    26 from logilab.common.decorators import clear_cache
    24 from logilab.common.decorators import clear_cache
    27 
    25 
    28 from cubicweb import Binary
    26 from cubicweb import Binary
   798             person = req.create_entity('Personne', prenom=u'john', nom=u'doe')
   796             person = req.create_entity('Personne', prenom=u'john', nom=u'doe')
   799             self.assertEqual(person.rest_path(), 'personne/doe')
   797             self.assertEqual(person.rest_path(), 'personne/doe')
   800             # ambiguity test
   798             # ambiguity test
   801             person2 = req.create_entity('Personne', prenom=u'remi', nom=u'doe')
   799             person2 = req.create_entity('Personne', prenom=u'remi', nom=u'doe')
   802             person.cw_clear_all_caches()
   800             person.cw_clear_all_caches()
   803             self.assertEqual(person.rest_path(), text_type(person.eid))
   801             self.assertEqual(person.rest_path(), str(person.eid))
   804             self.assertEqual(person2.rest_path(), text_type(person2.eid))
   802             self.assertEqual(person2.rest_path(), str(person2.eid))
   805             # unique attr with None value (nom in this case)
   803             # unique attr with None value (nom in this case)
   806             friend = req.create_entity('Ami', prenom=u'bob')
   804             friend = req.create_entity('Ami', prenom=u'bob')
   807             self.assertEqual(friend.rest_path(), text_type(friend.eid))
   805             self.assertEqual(friend.rest_path(), str(friend.eid))
   808             # 'ref' below is created without the unique but not required
   806             # 'ref' below is created without the unique but not required
   809             # attribute, make sur that the unique _and_ required 'ean' is used
   807             # attribute, make sur that the unique _and_ required 'ean' is used
   810             # as the rest attribute
   808             # as the rest attribute
   811             ref = req.create_entity('Reference', ean=u'42-1337-42')
   809             ref = req.create_entity('Reference', ean=u'42-1337-42')
   812             self.assertEqual(ref.rest_path(), 'reference/42-1337-42')
   810             self.assertEqual(ref.rest_path(), 'reference/42-1337-42')