author | Rabah Meradi <rabah.meradi@logilab.fr> |
Wed, 25 Nov 2015 18:31:48 +0100 | |
changeset 10932 | cb217b2b3463 |
parent 10751 | 9ffdfa1d28f5 |
child 10968 | 9c6c3e68422e |
permissions | -rw-r--r-- |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
18 |
"""cubicweb.web.views.basecontrollers unit tests""" |
0 | 19 |
|
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
20 |
from six import text_type |
10603
65ad6980976e
[py3k] import URL mangling functions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10587
diff
changeset
|
21 |
from six.moves.urllib.parse import urlsplit, urlunsplit, urljoin, parse_qs |
10016
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
22 |
|
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
23 |
import lxml |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
24 |
|
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
25 |
from logilab.common.testlib import unittest_main |
10016
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
26 |
|
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
27 |
from logilab.common.decorators import monkeypatch |
0 | 28 |
|
2559
46859078c866
[R xhtml] remove xhtml_wrap* function, use instead a single req.document_surrounding_div method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
29 |
from cubicweb import Binary, NoSelectableObject, ValidationError |
10075
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10016
diff
changeset
|
30 |
from cubicweb.schema import RRQLExpression |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
31 |
from cubicweb.devtools.testlib import CubicWebTC |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
32 |
from cubicweb.utils import json_dumps |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
33 |
from cubicweb.uilib import rql_for_eid |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
34 |
from cubicweb.web import Redirect, RemoteCallFailed |
8812
52af67a2f0a5
[session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8803
diff
changeset
|
35 |
import cubicweb.server.session |
9020
cb87e831c183
rename server.session.transaction into server.session.connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
36 |
from cubicweb.server.session import Connection as OldConnection |
4390 | 37 |
from cubicweb.web.views.autoform import get_pending_inserts, get_pending_deletes |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
38 |
from cubicweb.web.views.basecontrollers import JSonController, xhtmlize, jsonize |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
39 |
from cubicweb.web.views.ajaxcontroller import ajaxfunc, AjaxFunction |
8267
486386d9f836
[web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8128
diff
changeset
|
40 |
import cubicweb.transaction as tx |
9184
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
41 |
from cubicweb.server.hook import Hook, Operation |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
42 |
from cubicweb.predicates import is_instance |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
43 |
|
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
44 |
def req_form(user): |
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
45 |
return {'eid': [str(user.eid)], |
7584
e1881933f366
[form, controller] closes #1787233: form should provide a method to process posted content
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7442
diff
changeset
|
46 |
'_cw_entity_fields:%s' % user.eid: '_cw_generic_field', |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
47 |
'__type:%s' % user.eid: user.__regid__ |
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
48 |
} |
0 | 49 |
|
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
50 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
51 |
class EditControllerTC(CubicWebTC): |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
52 |
|
0 | 53 |
def setUp(self): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
54 |
CubicWebTC.setUp(self) |
9674
96549de9dd70
[test] use assertIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
55 |
self.assertIn('users', self.schema.eschema('CWGroup').get_groups('read')) |
1426 | 56 |
|
0 | 57 |
def tearDown(self): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
58 |
CubicWebTC.tearDown(self) |
9674
96549de9dd70
[test] use assertIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
59 |
self.assertIn('users', self.schema.eschema('CWGroup').get_groups('read')) |
1426 | 60 |
|
0 | 61 |
def test_noparam_edit(self): |
62 |
"""check behaviour of this controller without any form parameter |
|
63 |
""" |
|
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
64 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
65 |
with self.assertRaises(ValidationError) as cm: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
66 |
self.ctrl_publish(req) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
67 |
self.assertEqual(cm.exception.errors, {None: u'no selected entities'}) |
1426 | 68 |
|
0 | 69 |
def test_validation_unique(self): |
70 |
"""test creation of two linked entities |
|
1426 | 71 |
""" |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
72 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
73 |
req.form = {'eid': 'X', '__type:X': 'CWUser', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
74 |
'_cw_entity_fields:X': 'login-subject,upassword-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
75 |
'login-subject:X': u'admin', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
76 |
'upassword-subject:X': u'toto', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
77 |
'upassword-subject-confirm:X': u'toto', |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
78 |
} |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
79 |
with self.assertRaises(ValidationError) as cm: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
80 |
self.ctrl_publish(req) |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
81 |
cm.exception.translate(text_type) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
82 |
self.assertEqual({'login-subject': 'the value "admin" is already used, use another one'}, |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
83 |
cm.exception.errors) |
0 | 84 |
|
10016
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
85 |
def test_simultaneous_edition_only_one_commit(self): |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
86 |
""" Allow two simultaneous edit view of the same entity as long as only one commits |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
87 |
""" |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
88 |
with self.admin_access.web_request() as req: |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
89 |
e = req.create_entity('BlogEntry', title=u'cubicweb.org', content=u"hop") |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
90 |
expected_path = e.rest_path() |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
91 |
req.cnx.commit() |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
92 |
form = self.vreg['views'].select('edition', req, rset=e.as_rset(), row=0) |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
93 |
html_form = lxml.html.fromstring(form.render(w=None, action='edit')).forms[0] |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
94 |
|
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
95 |
with self.admin_access.web_request() as req2: |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
96 |
form2 = self.vreg['views'].select('edition', req, rset=e.as_rset(), row=0) |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
97 |
|
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
98 |
with self.admin_access.web_request(**dict(html_form.form_values())) as req: |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
99 |
path, args = self.expect_redirect_handle_request(req, path='edit') |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
100 |
self.assertEqual(path, expected_path) |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
101 |
|
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
102 |
def test_simultaneous_edition_refuse_second_commit(self): |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
103 |
""" Disallow committing changes to an entity edited in between """ |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
104 |
with self.admin_access.web_request() as req: |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
105 |
e = req.create_entity('BlogEntry', title=u'cubicweb.org', content=u"hop") |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
106 |
eid = e.eid |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
107 |
req.cnx.commit() |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
108 |
form = self.vreg['views'].select('edition', req, rset=e.as_rset(), row=0) |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
109 |
html_form = lxml.html.fromstring(form.render(w=None, action='edit')).forms[0] |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
110 |
|
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
111 |
with self.admin_access.web_request() as req2: |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
112 |
e = req2.entity_from_eid(eid) |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
113 |
e.cw_set(content = u"hip") |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
114 |
req2.cnx.commit() |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
115 |
|
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
116 |
form_field_name = "content-subject:%d" % eid |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
117 |
form_values = dict(html_form.form_values()) |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
118 |
assert form_field_name in form_values |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
119 |
form_values[form_field_name] = u'yep' |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
120 |
with self.admin_access.web_request(**form_values) as req: |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
121 |
with self.assertRaises(ValidationError) as cm: |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
122 |
self.ctrl_publish(req) |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
123 |
reported_eid, dict_info = cm.exception.args |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
124 |
self.assertEqual(reported_eid, eid) |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
125 |
self.assertIn(None, dict_info) |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
126 |
self.assertIn("has changed since you started to edit it.", dict_info[None]) |
984505da8b89
[forms] closes #2437859 - Detect and prevent concurrent edition of the same entity.
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9846
diff
changeset
|
127 |
|
0 | 128 |
def test_user_editing_itself(self): |
129 |
"""checking that a manager user can edit itself |
|
130 |
""" |
|
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
131 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
132 |
user = req.user |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
133 |
groupeids = [eid for eid, in req.execute('CWGroup G WHERE G name ' |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
134 |
'in ("managers", "users")')] |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
135 |
groups = [text_type(eid) for eid in groupeids] |
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
136 |
eid = text_type(user.eid) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
137 |
req.form = { |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
138 |
'eid': eid, '__type:'+eid: 'CWUser', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
139 |
'_cw_entity_fields:'+eid: 'login-subject,firstname-subject,surname-subject,in_group-subject', |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
140 |
'login-subject:'+eid: text_type(user.login), |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
141 |
'surname-subject:'+eid: u'Th\xe9nault', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
142 |
'firstname-subject:'+eid: u'Sylvain', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
143 |
'in_group-subject:'+eid: groups, |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
144 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
145 |
self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
146 |
e = req.execute('Any X WHERE X eid %(x)s', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
147 |
{'x': user.eid}).get_entity(0, 0) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
148 |
self.assertEqual(e.firstname, u'Sylvain') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
149 |
self.assertEqual(e.surname, u'Th\xe9nault') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
150 |
self.assertEqual(e.login, user.login) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
151 |
self.assertEqual([g.eid for g in e.in_group], groupeids) |
0 | 152 |
|
153 |
def test_user_can_change_its_password(self): |
|
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
154 |
with self.admin_access.repo_cnx() as cnx: |
10253
8eb9a3e9531c
[web/test] use unicode instead of str for user logins
Julien Cristau <julien.cristau@logilab.fr>
parents:
10083
diff
changeset
|
155 |
self.create_user(cnx, u'user') |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
156 |
cnx.commit() |
10253
8eb9a3e9531c
[web/test] use unicode instead of str for user logins
Julien Cristau <julien.cristau@logilab.fr>
parents:
10083
diff
changeset
|
157 |
with self.new_access(u'user').web_request() as req: |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
158 |
eid = text_type(req.user.eid) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
159 |
req.form = { |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
160 |
'eid': eid, '__maineid' : eid, |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
161 |
'__type:'+eid: 'CWUser', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
162 |
'_cw_entity_fields:'+eid: 'upassword-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
163 |
'upassword-subject:'+eid: 'tournicoton', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
164 |
'upassword-subject-confirm:'+eid: 'tournicoton', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
165 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
166 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
167 |
req.cnx.commit() # commit to check we don't get late validation error for instance |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
168 |
self.assertEqual(path, 'cwuser/user') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
169 |
self.assertNotIn('vid', params) |
0 | 170 |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
171 |
def test_user_editing_itself_no_relation(self): |
0 | 172 |
"""checking we can edit an entity without specifying some required |
173 |
relations (meaning no changes) |
|
174 |
""" |
|
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
175 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
176 |
user = req.user |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
177 |
groupeids = [g.eid for g in user.in_group] |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
178 |
eid = text_type(user.eid) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
179 |
req.form = { |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
180 |
'eid': eid, |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
181 |
'__type:'+eid: 'CWUser', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
182 |
'_cw_entity_fields:'+eid: 'login-subject,firstname-subject,surname-subject', |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
183 |
'login-subject:'+eid: text_type(user.login), |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
184 |
'firstname-subject:'+eid: u'Th\xe9nault', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
185 |
'surname-subject:'+eid: u'Sylvain', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
186 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
187 |
self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
188 |
e = req.execute('Any X WHERE X eid %(x)s', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
189 |
{'x': user.eid}).get_entity(0, 0) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
190 |
self.assertEqual(e.login, user.login) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
191 |
self.assertEqual(e.firstname, u'Th\xe9nault') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
192 |
self.assertEqual(e.surname, u'Sylvain') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
193 |
self.assertEqual([g.eid for g in e.in_group], groupeids) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
194 |
self.assertEqual(e.cw_adapt_to('IWorkflowable').state, 'activated') |
1426 | 195 |
|
196 |
||
0 | 197 |
def test_create_multiple_linked(self): |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
198 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
199 |
gueid = req.execute('CWGroup G WHERE G name "users"')[0][0] |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
200 |
req.form = {'eid': ['X', 'Y'], '__maineid' : 'X', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
201 |
'__type:X': 'CWUser', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
202 |
'_cw_entity_fields:X': 'login-subject,upassword-subject,surname-subject,in_group-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
203 |
'login-subject:X': u'adim', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
204 |
'upassword-subject:X': u'toto', 'upassword-subject-confirm:X': u'toto', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
205 |
'surname-subject:X': u'Di Mascio', |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
206 |
'in_group-subject:X': text_type(gueid), |
1426 | 207 |
|
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
208 |
'__type:Y': 'EmailAddress', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
209 |
'_cw_entity_fields:Y': 'address-subject,use_email-object', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
210 |
'address-subject:Y': u'dima@logilab.fr', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
211 |
'use_email-object:Y': 'X', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
212 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
213 |
path, _params = self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
214 |
# should be redirected on the created person |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
215 |
self.assertEqual(path, 'cwuser/adim') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
216 |
e = req.execute('Any P WHERE P surname "Di Mascio"').get_entity(0, 0) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
217 |
self.assertEqual(e.surname, 'Di Mascio') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
218 |
email = e.use_email[0] |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
219 |
self.assertEqual(email.address, 'dima@logilab.fr') |
1426 | 220 |
|
9179
570208f74a84
[editcontrollers] Ensure entities are created in an order satisfying schema constraints. Closes #3031719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8941
diff
changeset
|
221 |
def test_create_mandatory_inlined(self): |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
222 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
223 |
req.form = {'eid': ['X', 'Y'], '__maineid' : 'X', |
9179
570208f74a84
[editcontrollers] Ensure entities are created in an order satisfying schema constraints. Closes #3031719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8941
diff
changeset
|
224 |
|
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
225 |
'__type:X': 'Salesterm', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
226 |
'_cw_entity_fields:X': '', |
9179
570208f74a84
[editcontrollers] Ensure entities are created in an order satisfying schema constraints. Closes #3031719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8941
diff
changeset
|
227 |
|
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
228 |
'__type:Y': 'File', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
229 |
'_cw_entity_fields:Y': 'data-subject,described_by_test-object', |
10704
73367a56ee41
[py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10603
diff
changeset
|
230 |
'data-subject:Y': (u'coucou.txt', Binary(b'coucou')), |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
231 |
'described_by_test-object:Y': 'X', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
232 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
233 |
path, _params = self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
234 |
self.assertTrue(path.startswith('salesterm/'), path) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
235 |
eid = path.split('/')[1] |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
236 |
salesterm = req.entity_from_eid(eid) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
237 |
# The NOT NULL constraint of mandatory relation implies that the File |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
238 |
# must be created before the Salesterm, otherwise Salesterm insertion |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
239 |
# will fail. |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
240 |
# NOTE: sqlite does have NOT NULL constraint, unlike Postgres so the |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
241 |
# insertion does not fail and we have to check dumbly that File is |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
242 |
# created before. |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
243 |
self.assertGreater(salesterm.eid, salesterm.described_by_test[0].eid) |
9179
570208f74a84
[editcontrollers] Ensure entities are created in an order satisfying schema constraints. Closes #3031719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8941
diff
changeset
|
244 |
|
9196
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
245 |
def test_create_mandatory_inlined2(self): |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
246 |
with self.admin_access.web_request() as req: |
9213
312062f53981
[inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9196
diff
changeset
|
247 |
req.form = {'eid': ['X', 'Y'], '__maineid' : 'X', |
312062f53981
[inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9196
diff
changeset
|
248 |
|
312062f53981
[inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9196
diff
changeset
|
249 |
'__type:X': 'Salesterm', |
312062f53981
[inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9196
diff
changeset
|
250 |
'_cw_entity_fields:X': 'described_by_test-subject', |
312062f53981
[inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9196
diff
changeset
|
251 |
'described_by_test-subject:X': 'Y', |
312062f53981
[inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9196
diff
changeset
|
252 |
|
312062f53981
[inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9196
diff
changeset
|
253 |
'__type:Y': 'File', |
312062f53981
[inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9196
diff
changeset
|
254 |
'_cw_entity_fields:Y': 'data-subject', |
10704
73367a56ee41
[py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10603
diff
changeset
|
255 |
'data-subject:Y': (u'coucou.txt', Binary(b'coucou')), |
9213
312062f53981
[inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9196
diff
changeset
|
256 |
} |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
257 |
path, _params = self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
258 |
self.assertTrue(path.startswith('salesterm/'), path) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
259 |
eid = path.split('/')[1] |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
260 |
salesterm = req.entity_from_eid(eid) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
261 |
# The NOT NULL constraint of mandatory relation implies that the File |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
262 |
# must be created before the Salesterm, otherwise Salesterm insertion |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
263 |
# will fail. |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
264 |
# NOTE: sqlite does have NOT NULL constraint, unlike Postgres so the |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
265 |
# insertion does not fail and we have to check dumbly that File is |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
266 |
# created before. |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
267 |
self.assertGreater(salesterm.eid, salesterm.described_by_test[0].eid) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
268 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
269 |
def test_edit_mandatory_inlined3_object(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
270 |
# non regression test for #3120495. Without the fix, leads to |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
271 |
# "unhashable type: 'list'" error |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
272 |
with self.admin_access.web_request() as req: |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
273 |
cwrelation = text_type(req.execute('CWEType X WHERE X name "CWSource"')[0][0]) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
274 |
req.form = {'eid': [cwrelation], '__maineid' : cwrelation, |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
275 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
276 |
'__type:'+cwrelation: 'CWEType', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
277 |
'_cw_entity_fields:'+cwrelation: 'to_entity-object', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
278 |
'to_entity-object:'+cwrelation: [9999, 9998], |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
279 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
280 |
with req.cnx.deny_all_hooks_but(): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
281 |
path, _params = self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
282 |
self.assertTrue(path.startswith('cwetype/CWSource'), path) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
283 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
284 |
def test_edit_multiple_linked(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
285 |
with self.admin_access.web_request() as req: |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
286 |
peid = text_type(self.create_user(req, u'adim').eid) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
287 |
req.form = {'eid': [peid, 'Y'], '__maineid': peid, |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
288 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
289 |
'__type:'+peid: u'CWUser', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
290 |
'_cw_entity_fields:'+peid: u'surname-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
291 |
'surname-subject:'+peid: u'Di Masci', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
292 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
293 |
'__type:Y': u'EmailAddress', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
294 |
'_cw_entity_fields:Y': u'address-subject,use_email-object', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
295 |
'address-subject:Y': u'dima@logilab.fr', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
296 |
'use_email-object:Y': peid, |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
297 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
298 |
path, _params = self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
299 |
# should be redirected on the created person |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
300 |
self.assertEqual(path, 'cwuser/adim') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
301 |
e = req.execute('Any P WHERE P surname "Di Masci"').get_entity(0, 0) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
302 |
email = e.use_email[0] |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
303 |
self.assertEqual(email.address, 'dima@logilab.fr') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
304 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
305 |
# with self.admin_access.web_request() as req: |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
306 |
emaileid = text_type(email.eid) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
307 |
req.form = {'eid': [peid, emaileid], |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
308 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
309 |
'__type:'+peid: u'CWUser', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
310 |
'_cw_entity_fields:'+peid: u'surname-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
311 |
'surname-subject:'+peid: u'Di Masci', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
312 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
313 |
'__type:'+emaileid: u'EmailAddress', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
314 |
'_cw_entity_fields:'+emaileid: u'address-subject,use_email-object', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
315 |
'address-subject:'+emaileid: u'adim@logilab.fr', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
316 |
'use_email-object:'+emaileid: peid, |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
317 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
318 |
self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
319 |
email.cw_clear_all_caches() |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
320 |
self.assertEqual(email.address, 'adim@logilab.fr') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
321 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
322 |
def test_password_confirm(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
323 |
"""test creation of two linked entities |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
324 |
""" |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
325 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
326 |
user = req.user |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
327 |
req.form = {'eid': 'X', |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
328 |
'__cloned_eid:X': text_type(user.eid), '__type:X': 'CWUser', |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
329 |
'_cw_entity_fields:X': 'login-subject,upassword-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
330 |
'login-subject:X': u'toto', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
331 |
'upassword-subject:X': u'toto', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
332 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
333 |
with self.assertRaises(ValidationError) as cm: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
334 |
self.ctrl_publish(req) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
335 |
self.assertEqual({'upassword-subject': u'password and confirmation don\'t match'}, |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
336 |
cm.exception.errors) |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
337 |
req.form = {'__cloned_eid:X': text_type(user.eid), |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
338 |
'eid': 'X', '__type:X': 'CWUser', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
339 |
'_cw_entity_fields:X': 'login-subject,upassword-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
340 |
'login-subject:X': u'toto', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
341 |
'upassword-subject:X': u'toto', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
342 |
'upassword-subject-confirm:X': u'tutu', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
343 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
344 |
with self.assertRaises(ValidationError) as cm: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
345 |
self.ctrl_publish(req) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
346 |
self.assertEqual({'upassword-subject': u'password and confirmation don\'t match'}, |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
347 |
cm.exception.errors) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
348 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
349 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
350 |
def test_interval_bound_constraint_success(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
351 |
with self.admin_access.repo_cnx() as cnx: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
352 |
feid = cnx.execute('INSERT File X: X data_name "toto.txt", X data %(data)s', |
10704
73367a56ee41
[py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10603
diff
changeset
|
353 |
{'data': Binary(b'yo')})[0][0] |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
354 |
cnx.commit() |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
355 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
356 |
with self.admin_access.web_request(rollbackfirst=True) as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
357 |
req.form = {'eid': ['X'], |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
358 |
'__type:X': 'Salesterm', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
359 |
'_cw_entity_fields:X': 'amount-subject,described_by_test-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
360 |
'amount-subject:X': u'-10', |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
361 |
'described_by_test-subject:X': text_type(feid), |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
362 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
363 |
with self.assertRaises(ValidationError) as cm: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
364 |
self.ctrl_publish(req) |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
365 |
cm.exception.translate(text_type) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
366 |
self.assertEqual({'amount-subject': 'value -10 must be >= 0'}, |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
367 |
cm.exception.errors) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
368 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
369 |
with self.admin_access.web_request(rollbackfirst=True) as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
370 |
req.form = {'eid': ['X'], |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
371 |
'__type:X': 'Salesterm', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
372 |
'_cw_entity_fields:X': 'amount-subject,described_by_test-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
373 |
'amount-subject:X': u'110', |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
374 |
'described_by_test-subject:X': text_type(feid), |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
375 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
376 |
with self.assertRaises(ValidationError) as cm: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
377 |
self.ctrl_publish(req) |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
378 |
cm.exception.translate(text_type) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
379 |
self.assertEqual(cm.exception.errors, {'amount-subject': 'value 110 must be <= 100'}) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
380 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
381 |
with self.admin_access.web_request(rollbackfirst=True) as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
382 |
req.form = {'eid': ['X'], |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
383 |
'__type:X': 'Salesterm', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
384 |
'_cw_entity_fields:X': 'amount-subject,described_by_test-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
385 |
'amount-subject:X': u'10', |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
386 |
'described_by_test-subject:X': text_type(feid), |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
387 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
388 |
self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
389 |
# should be redirected on the created |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
390 |
#eid = params['rql'].split()[-1] |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
391 |
e = req.execute('Salesterm X').get_entity(0, 0) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
392 |
self.assertEqual(e.amount, 10) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
393 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
394 |
def test_interval_bound_constraint_validateform(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
395 |
"""Test the FormValidatorController controller on entity with |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
396 |
constrained attributes""" |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
397 |
with self.admin_access.repo_cnx() as cnx: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
398 |
feid = cnx.execute('INSERT File X: X data_name "toto.txt", X data %(data)s', |
10704
73367a56ee41
[py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10603
diff
changeset
|
399 |
{'data': Binary(b'yo')})[0][0] |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
400 |
seid = cnx.create_entity('Salesterm', amount=0, described_by_test=feid).eid |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
401 |
cnx.commit() |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
402 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
403 |
# ensure a value that violate a constraint is properly detected |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
404 |
with self.admin_access.web_request(rollbackfirst=True) as req: |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
405 |
req.form = {'eid': [text_type(seid)], |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
406 |
'__type:%s'%seid: 'Salesterm', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
407 |
'_cw_entity_fields:%s'%seid: 'amount-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
408 |
'amount-subject:%s'%seid: u'-10', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
409 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
410 |
self.assertMultiLineEqual('''<script type="text/javascript"> |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
411 |
window.parent.handleFormValidationResponse('entityForm', null, null, [false, [%s, {"amount-subject": "value -10 must be >= 0"}], null], null); |
10751
9ffdfa1d28f5
[web/test] str vs bytes
Julien Cristau <julien.cristau@logilab.fr>
parents:
10749
diff
changeset
|
412 |
</script>'''%seid, self.ctrl_publish(req, 'validateform').decode('ascii')) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
413 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
414 |
# ensure a value that comply a constraint is properly processed |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
415 |
with self.admin_access.web_request(rollbackfirst=True) as req: |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
416 |
req.form = {'eid': [text_type(seid)], |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
417 |
'__type:%s'%seid: 'Salesterm', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
418 |
'_cw_entity_fields:%s'%seid: 'amount-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
419 |
'amount-subject:%s'%seid: u'20', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
420 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
421 |
self.assertMultiLineEqual('''<script type="text/javascript"> |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
422 |
window.parent.handleFormValidationResponse('entityForm', null, null, [true, "http://testing.fr/cubicweb/view", null], null); |
10751
9ffdfa1d28f5
[web/test] str vs bytes
Julien Cristau <julien.cristau@logilab.fr>
parents:
10749
diff
changeset
|
423 |
</script>''', self.ctrl_publish(req, 'validateform').decode('ascii')) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
424 |
self.assertEqual(20, req.execute('Any V WHERE X amount V, X eid %(eid)s', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
425 |
{'eid': seid})[0][0]) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
426 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
427 |
with self.admin_access.web_request(rollbackfirst=True) as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
428 |
req.form = {'eid': ['X'], |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
429 |
'__type:X': 'Salesterm', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
430 |
'_cw_entity_fields:X': 'amount-subject,described_by_test-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
431 |
'amount-subject:X': u'0', |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
432 |
'described_by_test-subject:X': text_type(feid), |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
433 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
434 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
435 |
# ensure a value that is modified in an operation on a modify |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
436 |
# hook works as it should (see |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
437 |
# https://www.cubicweb.org/ticket/2509729 ) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
438 |
class MyOperation(Operation): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
439 |
def precommit_event(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
440 |
self.entity.cw_set(amount=-10) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
441 |
class ValidationErrorInOpAfterHook(Hook): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
442 |
__regid__ = 'valerror-op-after-hook' |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
443 |
__select__ = Hook.__select__ & is_instance('Salesterm') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
444 |
events = ('after_add_entity',) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
445 |
def __call__(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
446 |
MyOperation(self._cw, entity=self.entity) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
447 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
448 |
with self.temporary_appobjects(ValidationErrorInOpAfterHook): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
449 |
self.assertMultiLineEqual('''<script type="text/javascript"> |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
450 |
window.parent.handleFormValidationResponse('entityForm', null, null, [false, ["X", {"amount-subject": "value -10 must be >= 0"}], null], null); |
10751
9ffdfa1d28f5
[web/test] str vs bytes
Julien Cristau <julien.cristau@logilab.fr>
parents:
10749
diff
changeset
|
451 |
</script>''', self.ctrl_publish(req, 'validateform').decode('ascii')) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
452 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
453 |
self.assertMultiLineEqual('''<script type="text/javascript"> |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
454 |
window.parent.handleFormValidationResponse('entityForm', null, null, [true, "http://testing.fr/cubicweb/view", null], null); |
10751
9ffdfa1d28f5
[web/test] str vs bytes
Julien Cristau <julien.cristau@logilab.fr>
parents:
10749
diff
changeset
|
455 |
</script>''', self.ctrl_publish(req, 'validateform').decode('ascii')) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
456 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
457 |
def test_req_pending_insert(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
458 |
"""make sure req's pending insertions are taken into account""" |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
459 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
460 |
tmpgroup = req.create_entity('CWGroup', name=u"test") |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
461 |
user = req.user |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
462 |
req.cnx.commit() |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
463 |
with self.admin_access.web_request(**req_form(user)) as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
464 |
req.session.data['pending_insert'] = set([(user.eid, 'in_group', tmpgroup.eid)]) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
465 |
self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
466 |
usergroups = [gname for gname, in |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
467 |
req.execute('Any N WHERE G name N, U in_group G, U eid %(u)s', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
468 |
{'u': user.eid})] |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
469 |
self.assertCountEqual(usergroups, ['managers', 'test']) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
470 |
self.assertEqual(get_pending_inserts(req), []) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
471 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
472 |
def test_req_pending_delete(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
473 |
"""make sure req's pending deletions are taken into account""" |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
474 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
475 |
user = req.user |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
476 |
groupeid = req.execute('INSERT CWGroup G: G name "test", U in_group G WHERE U eid %(x)s', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
477 |
{'x': user.eid})[0][0] |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
478 |
usergroups = [gname for gname, in |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
479 |
req.execute('Any N WHERE G name N, U in_group G, U eid %(u)s', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
480 |
{'u': user.eid})] |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
481 |
# just make sure everything was set correctly |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
482 |
self.assertCountEqual(usergroups, ['managers', 'test']) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
483 |
req.cnx.commit() |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
484 |
# now try to delete the relation |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
485 |
with self.admin_access.web_request(**req_form(user)) as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
486 |
req.session.data['pending_delete'] = set([(user.eid, 'in_group', groupeid)]) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
487 |
self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
488 |
usergroups = [gname for gname, in |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
489 |
req.execute('Any N WHERE G name N, U in_group G, U eid %(u)s', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
490 |
{'u': user.eid})] |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
491 |
self.assertCountEqual(usergroups, ['managers']) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
492 |
self.assertEqual(get_pending_deletes(req), []) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
493 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
494 |
def test_redirect_apply_button(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
495 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
496 |
redirectrql = rql_for_eid(4012) # whatever |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
497 |
req.form = { |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
498 |
'eid': 'A', '__maineid' : 'A', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
499 |
'__type:A': 'BlogEntry', '_cw_entity_fields:A': 'content-subject,title-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
500 |
'content-subject:A': u'"13:03:43"', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
501 |
'title-subject:A': u'huuu', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
502 |
'__redirectrql': redirectrql, |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
503 |
'__redirectvid': 'primary', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
504 |
'__redirectparams': 'toto=tutu&tata=titi', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
505 |
'__form_id': 'edition', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
506 |
'__action_apply': '', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
507 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
508 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
509 |
self.assertTrue(path.startswith('blogentry/')) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
510 |
eid = path.split('/')[1] |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
511 |
self.assertEqual(params['vid'], 'edition') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
512 |
self.assertNotEqual(int(eid), 4012) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
513 |
self.assertEqual(params['__redirectrql'], redirectrql) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
514 |
self.assertEqual(params['__redirectvid'], 'primary') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
515 |
self.assertEqual(params['__redirectparams'], 'toto=tutu&tata=titi') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
516 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
517 |
def test_redirect_ok_button(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
518 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
519 |
redirectrql = rql_for_eid(4012) # whatever |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
520 |
req.form = { |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
521 |
'eid': 'A', '__maineid' : 'A', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
522 |
'__type:A': 'BlogEntry', '_cw_entity_fields:A': 'content-subject,title-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
523 |
'content-subject:A': u'"13:03:43"', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
524 |
'title-subject:A': u'huuu', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
525 |
'__redirectrql': redirectrql, |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
526 |
'__redirectvid': 'primary', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
527 |
'__redirectparams': 'toto=tutu&tata=titi', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
528 |
'__form_id': 'edition', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
529 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
530 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
531 |
self.assertEqual(path, 'view') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
532 |
self.assertEqual(params['rql'], redirectrql) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
533 |
self.assertEqual(params['vid'], 'primary') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
534 |
self.assertEqual(params['tata'], 'titi') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
535 |
self.assertEqual(params['toto'], 'tutu') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
536 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
537 |
def test_redirect_delete_button(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
538 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
539 |
eid = req.create_entity('BlogEntry', title=u'hop', content=u'hop').eid |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
540 |
req.form = {'eid': text_type(eid), '__type:%s'%eid: 'BlogEntry', |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
541 |
'__action_delete': ''} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
542 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
543 |
self.assertEqual(path, 'blogentry') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
544 |
self.assertIn('_cwmsgid', params) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
545 |
eid = req.create_entity('EmailAddress', address=u'hop@logilab.fr').eid |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
546 |
req.execute('SET X use_email E WHERE E eid %(e)s, X eid %(x)s', |
10254
e42c2226c878
[web/test] fix cubicweb 3.19 deprecation warning
Julien Cristau <julien.cristau@logilab.fr>
parents:
10253
diff
changeset
|
547 |
{'x': req.user.eid, 'e': eid}) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
548 |
req.cnx.commit() |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
549 |
req.form = {'eid': text_type(eid), '__type:%s'%eid: 'EmailAddress', |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
550 |
'__action_delete': ''} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
551 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
552 |
self.assertEqual(path, 'cwuser/admin') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
553 |
self.assertIn('_cwmsgid', params) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
554 |
eid1 = req.create_entity('BlogEntry', title=u'hop', content=u'hop').eid |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
555 |
eid2 = req.create_entity('EmailAddress', address=u'hop@logilab.fr').eid |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
556 |
req.form = {'eid': [text_type(eid1), text_type(eid2)], |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
557 |
'__type:%s'%eid1: 'BlogEntry', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
558 |
'__type:%s'%eid2: 'EmailAddress', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
559 |
'__action_delete': ''} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
560 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
561 |
self.assertEqual(path, 'view') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
562 |
self.assertIn('_cwmsgid', params) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
563 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
564 |
def test_simple_copy(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
565 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
566 |
blog = req.create_entity('Blog', title=u'my-blog') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
567 |
blogentry = req.create_entity('BlogEntry', title=u'entry1', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
568 |
content=u'content1', entry_of=blog) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
569 |
req.form = {'__maineid' : 'X', 'eid': 'X', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
570 |
'__cloned_eid:X': blogentry.eid, '__type:X': 'BlogEntry', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
571 |
'_cw_entity_fields:X': 'title-subject,content-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
572 |
'title-subject:X': u'entry1-copy', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
573 |
'content-subject:X': u'content1', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
574 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
575 |
self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
576 |
blogentry2 = req.find('BlogEntry', title=u'entry1-copy').one() |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
577 |
self.assertEqual(blogentry2.entry_of[0].eid, blog.eid) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
578 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
579 |
def test_skip_copy_for(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
580 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
581 |
blog = req.create_entity('Blog', title=u'my-blog') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
582 |
blogentry = req.create_entity('BlogEntry', title=u'entry1', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
583 |
content=u'content1', entry_of=blog) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
584 |
blogentry.__class__.cw_skip_copy_for = [('entry_of', 'subject')] |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
585 |
try: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
586 |
req.form = {'__maineid' : 'X', 'eid': 'X', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
587 |
'__cloned_eid:X': blogentry.eid, '__type:X': 'BlogEntry', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
588 |
'_cw_entity_fields:X': 'title-subject,content-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
589 |
'title-subject:X': u'entry1-copy', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
590 |
'content-subject:X': u'content1', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
591 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
592 |
self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
593 |
blogentry2 = req.find('BlogEntry', title=u'entry1-copy').one() |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
594 |
# entry_of should not be copied |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
595 |
self.assertEqual(len(blogentry2.entry_of), 0) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
596 |
finally: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
597 |
blogentry.__class__.cw_skip_copy_for = [] |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
598 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
599 |
def test_nonregr_eetype_etype_editing(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
600 |
"""non-regression test checking that a manager user can edit a CWEType entity |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
601 |
""" |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
602 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
603 |
groupeids = sorted(eid |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
604 |
for eid, in req.execute('CWGroup G ' |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
605 |
'WHERE G name in ("managers", "users")')) |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
606 |
groups = [text_type(eid) for eid in groupeids] |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
607 |
cwetypeeid = req.execute('CWEType X WHERE X name "CWEType"')[0][0] |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
608 |
basegroups = [text_type(eid) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
609 |
for eid, in req.execute('CWGroup G ' |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
610 |
'WHERE X read_permission G, X eid %(x)s', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
611 |
{'x': cwetypeeid})] |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
612 |
cwetypeeid = text_type(cwetypeeid) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
613 |
req.form = { |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
614 |
'eid': cwetypeeid, |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
615 |
'__type:'+cwetypeeid: 'CWEType', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
616 |
'_cw_entity_fields:'+cwetypeeid: 'name-subject,final-subject,description-subject,read_permission-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
617 |
'name-subject:'+cwetypeeid: u'CWEType', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
618 |
'final-subject:'+cwetypeeid: '', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
619 |
'description-subject:'+cwetypeeid: u'users group', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
620 |
'read_permission-subject:'+cwetypeeid: groups, |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
621 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
622 |
try: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
623 |
self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
624 |
e = req.execute('Any X WHERE X eid %(x)s', {'x': cwetypeeid}).get_entity(0, 0) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
625 |
self.assertEqual(e.name, 'CWEType') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
626 |
self.assertEqual(sorted(g.eid for g in e.read_permission), groupeids) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
627 |
finally: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
628 |
# restore |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
629 |
req.execute('SET X read_permission Y WHERE X name "CWEType", ' |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
630 |
'Y eid IN (%s), NOT X read_permission Y' % (','.join(basegroups))) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
631 |
req.cnx.commit() |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
632 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
633 |
def test_nonregr_strange_text_input(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
634 |
"""non-regression test checking text input containing "13:03:43" |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
635 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
636 |
this seems to be postgres (tsearch?) specific |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
637 |
""" |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
638 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
639 |
req.form = { |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
640 |
'eid': 'A', '__maineid' : 'A', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
641 |
'__type:A': 'BlogEntry', '_cw_entity_fields:A': 'title-subject,content-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
642 |
'title-subject:A': u'"13:03:40"', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
643 |
'content-subject:A': u'"13:03:43"',} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
644 |
path, _params = self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
645 |
self.assertTrue(path.startswith('blogentry/')) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
646 |
eid = path.split('/')[1] |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
647 |
e = req.execute('Any C, T WHERE C eid %(x)s, C content T', {'x': eid}).get_entity(0, 0) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
648 |
self.assertEqual(e.title, '"13:03:40"') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
649 |
self.assertEqual(e.content, '"13:03:43"') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
650 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
651 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
652 |
def test_nonregr_multiple_empty_email_addr(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
653 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
654 |
gueid = req.execute('CWGroup G WHERE G name "users"')[0][0] |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
655 |
req.form = {'eid': ['X', 'Y'], |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
656 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
657 |
'__type:X': 'CWUser', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
658 |
'_cw_entity_fields:X': 'login-subject,upassword-subject,in_group-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
659 |
'login-subject:X': u'adim', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
660 |
'upassword-subject:X': u'toto', 'upassword-subject-confirm:X': u'toto', |
10587
72447be71b48
[py3k] backtick to repr
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10255
diff
changeset
|
661 |
'in_group-subject:X': repr(gueid), |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
662 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
663 |
'__type:Y': 'EmailAddress', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
664 |
'_cw_entity_fields:Y': 'address-subject,alias-subject,use_email-object', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
665 |
'address-subject:Y': u'', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
666 |
'alias-subject:Y': u'', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
667 |
'use_email-object:Y': 'X', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
668 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
669 |
with self.assertRaises(ValidationError) as cm: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
670 |
self.ctrl_publish(req) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
671 |
self.assertEqual(cm.exception.errors, {'address-subject': u'required field'}) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
672 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
673 |
def test_nonregr_copy(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
674 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
675 |
user = req.user |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
676 |
req.form = {'__maineid' : 'X', 'eid': 'X', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
677 |
'__cloned_eid:X': user.eid, '__type:X': 'CWUser', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
678 |
'_cw_entity_fields:X': 'login-subject,upassword-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
679 |
'login-subject:X': u'toto', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
680 |
'upassword-subject:X': u'toto', 'upassword-subject-confirm:X': u'toto', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
681 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
682 |
path, _params = self.expect_redirect_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
683 |
self.assertEqual(path, 'cwuser/toto') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
684 |
e = req.execute('Any X WHERE X is CWUser, X login "toto"').get_entity(0, 0) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
685 |
self.assertEqual(e.login, 'toto') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
686 |
self.assertEqual(e.in_group[0].name, 'managers') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
687 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
688 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
689 |
def test_nonregr_rollback_on_validation_error(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
690 |
with self.admin_access.web_request() as req: |
10253
8eb9a3e9531c
[web/test] use unicode instead of str for user logins
Julien Cristau <julien.cristau@logilab.fr>
parents:
10083
diff
changeset
|
691 |
p = self.create_user(req, u"doe") |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
692 |
# do not try to skip 'primary_email' for this test |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
693 |
old_skips = p.__class__.skip_copy_for |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
694 |
p.__class__.skip_copy_for = () |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
695 |
try: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
696 |
e = req.create_entity('EmailAddress', address=u'doe@doe.com') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
697 |
req.execute('SET P use_email E, P primary_email E WHERE P eid %(p)s, E eid %(e)s', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
698 |
{'p' : p.eid, 'e' : e.eid}) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
699 |
req.form = {'eid': 'X', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
700 |
'__cloned_eid:X': p.eid, '__type:X': 'CWUser', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
701 |
'_cw_entity_fields:X': 'login-subject,surname-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
702 |
'login-subject': u'dodo', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
703 |
'surname-subject:X': u'Boom', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
704 |
'__errorurl' : "whatever but required", |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
705 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
706 |
# try to emulate what really happens in the web application |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
707 |
# 1/ validate form => EditController.publish raises a ValidationError |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
708 |
# which fires a Redirect |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
709 |
# 2/ When re-publishing the copy form, the publisher implicitly commits |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
710 |
try: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
711 |
self.app_handle_request(req, 'edit') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
712 |
except Redirect: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
713 |
req.form['rql'] = 'Any X WHERE X eid %s' % p.eid |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
714 |
req.form['vid'] = 'copy' |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
715 |
self.app_handle_request(req, 'view') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
716 |
rset = req.execute('CWUser P WHERE P surname "Boom"') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
717 |
self.assertEqual(len(rset), 0) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
718 |
finally: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
719 |
p.__class__.skip_copy_for = old_skips |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
720 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
721 |
def test_regr_inlined_forms(self): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
722 |
with self.admin_access.web_request() as req: |
9213
312062f53981
[inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9196
diff
changeset
|
723 |
self.schema['described_by_test'].inlined = False |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
724 |
try: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
725 |
req.data['eidmap'] = {} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
726 |
req.data['pending_others'] = set() |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
727 |
req.data['pending_inlined'] = {} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
728 |
req.form = {'eid': ['X', 'Y'], '__maineid' : 'X', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
729 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
730 |
'__type:X': 'Salesterm', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
731 |
'_cw_entity_fields:X': 'described_by_test-subject', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
732 |
'described_by_test-subject:X': 'Y', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
733 |
|
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
734 |
'__type:Y': 'File', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
735 |
'_cw_entity_fields:Y': 'data-subject', |
10704
73367a56ee41
[py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10603
diff
changeset
|
736 |
'data-subject:Y': (u'coucou.txt', Binary(b'coucou')), |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
737 |
} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
738 |
values_by_eid = dict((eid, req.extract_entity_params(eid, minparams=2)) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
739 |
for eid in req.edited_eids()) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
740 |
editctrl = self.vreg['controllers'].select('edit', req) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
741 |
# don't call publish to enforce select order |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
742 |
editctrl.errors = [] |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
743 |
editctrl._to_create = {} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
744 |
editctrl.edit_entity(values_by_eid['X']) # #3064653 raise ValidationError |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
745 |
editctrl.edit_entity(values_by_eid['Y']) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
746 |
finally: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
747 |
self.schema['described_by_test'].inlined = False |
9213
312062f53981
[inlined form field] fix regression introduced in 3.16.4/570208f74a84. Closes #3064653
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9196
diff
changeset
|
748 |
|
0 | 749 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
750 |
class ReportBugControllerTC(CubicWebTC): |
0 | 751 |
|
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6875
diff
changeset
|
752 |
def test_usable_by_guest(self): |
10253
8eb9a3e9531c
[web/test] use unicode instead of str for user logins
Julien Cristau <julien.cristau@logilab.fr>
parents:
10083
diff
changeset
|
753 |
with self.new_access(u'anon').web_request() as req: |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
754 |
self.assertRaises(NoSelectableObject, |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
755 |
self.vreg['controllers'].select, 'reportbug', req) |
10253
8eb9a3e9531c
[web/test] use unicode instead of str for user logins
Julien Cristau <julien.cristau@logilab.fr>
parents:
10083
diff
changeset
|
756 |
with self.new_access(u'anon').web_request(description='hop') as req: |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
757 |
self.vreg['controllers'].select('reportbug', req) |
0 | 758 |
|
759 |
||
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
760 |
class AjaxControllerTC(CubicWebTC): |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
761 |
tested_controller = 'ajax' |
0 | 762 |
|
763 |
def ctrl(self, req=None): |
|
764 |
req = req or self.request(url='http://whatever.fr/') |
|
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
765 |
return self.vreg['controllers'].select(self.tested_controller, req) |
0 | 766 |
|
767 |
def setup_database(self): |
|
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
768 |
with self.admin_access.repo_cnx() as cnx: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
769 |
self.pytag = cnx.create_entity('Tag', name=u'python') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
770 |
self.cubicwebtag = cnx.create_entity('Tag', name=u'cubicweb') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
771 |
self.john = self.create_user(cnx, u'John') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
772 |
cnx.commit() |
0 | 773 |
|
774 |
## tests ################################################################## |
|
775 |
def test_simple_exec(self): |
|
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
776 |
with self.admin_access.web_request(rql='CWUser P WHERE P login "John"', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
777 |
pageid='123', fname='view') as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
778 |
ctrl = self.ctrl(req) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
779 |
rset = self.john.as_rset() |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
780 |
rset.req = req |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
781 |
source = ctrl.publish() |
10749
2703116e4b21
[web/test] str → bytes
Julien Cristau <julien.cristau@logilab.fr>
parents:
10728
diff
changeset
|
782 |
self.assertTrue(source.startswith(b'<div>')) |
0 | 783 |
|
1654 | 784 |
# def test_json_exec(self): |
785 |
# rql = 'Any T,N WHERE T is Tag, T name N' |
|
786 |
# ctrl = self.ctrl(self.request(mode='json', rql=rql, pageid='123')) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
787 |
# self.assertEqual(ctrl.publish(), |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
788 |
# json_dumps(self.execute(rql).rows)) |
0 | 789 |
|
790 |
def test_remote_add_existing_tag(self): |
|
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
791 |
with self.remote_calling('tag_entity', self.john.eid, ['python']) as (_, req): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
792 |
self.assertCountEqual( |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
793 |
[tname for tname, in req.execute('Any N WHERE T is Tag, T name N')], |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
794 |
['python', 'cubicweb']) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
795 |
self.assertEqual( |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
796 |
req.execute('Any N WHERE T tags P, P is CWUser, T name N').rows, |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
797 |
[['python']]) |
1426 | 798 |
|
0 | 799 |
def test_remote_add_new_tag(self): |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
800 |
with self.remote_calling('tag_entity', self.john.eid, ['javascript']) as (_, req): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
801 |
self.assertCountEqual( |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
802 |
[tname for tname, in req.execute('Any N WHERE T is Tag, T name N')], |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
803 |
['python', 'cubicweb', 'javascript']) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
804 |
self.assertEqual( |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
805 |
req.execute('Any N WHERE T tags P, P is CWUser, T name N').rows, |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
806 |
[['javascript']]) |
0 | 807 |
|
10075
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10016
diff
changeset
|
808 |
def test_maydel_perms(self): |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10016
diff
changeset
|
809 |
"""Check that AjaxEditRelationCtxComponent calls rdef.check with a |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10016
diff
changeset
|
810 |
sufficient context""" |
10083
afc5615aa92b
[tests/web] switch previous commit (136b5f995f8) to the new test api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10075
diff
changeset
|
811 |
with self.remote_calling('tag_entity', self.john.eid, ['python']) as (_, req): |
afc5615aa92b
[tests/web] switch previous commit (136b5f995f8) to the new test api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10075
diff
changeset
|
812 |
req.cnx.commit() |
10075
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10016
diff
changeset
|
813 |
with self.temporary_permissions( |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10016
diff
changeset
|
814 |
(self.schema['tags'].rdefs['Tag', 'CWUser'], |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10016
diff
changeset
|
815 |
{'delete': (RRQLExpression('S owned_by U'), )}, )): |
10083
afc5615aa92b
[tests/web] switch previous commit (136b5f995f8) to the new test api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10075
diff
changeset
|
816 |
with self.admin_access.web_request(rql='CWUser P WHERE P login "John"', |
afc5615aa92b
[tests/web] switch previous commit (136b5f995f8) to the new test api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10075
diff
changeset
|
817 |
pageid='123', fname='view') as req: |
afc5615aa92b
[tests/web] switch previous commit (136b5f995f8) to the new test api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10075
diff
changeset
|
818 |
ctrl = self.ctrl(req) |
afc5615aa92b
[tests/web] switch previous commit (136b5f995f8) to the new test api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10075
diff
changeset
|
819 |
rset = self.john.as_rset() |
afc5615aa92b
[tests/web] switch previous commit (136b5f995f8) to the new test api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10075
diff
changeset
|
820 |
rset.req = req |
afc5615aa92b
[tests/web] switch previous commit (136b5f995f8) to the new test api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10075
diff
changeset
|
821 |
source = ctrl.publish() |
afc5615aa92b
[tests/web] switch previous commit (136b5f995f8) to the new test api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10075
diff
changeset
|
822 |
# maydel jscall |
10749
2703116e4b21
[web/test] str → bytes
Julien Cristau <julien.cristau@logilab.fr>
parents:
10728
diff
changeset
|
823 |
self.assertIn(b'ajaxBoxRemoveLinkedEntity', source) |
10075
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10016
diff
changeset
|
824 |
|
0 | 825 |
def test_pending_insertion(self): |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
826 |
with self.remote_calling('add_pending_inserts', [['12', 'tags', '13']]) as (_, req): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
827 |
deletes = get_pending_deletes(req) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
828 |
self.assertEqual(deletes, []) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
829 |
inserts = get_pending_inserts(req) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
830 |
self.assertEqual(inserts, ['12:tags:13']) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
831 |
with self.remote_calling('add_pending_inserts', [['12', 'tags', '14']]) as (_, req): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
832 |
deletes = get_pending_deletes(req) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
833 |
self.assertEqual(deletes, []) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
834 |
inserts = get_pending_inserts(req) |
10255
55413788be10
[web/test] don't depend on iteration order on a set
Julien Cristau <julien.cristau@logilab.fr>
parents:
10254
diff
changeset
|
835 |
self.assertCountEqual(inserts, ['12:tags:13', '12:tags:14']) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
836 |
inserts = get_pending_inserts(req, 12) |
10255
55413788be10
[web/test] don't depend on iteration order on a set
Julien Cristau <julien.cristau@logilab.fr>
parents:
10254
diff
changeset
|
837 |
self.assertCountEqual(inserts, ['12:tags:13', '12:tags:14']) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
838 |
inserts = get_pending_inserts(req, 13) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
839 |
self.assertEqual(inserts, ['12:tags:13']) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
840 |
inserts = get_pending_inserts(req, 14) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
841 |
self.assertEqual(inserts, ['12:tags:14']) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
842 |
req.remove_pending_operations() |
0 | 843 |
|
844 |
def test_pending_deletion(self): |
|
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
845 |
with self.remote_calling('add_pending_delete', ['12', 'tags', '13']) as (_, req): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
846 |
inserts = get_pending_inserts(req) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
847 |
self.assertEqual(inserts, []) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
848 |
deletes = get_pending_deletes(req) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
849 |
self.assertEqual(deletes, ['12:tags:13']) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
850 |
with self.remote_calling('add_pending_delete', ['12', 'tags', '14']) as (_, req): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
851 |
inserts = get_pending_inserts(req) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
852 |
self.assertEqual(inserts, []) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
853 |
deletes = get_pending_deletes(req) |
10255
55413788be10
[web/test] don't depend on iteration order on a set
Julien Cristau <julien.cristau@logilab.fr>
parents:
10254
diff
changeset
|
854 |
self.assertCountEqual(deletes, ['12:tags:13', '12:tags:14']) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
855 |
deletes = get_pending_deletes(req, 12) |
10255
55413788be10
[web/test] don't depend on iteration order on a set
Julien Cristau <julien.cristau@logilab.fr>
parents:
10254
diff
changeset
|
856 |
self.assertCountEqual(deletes, ['12:tags:13', '12:tags:14']) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
857 |
deletes = get_pending_deletes(req, 13) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
858 |
self.assertEqual(deletes, ['12:tags:13']) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
859 |
deletes = get_pending_deletes(req, 14) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
860 |
self.assertEqual(deletes, ['12:tags:14']) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
861 |
req.remove_pending_operations() |
0 | 862 |
|
863 |
def test_remove_pending_operations(self): |
|
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
864 |
with self.remote_calling('add_pending_delete', ['12', 'tags', '13']): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
865 |
pass |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
866 |
with self.remote_calling('add_pending_inserts', [['12', 'tags', '14']]) as (_, req): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
867 |
inserts = get_pending_inserts(req) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
868 |
self.assertEqual(inserts, ['12:tags:14']) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
869 |
deletes = get_pending_deletes(req) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
870 |
self.assertEqual(deletes, ['12:tags:13']) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
871 |
req.remove_pending_operations() |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
872 |
self.assertEqual(get_pending_deletes(req), []) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
873 |
self.assertEqual(get_pending_inserts(req), []) |
0 | 874 |
|
875 |
def test_add_inserts(self): |
|
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
876 |
with self.remote_calling('add_pending_inserts', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
877 |
[('12', 'tags', '13'), ('12', 'tags', '14')]) as (_, req): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
878 |
inserts = get_pending_inserts(req) |
10255
55413788be10
[web/test] don't depend on iteration order on a set
Julien Cristau <julien.cristau@logilab.fr>
parents:
10254
diff
changeset
|
879 |
self.assertCountEqual(inserts, ['12:tags:13', '12:tags:14']) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
880 |
req.remove_pending_operations() |
1426 | 881 |
|
0 | 882 |
|
883 |
# silly tests |
|
884 |
def test_external_resource(self): |
|
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
885 |
with self.remote_calling('external_resource', 'RSS_LOGO') as (res, _): |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
886 |
self.assertEqual(json_dumps(self.config.uiprops['RSS_LOGO']).encode('ascii'), |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
887 |
res) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
888 |
|
0 | 889 |
def test_i18n(self): |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
890 |
with self.remote_calling('i18n', ['bimboom']) as (res, _): |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
891 |
self.assertEqual(json_dumps(['bimboom']).encode('ascii'), res) |
0 | 892 |
|
893 |
def test_format_date(self): |
|
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
894 |
with self.remote_calling('format_date', '2007-01-01 12:00:00') as (res, _): |
10728
48c6de7321d8
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
895 |
self.assertEqual(json_dumps('2007/01/01').encode('ascii'), res) |
0 | 896 |
|
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
897 |
def test_ajaxfunc_noparameter(self): |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
898 |
@ajaxfunc |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
899 |
def foo(self, x, y): |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
900 |
return 'hello' |
8437
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
901 |
self.assertEqual(foo(object, 1, 2), 'hello') |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
902 |
appobject = foo.__appobject__ |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
903 |
self.assertTrue(issubclass(appobject, AjaxFunction)) |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
904 |
self.assertEqual(appobject.__regid__, 'foo') |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
905 |
self.assertEqual(appobject.check_pageid, False) |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
906 |
self.assertEqual(appobject.output_type, None) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
907 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
908 |
f = appobject(req) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
909 |
self.assertEqual(f(12, 13), 'hello') |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
910 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
911 |
def test_ajaxfunc_checkpageid(self): |
8437
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
912 |
@ajaxfunc(check_pageid=True) |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
913 |
def foo(self, x, y): |
8437
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
914 |
return 'hello' |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
915 |
self.assertEqual(foo(object, 1, 2), 'hello') |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
916 |
appobject = foo.__appobject__ |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
917 |
self.assertTrue(issubclass(appobject, AjaxFunction)) |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
918 |
self.assertEqual(appobject.__regid__, 'foo') |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
919 |
self.assertEqual(appobject.check_pageid, True) |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
920 |
self.assertEqual(appobject.output_type, None) |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
921 |
# no pageid |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
922 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
923 |
f = appobject(req) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
924 |
self.assertRaises(RemoteCallFailed, f, 12, 13) |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
925 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
926 |
def test_ajaxfunc_json(self): |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
927 |
@ajaxfunc(output_type='json') |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
928 |
def foo(self, x, y): |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
929 |
return x + y |
8437
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
930 |
self.assertEqual(foo(object, 1, 2), 3) |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
931 |
appobject = foo.__appobject__ |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
932 |
self.assertTrue(issubclass(appobject, AjaxFunction)) |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
933 |
self.assertEqual(appobject.__regid__, 'foo') |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
934 |
self.assertEqual(appobject.check_pageid, False) |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8312
diff
changeset
|
935 |
self.assertEqual(appobject.output_type, 'json') |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
936 |
# no pageid |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
937 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
938 |
f = appobject(req) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
939 |
self.assertEqual(f(12, 13), '25') |
1426 | 940 |
|
0 | 941 |
|
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
942 |
class JSonControllerTC(AjaxControllerTC): |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
943 |
# NOTE: this class performs the same tests as AjaxController but with |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
944 |
# deprecated 'json' controller (i.e. check backward compatibility) |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
945 |
tested_controller = 'json' |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
946 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
947 |
def setUp(self): |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
948 |
super(JSonControllerTC, self).setUp() |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
949 |
self.exposed_remote_funcs = [fname for fname in dir(JSonController) |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
950 |
if fname.startswith('js_')] |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
951 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
952 |
def tearDown(self): |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
953 |
super(JSonControllerTC, self).tearDown() |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
954 |
for funcname in dir(JSonController): |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
955 |
# remove functions added dynamically during tests |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
956 |
if funcname.startswith('js_') and funcname not in self.exposed_remote_funcs: |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
957 |
delattr(JSonController, funcname) |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
958 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
959 |
def test_monkeypatch_jsoncontroller(self): |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
960 |
with self.assertRaises(RemoteCallFailed): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
961 |
with self.remote_calling('foo'): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
962 |
pass |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
963 |
@monkeypatch(JSonController) |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
964 |
def js_foo(self): |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
965 |
return u'hello' |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
966 |
with self.remote_calling('foo') as (res, _): |
10751
9ffdfa1d28f5
[web/test] str vs bytes
Julien Cristau <julien.cristau@logilab.fr>
parents:
10749
diff
changeset
|
967 |
self.assertEqual(res, b'hello') |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
968 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
969 |
def test_monkeypatch_jsoncontroller_xhtmlize(self): |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
970 |
with self.assertRaises(RemoteCallFailed): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
971 |
with self.remote_calling('foo'): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
972 |
pass |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
973 |
@monkeypatch(JSonController) |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
974 |
@xhtmlize |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
975 |
def js_foo(self): |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
976 |
return u'hello' |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
977 |
with self.remote_calling('foo') as (res, _): |
10751
9ffdfa1d28f5
[web/test] str vs bytes
Julien Cristau <julien.cristau@logilab.fr>
parents:
10749
diff
changeset
|
978 |
self.assertEqual(b'<div>hello</div>', res) |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
979 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
980 |
def test_monkeypatch_jsoncontroller_jsonize(self): |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
981 |
with self.assertRaises(RemoteCallFailed): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
982 |
with self.remote_calling('foo'): |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
983 |
pass |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
984 |
@monkeypatch(JSonController) |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
985 |
@jsonize |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
986 |
def js_foo(self): |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
987 |
return 12 |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
988 |
with self.remote_calling('foo') as (res, _): |
10751
9ffdfa1d28f5
[web/test] str vs bytes
Julien Cristau <julien.cristau@logilab.fr>
parents:
10749
diff
changeset
|
989 |
self.assertEqual(res, b'12') |
1426 | 990 |
|
8504
f21c72928662
[ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8487
diff
changeset
|
991 |
def test_monkeypatch_jsoncontroller_stdfunc(self): |
f21c72928662
[ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8487
diff
changeset
|
992 |
@monkeypatch(JSonController) |
f21c72928662
[ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8487
diff
changeset
|
993 |
@jsonize |
f21c72928662
[ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8487
diff
changeset
|
994 |
def js_reledit_form(self): |
f21c72928662
[ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8487
diff
changeset
|
995 |
return 12 |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
996 |
with self.remote_calling('reledit_form') as (res, _): |
10751
9ffdfa1d28f5
[web/test] str vs bytes
Julien Cristau <julien.cristau@logilab.fr>
parents:
10749
diff
changeset
|
997 |
self.assertEqual(res, b'12') |
8504
f21c72928662
[ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8487
diff
changeset
|
998 |
|
8267
486386d9f836
[web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8128
diff
changeset
|
999 |
|
486386d9f836
[web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8128
diff
changeset
|
1000 |
class UndoControllerTC(CubicWebTC): |
486386d9f836
[web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8128
diff
changeset
|
1001 |
|
8812
52af67a2f0a5
[session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8803
diff
changeset
|
1002 |
def setUp(self): |
9020
cb87e831c183
rename server.session.transaction into server.session.connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
1003 |
class Connection(OldConnection): |
8812
52af67a2f0a5
[session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8803
diff
changeset
|
1004 |
"""Force undo feature to be turned on in all case""" |
52af67a2f0a5
[session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8803
diff
changeset
|
1005 |
undo_actions = property(lambda tx: True, lambda x, y:None) |
9020
cb87e831c183
rename server.session.transaction into server.session.connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
1006 |
cubicweb.server.session.Connection = Connection |
8812
52af67a2f0a5
[session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8803
diff
changeset
|
1007 |
super(UndoControllerTC, self).setUp() |
52af67a2f0a5
[session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8803
diff
changeset
|
1008 |
|
52af67a2f0a5
[session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8803
diff
changeset
|
1009 |
def tearDown(self): |
52af67a2f0a5
[session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8803
diff
changeset
|
1010 |
super(UndoControllerTC, self).tearDown() |
9020
cb87e831c183
rename server.session.transaction into server.session.connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
1011 |
cubicweb.server.session.Connection = OldConnection |
8812
52af67a2f0a5
[session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8803
diff
changeset
|
1012 |
|
8267
486386d9f836
[web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8128
diff
changeset
|
1013 |
def setup_database(self): |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1014 |
with self.admin_access.repo_cnx() as cnx: |
10253
8eb9a3e9531c
[web/test] use unicode instead of str for user logins
Julien Cristau <julien.cristau@logilab.fr>
parents:
10083
diff
changeset
|
1015 |
self.toto = self.create_user(cnx, u'toto', |
8eb9a3e9531c
[web/test] use unicode instead of str for user logins
Julien Cristau <julien.cristau@logilab.fr>
parents:
10083
diff
changeset
|
1016 |
password=u'toto', |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1017 |
groups=('users',), |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1018 |
commit=False) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1019 |
self.txuuid_toto = cnx.commit() |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1020 |
self.toto_email = cnx.create_entity('EmailAddress', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1021 |
address=u'toto@logilab.org', |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1022 |
reverse_use_email=self.toto) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1023 |
self.txuuid_toto_email = cnx.commit() |
8267
486386d9f836
[web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8128
diff
changeset
|
1024 |
|
486386d9f836
[web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8128
diff
changeset
|
1025 |
def test_no_such_transaction(self): |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1026 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1027 |
txuuid = u"12345acbd" |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1028 |
req.form['txuuid'] = txuuid |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1029 |
controller = self.vreg['controllers'].select('undo', req) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1030 |
with self.assertRaises(tx.NoSuchTransaction) as cm: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1031 |
result = controller.publish(rset=None) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1032 |
self.assertEqual(cm.exception.txuuid, txuuid) |
8267
486386d9f836
[web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8128
diff
changeset
|
1033 |
|
486386d9f836
[web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8128
diff
changeset
|
1034 |
def assertURLPath(self, url, expected_path, expected_params=None): |
486386d9f836
[web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8128
diff
changeset
|
1035 |
""" This assert that the path part of `url` matches expected path |
486386d9f836
[web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8128
diff
changeset
|
1036 |
|
486386d9f836
[web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8128
diff
changeset
|
1037 |
TODO : implement assertion on the expected_params too |
486386d9f836
[web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8128
diff
changeset
|
1038 |
""" |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1039 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1040 |
scheme, netloc, path, query, fragment = urlsplit(url) |
10603
65ad6980976e
[py3k] import URL mangling functions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10587
diff
changeset
|
1041 |
query_dict = parse_qs(query) |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1042 |
expected_url = urljoin(req.base_url(), expected_path) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1043 |
self.assertEqual( urlunsplit((scheme, netloc, path, None, None)), expected_url) |
8267
486386d9f836
[web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8128
diff
changeset
|
1044 |
|
486386d9f836
[web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8128
diff
changeset
|
1045 |
def test_redirect_redirectpath(self): |
486386d9f836
[web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8128
diff
changeset
|
1046 |
"Check that the potential __redirectpath is honored" |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1047 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1048 |
txuuid = self.txuuid_toto_email |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1049 |
req.form['txuuid'] = txuuid |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1050 |
rpath = "toto" |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1051 |
req.form['__redirectpath'] = rpath |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1052 |
controller = self.vreg['controllers'].select('undo', req) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1053 |
with self.assertRaises(Redirect) as cm: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1054 |
result = controller.publish(rset=None) |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1055 |
self.assertURLPath(cm.exception.location, rpath) |
8267
486386d9f836
[web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8128
diff
changeset
|
1056 |
|
486386d9f836
[web] Exposes the undo feature to user through a undo-history view (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
8128
diff
changeset
|
1057 |
|
8311
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8267
diff
changeset
|
1058 |
class LoginControllerTC(CubicWebTC): |
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8267
diff
changeset
|
1059 |
|
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8267
diff
changeset
|
1060 |
def test_login_with_dest(self): |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1061 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1062 |
req.form = {'postlogin_path': 'elephants/babar'} |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1063 |
with self.assertRaises(Redirect) as cm: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1064 |
self.ctrl_publish(req, ctrl='login') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1065 |
self.assertEqual(req.build_url('elephants/babar'), cm.exception.location) |
8311
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8267
diff
changeset
|
1066 |
|
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8267
diff
changeset
|
1067 |
def test_login_no_dest(self): |
9846
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1068 |
with self.admin_access.web_request() as req: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1069 |
with self.assertRaises(Redirect) as cm: |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1070 |
self.ctrl_publish(req, ctrl='login') |
67c1b77b44be
[webtests/basecontrollers] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
1071 |
self.assertEqual(req.base_url(), cm.exception.location) |
8311
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8267
diff
changeset
|
1072 |
|
0 | 1073 |
if __name__ == '__main__': |
1074 |
unittest_main() |