16 # |
16 # |
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 __future__ import with_statement |
|
22 |
21 from datetime import datetime |
23 from datetime import datetime |
22 |
24 |
23 from logilab.common import tempattr |
25 from logilab.common import tempattr |
24 from logilab.common.decorators import clear_cache |
26 from logilab.common.decorators import clear_cache |
25 |
27 |
26 from cubicweb import Binary, Unauthorized |
28 from cubicweb import Binary, Unauthorized |
27 from cubicweb.devtools.testlib import CubicWebTC |
29 from cubicweb.devtools.testlib import CubicWebTC |
28 from cubicweb.mttransforms import HAS_TAL |
30 from cubicweb.mttransforms import HAS_TAL |
29 from cubicweb.entities import fetch_config |
31 from cubicweb.entities import fetch_config |
30 from cubicweb.uilib import soup2xhtml |
32 from cubicweb.uilib import soup2xhtml |
31 from cubicweb.schema import RQLVocabularyConstraint |
33 from cubicweb.schema import RQLVocabularyConstraint, RRQLExpression |
32 |
34 |
33 class EntityTC(CubicWebTC): |
35 class EntityTC(CubicWebTC): |
34 |
36 |
35 def setUp(self): |
37 def setUp(self): |
36 super(EntityTC, self).setUp() |
38 super(EntityTC, self).setUp() |
359 rql, 'Any S,AA,AB,AC ORDERBY AC DESC WHERE ' |
361 rql, 'Any S,AA,AB,AC ORDERBY AC DESC WHERE ' |
360 'S is Personne, S nom AA, S prenom AB, S modification_date AC, ' |
362 'S is Personne, S nom AA, S prenom AB, S modification_date AC, ' |
361 'NOT (S connait AD, AD nom "toto"), AD is Personne, ' |
363 'NOT (S connait AD, AD nom "toto"), AD is Personne, ' |
362 'EXISTS(S travaille AE, AE nom "tutu")') |
364 'EXISTS(S travaille AE, AE nom "tutu")') |
363 |
365 |
|
366 def test_unrelated_rql_security_rel_perms(self): |
|
367 '''check `connait` add permission has no effect for a new entity on the |
|
368 unrelated rql''' |
|
369 rdef = self.schema['Personne'].rdef('connait') |
|
370 perm_rrqle = RRQLExpression('U has_update_permission S') |
|
371 with self.temporary_permissions((rdef, {'add': (perm_rrqle,)})): |
|
372 person = self.vreg['etypes'].etype_class('Personne')(self.request()) |
|
373 rql = person.cw_unrelated_rql('connait', 'Personne', 'subject')[0] |
|
374 self.assertEqual(rql, 'Any O,AA,AB,AC ORDERBY AC DESC WHERE ' |
|
375 'O is Personne, O nom AA, O prenom AB, ' |
|
376 'O modification_date AC') |
|
377 |
364 def test_unrelated_rql_constraints_edition_subject(self): |
378 def test_unrelated_rql_constraints_edition_subject(self): |
365 person = self.request().create_entity('Personne', nom=u'sylvain') |
379 person = self.request().create_entity('Personne', nom=u'sylvain') |
366 rql = person.cw_unrelated_rql('connait', 'Personne', 'subject')[0] |
380 rql = person.cw_unrelated_rql('connait', 'Personne', 'subject')[0] |
367 self.assertEqual( |
381 self.assertEqual( |
368 rql, 'Any O,AA,AB,AC ORDERBY AC DESC WHERE ' |
382 rql, 'Any O,AA,AB,AC ORDERBY AC DESC WHERE ' |