test/unittest_entity.py
branchstable
changeset 9319 a68b8f423a8b
parent 9273 f3795da61959
child 9340 b1e933b0e850
child 9432 030745ac9873
equal deleted inserted replaced
9318:5d5b3a865eb1 9319:a68b8f423a8b
     1 # -*- coding: utf-8 -*-
     1 # -*- coding: utf-8 -*-
     2 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # copyright 2003-2013 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
    24 from logilab.common.decorators import clear_cache
    24 from logilab.common.decorators import clear_cache
    25 
    25 
    26 from cubicweb import Binary, Unauthorized
    26 from cubicweb import Binary, Unauthorized
    27 from cubicweb.devtools.testlib import CubicWebTC
    27 from cubicweb.devtools.testlib import CubicWebTC
    28 from cubicweb.mttransforms import HAS_TAL
    28 from cubicweb.mttransforms import HAS_TAL
       
    29 from cubicweb.entity import can_use_rest_path
    29 from cubicweb.entities import fetch_config
    30 from cubicweb.entities import fetch_config
    30 from cubicweb.uilib import soup2xhtml
    31 from cubicweb.uilib import soup2xhtml
    31 from cubicweb.schema import RQLVocabularyConstraint, RRQLExpression
    32 from cubicweb.schema import RQLVocabularyConstraint, RRQLExpression
    32 
    33 
    33 class EntityTC(CubicWebTC):
    34 class EntityTC(CubicWebTC):
   693         self.assertEqual(person.rest_path(), unicode(person.eid))
   694         self.assertEqual(person.rest_path(), unicode(person.eid))
   694         self.assertEqual(person2.rest_path(), unicode(person2.eid))
   695         self.assertEqual(person2.rest_path(), unicode(person2.eid))
   695         # unique attr with None value (nom in this case)
   696         # unique attr with None value (nom in this case)
   696         friend = req.create_entity('Ami', prenom=u'bob')
   697         friend = req.create_entity('Ami', prenom=u'bob')
   697         self.assertEqual(friend.rest_path(), unicode(friend.eid))
   698         self.assertEqual(friend.rest_path(), unicode(friend.eid))
       
   699 
       
   700     def test_can_use_rest_path(self):
       
   701         self.assertTrue(can_use_rest_path(u'zobi'))
   698         # don't use rest if we have /, ? or & in the path (breaks mod_proxy)
   702         # don't use rest if we have /, ? or & in the path (breaks mod_proxy)
   699         person3 = req.create_entity('Personne', nom=u'zo/bi')
   703         self.assertFalse(can_use_rest_path(u'zo/bi'))
   700         self.assertEqual(person3.rest_path(), unicode(person3.eid))
   704         self.assertFalse(can_use_rest_path(u'zo&bi'))
   701         person4 = req.create_entity('Personne', nom=u'zo&bi')
   705         self.assertFalse(can_use_rest_path(u'zo?bi'))
   702         self.assertEqual(person4.rest_path(), unicode(person4.eid))
       
   703         person5 = req.create_entity('Personne', nom=u'zo?bi')
       
   704         self.assertEqual(person5.rest_path(), unicode(person5.eid))
       
   705 
       
   706 
   706 
   707     def test_cw_set_attributes(self):
   707     def test_cw_set_attributes(self):
   708         req = self.request()
   708         req = self.request()
   709         person = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien')
   709         person = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien')
   710         self.assertEqual(person.prenom, u'adrien')
   710         self.assertEqual(person.prenom, u'adrien')