author | Julien Cristau <julien.cristau@logilab.fr> |
Mon, 19 Oct 2015 14:28:30 +0200 | |
changeset 10816 | d4a26e94f54a |
parent 10635 | 2b1cb1ba8df5 |
permissions | -rw-r--r-- |
9808
d121b74e043f
[webtests/views_actions] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9198
diff
changeset
|
1 |
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
18 |
|
0 | 19 |
from logilab.common.testlib import unittest_main |
20 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
21 |
from cubicweb.devtools.testlib import CubicWebTC |
9198
c32a21bf88bb
[web] consider inlined relations in has_editable_relation. Closes #3049970
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9197
diff
changeset
|
22 |
from cubicweb.web.views import actions, uicfg |
0 | 23 |
|
10635
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
24 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
25 |
class ActionsTC(CubicWebTC): |
0 | 26 |
def test_view_action(self): |
9808
d121b74e043f
[webtests/views_actions] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9198
diff
changeset
|
27 |
with self.admin_access.web_request(vid='rss', rql='CWUser X') as req: |
d121b74e043f
[webtests/views_actions] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9198
diff
changeset
|
28 |
rset = req.execute('CWUser X') |
d121b74e043f
[webtests/views_actions] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9198
diff
changeset
|
29 |
actions = self.vreg['actions'].poss_visible_objects(req, rset=rset) |
d121b74e043f
[webtests/views_actions] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9198
diff
changeset
|
30 |
vaction = [action for action in actions if action.__regid__ == 'view'][0] |
d121b74e043f
[webtests/views_actions] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9198
diff
changeset
|
31 |
self.assertEqual(vaction.url(), 'http://testing.fr/cubicweb/view?rql=CWUser%20X') |
0 | 32 |
|
9198
c32a21bf88bb
[web] consider inlined relations in has_editable_relation. Closes #3049970
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9197
diff
changeset
|
33 |
def test_has_editable_relations(self): |
c32a21bf88bb
[web] consider inlined relations in has_editable_relation. Closes #3049970
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9197
diff
changeset
|
34 |
"""ensure has_editable_relation predicate used by ModifyAction |
c32a21bf88bb
[web] consider inlined relations in has_editable_relation. Closes #3049970
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9197
diff
changeset
|
35 |
return positive score if there is only some inlined forms |
c32a21bf88bb
[web] consider inlined relations in has_editable_relation. Closes #3049970
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9197
diff
changeset
|
36 |
""" |
10635
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
37 |
# The schema only allows the anonymous user to modify his/her own |
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
38 |
# EmailAddress if it is set, not to create one. Since the 'anon' CWUser |
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
39 |
# entity is created without any associated EmailAddress entities, there |
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
40 |
# are no attributes nor relations that can be edited: the "modify" |
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
41 |
# action should not appear. |
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
42 |
with self.new_access('anon').web_request() as req: |
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
43 |
predicate = actions.has_editable_relation() |
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
44 |
self.assertEqual(predicate(None, req, rset=req.user.as_rset()), |
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
45 |
0) |
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
46 |
# being allowed to 'add' the relation is not enough |
9198
c32a21bf88bb
[web] consider inlined relations in has_editable_relation. Closes #3049970
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9197
diff
changeset
|
47 |
use_email = self.schema['use_email'].rdefs['CWUser', 'EmailAddress'] |
9808
d121b74e043f
[webtests/views_actions] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9198
diff
changeset
|
48 |
with self.temporary_permissions((use_email, {'add': ('guests',)})): |
d121b74e043f
[webtests/views_actions] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9198
diff
changeset
|
49 |
with self.new_access('anon').web_request() as req: |
9198
c32a21bf88bb
[web] consider inlined relations in has_editable_relation. Closes #3049970
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9197
diff
changeset
|
50 |
predicate = actions.has_editable_relation() |
c32a21bf88bb
[web] consider inlined relations in has_editable_relation. Closes #3049970
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9197
diff
changeset
|
51 |
self.assertEqual(predicate(None, req, rset=req.user.as_rset()), |
10635
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
52 |
0) |
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
53 |
# if we also allow creating the target etype, then the "modify" action |
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
54 |
# should appear |
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
55 |
with self.temporary_permissions((use_email, {'add': ('guests',)}), |
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
56 |
EmailAddress={'add': ('guests',)}): |
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
57 |
with self.new_access('anon').web_request() as req: |
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
58 |
predicate = actions.has_editable_relation() |
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
59 |
self.assertEqual(predicate(None, req, rset=req.user.as_rset()), |
9198
c32a21bf88bb
[web] consider inlined relations in has_editable_relation. Closes #3049970
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9197
diff
changeset
|
60 |
1) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
61 |
|
10635
2b1cb1ba8df5
[web/views] Fix `has_editable_relation` predicate wrt inlined relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9808
diff
changeset
|
62 |
|
0 | 63 |
if __name__ == '__main__': |
64 |
unittest_main() |