author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Sun, 16 Jun 2013 23:36:06 +0200 | |
changeset 9446 | 18a186b02970 |
parent 9402 | 2c48c091b6a2 |
child 9478 | 2d7521881d3d |
permissions | -rw-r--r-- |
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
|
1 |
# copyright 2003-2013 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 |
|
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
|
20 |
from urlparse import urlsplit, urlunsplit, urljoin |
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
|
21 |
# parse_qs is deprecated in cgi and has been moved to urlparse in Python 2.6 |
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
|
22 |
try: |
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
|
23 |
from urlparse import parse_qs as url_parse_query |
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
|
24 |
except ImportError: |
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
|
25 |
from cgi import parse_qs as url_parse_query |
1899
361774742f3e
[test] fix test after xhml_wrap changed signature
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1797
diff
changeset
|
26 |
from logilab.common.testlib import unittest_main, mock_object |
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 |
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
|
30 |
from cubicweb.view import STRICT_DOCTYPE |
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 |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
34 |
from cubicweb.web import INTERNAL_FIELD_VALUE, Redirect, RequestError, 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 |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
37 |
from cubicweb.entities.authobjs import CWUser |
4390 | 38 |
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
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
45 |
u = unicode |
0 | 46 |
|
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
47 |
def req_form(user): |
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
48 |
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
|
49 |
'_cw_entity_fields:%s' % user.eid: '_cw_generic_field', |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
50 |
'__type:%s' % user.eid: user.__regid__ |
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
51 |
} |
0 | 52 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
53 |
class EditControllerTC(CubicWebTC): |
0 | 54 |
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
|
55 |
CubicWebTC.setUp(self) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7702
diff
changeset
|
56 |
self.assertTrue('users' in self.schema.eschema('CWGroup').get_groups('read')) |
1426 | 57 |
|
0 | 58 |
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
|
59 |
CubicWebTC.tearDown(self) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7702
diff
changeset
|
60 |
self.assertTrue('users' in self.schema.eschema('CWGroup').get_groups('read')) |
1426 | 61 |
|
0 | 62 |
def test_noparam_edit(self): |
63 |
"""check behaviour of this controller without any form parameter |
|
64 |
""" |
|
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
65 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
66 |
self.ctrl_publish(self.request()) |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
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 |
""" |
0 | 72 |
user = self.user() |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
73 |
req = self.request() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
74 |
req.form = {'eid': 'X', '__type:X': 'CWUser', |
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
|
75 |
'_cw_entity_fields:X': 'login-subject,upassword-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
76 |
'login-subject:X': u'admin', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
77 |
'upassword-subject:X': u'toto', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
78 |
'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
|
79 |
} |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
80 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
81 |
self.ctrl_publish(req) |
8594
001159e2e4f3
[validation api] properly use yams 0.36 validation error api and update message catalog. Follows bbe0d6985e59
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8556
diff
changeset
|
82 |
cm.exception.translate(unicode) |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
83 |
self.assertEqual(cm.exception.errors, {'login-subject': 'the value "admin" is already used, use another one'}) |
0 | 84 |
|
85 |
def test_user_editing_itself(self): |
|
86 |
"""checking that a manager user can edit itself |
|
87 |
""" |
|
88 |
user = self.user() |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
89 |
basegroups = [u(eid) for eid, in self.execute('CWGroup G WHERE X in_group G, X eid %(x)s', {'x': user.eid})] |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
90 |
groupeids = [eid for eid, in self.execute('CWGroup G WHERE G name in ("managers", "users")')] |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
91 |
groups = [u(eid) for eid in groupeids] |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
92 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
93 |
eid = u(user.eid) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
94 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
95 |
'eid': eid, '__type:'+eid: 'CWUser', |
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
|
96 |
'_cw_entity_fields:'+eid: 'login-subject,firstname-subject,surname-subject,in_group-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
97 |
'login-subject:'+eid: u(user.login), |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
98 |
'surname-subject:'+eid: u'Th\xe9nault', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
99 |
'firstname-subject:'+eid: u'Sylvain', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
100 |
'in_group-subject:'+eid: groups, |
0 | 101 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
102 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5038
diff
changeset
|
103 |
e = self.execute('Any X WHERE X eid %(x)s', {'x': user.eid}).get_entity(0, 0) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
104 |
self.assertEqual(e.firstname, u'Sylvain') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
105 |
self.assertEqual(e.surname, u'Th\xe9nault') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
106 |
self.assertEqual(e.login, user.login) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
107 |
self.assertEqual([g.eid for g in e.in_group], groupeids) |
0 | 108 |
|
109 |
def test_user_can_change_its_password(self): |
|
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6875
diff
changeset
|
110 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6875
diff
changeset
|
111 |
user = self.create_user(req, 'user') |
0 | 112 |
cnx = self.login('user') |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
113 |
eid = u(user.eid) |
0 | 114 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
115 |
'eid': eid, '__maineid' : eid, |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
116 |
'__type:'+eid: 'CWUser', |
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
|
117 |
'_cw_entity_fields:'+eid: 'upassword-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
118 |
'upassword-subject:'+eid: 'tournicoton', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
119 |
'upassword-subject-confirm:'+eid: 'tournicoton', |
0 | 120 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
121 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
0 | 122 |
cnx.commit() # commit to check we don't get late validation error for instance |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
123 |
self.assertEqual(path, 'cwuser/user') |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7702
diff
changeset
|
124 |
self.assertFalse('vid' in params) |
0 | 125 |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
126 |
def test_user_editing_itself_no_relation(self): |
0 | 127 |
"""checking we can edit an entity without specifying some required |
128 |
relations (meaning no changes) |
|
129 |
""" |
|
130 |
user = self.user() |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
131 |
groupeids = [g.eid for g in user.in_group] |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
132 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
133 |
eid = u(user.eid) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
134 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
135 |
'eid': eid, |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
136 |
'__type:'+eid: 'CWUser', |
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
|
137 |
'_cw_entity_fields:'+eid: 'login-subject,firstname-subject,surname-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
138 |
'login-subject:'+eid: u(user.login), |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
139 |
'firstname-subject:'+eid: u'Th\xe9nault', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
140 |
'surname-subject:'+eid: u'Sylvain', |
0 | 141 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
142 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5038
diff
changeset
|
143 |
e = self.execute('Any X WHERE X eid %(x)s', {'x': user.eid}).get_entity(0, 0) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
144 |
self.assertEqual(e.login, user.login) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
145 |
self.assertEqual(e.firstname, u'Th\xe9nault') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
146 |
self.assertEqual(e.surname, u'Sylvain') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
147 |
self.assertEqual([g.eid for g in e.in_group], groupeids) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
148 |
self.assertEqual(e.cw_adapt_to('IWorkflowable').state, 'activated') |
1426 | 149 |
|
150 |
||
0 | 151 |
def test_create_multiple_linked(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
152 |
gueid = self.execute('CWGroup G WHERE G name "users"')[0][0] |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
153 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
154 |
req.form = {'eid': ['X', 'Y'], '__maineid' : 'X', |
0 | 155 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
156 |
'__type:X': 'CWUser', |
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
|
157 |
'_cw_entity_fields:X': 'login-subject,upassword-subject,surname-subject,in_group-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
158 |
'login-subject:X': u'adim', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
159 |
'upassword-subject:X': u'toto', 'upassword-subject-confirm:X': u'toto', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
160 |
'surname-subject:X': u'Di Mascio', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
161 |
'in_group-subject:X': u(gueid), |
1426 | 162 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
163 |
'__type:Y': 'EmailAddress', |
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
|
164 |
'_cw_entity_fields:Y': 'address-subject,use_email-object', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
165 |
'address-subject:Y': u'dima@logilab.fr', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
166 |
'use_email-object:Y': 'X', |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
167 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
168 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
0 | 169 |
# should be redirected on the created person |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
170 |
self.assertEqual(path, 'cwuser/adim') |
0 | 171 |
e = self.execute('Any P WHERE P surname "Di Mascio"').get_entity(0, 0) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
172 |
self.assertEqual(e.surname, 'Di Mascio') |
0 | 173 |
email = e.use_email[0] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
174 |
self.assertEqual(email.address, 'dima@logilab.fr') |
1426 | 175 |
|
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
|
176 |
def test_create_mandatory_inlined(self): |
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
|
177 |
req = self.request() |
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
|
178 |
req.form = {'eid': ['X', 'Y'], '__maineid' : 'X', |
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
|
179 |
|
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
|
180 |
'__type:X': 'Salesterm', |
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
|
181 |
'_cw_entity_fields:X': '', |
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
|
182 |
|
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
|
183 |
'__type:Y': 'File', |
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
|
184 |
'_cw_entity_fields:Y': 'data-subject,described_by_test-object', |
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
|
185 |
'data-subject:Y': (u'coucou.txt', Binary('coucou')), |
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
|
186 |
'described_by_test-object:Y': 'X', |
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
|
187 |
} |
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
|
188 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
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
|
189 |
self.assertTrue(path.startswith('salesterm/'), path) |
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
|
190 |
eid = path.split('/')[1] |
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
|
191 |
salesterm = req.entity_from_eid(eid) |
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
|
192 |
# The NOT NULL constraint of mandatory relation implies that the File |
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
|
193 |
# must be created before the Salesterm, otherwise Salesterm insertion |
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
|
194 |
# will fail. |
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
|
195 |
# NOTE: sqlite does have NOT NULL constraint, unlike Postgres so the |
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
|
196 |
# insertion does not fail and we have to check dumbly that File is |
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
|
197 |
# created before. |
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
|
198 |
self.assertGreater(salesterm.eid, salesterm.described_by_test[0].eid) |
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
|
199 |
|
9196
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
200 |
def test_create_mandatory_inlined2(self): |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
201 |
req = self.request() |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
202 |
req.form = {'eid': ['X', 'Y'], '__maineid' : 'X', |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
203 |
|
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
204 |
'__type:X': 'Salesterm', |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
205 |
'_cw_entity_fields:X': 'described_by_test-subject', |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
206 |
'described_by_test-subject:X': 'Y', |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
207 |
|
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
208 |
'__type:Y': 'File', |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
209 |
'_cw_entity_fields:Y': 'data-subject', |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
210 |
'data-subject:Y': (u'coucou.txt', Binary('coucou')), |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
211 |
} |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
212 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
213 |
self.assertTrue(path.startswith('salesterm/'), path) |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
214 |
eid = path.split('/')[1] |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
215 |
salesterm = req.entity_from_eid(eid) |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
216 |
# The NOT NULL constraint of mandatory relation implies that the File |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
217 |
# must be created before the Salesterm, otherwise Salesterm insertion |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
218 |
# will fail. |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
219 |
# NOTE: sqlite does have NOT NULL constraint, unlike Postgres so the |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
220 |
# insertion does not fail and we have to check dumbly that File is |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
221 |
# created before. |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
222 |
self.assertGreater(salesterm.eid, salesterm.described_by_test[0].eid) |
13461cb8ff40
[editcontrollers] Account for role in the ordering of entities (Complements #3031719)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9184
diff
changeset
|
223 |
|
0 | 224 |
def test_edit_multiple_linked(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
|
225 |
req = self.request() |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6875
diff
changeset
|
226 |
peid = u(self.create_user(req, 'adim').eid) |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
227 |
req.form = {'eid': [peid, 'Y'], '__maineid': peid, |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
228 |
|
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
229 |
'__type:'+peid: u'CWUser', |
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
|
230 |
'_cw_entity_fields:'+peid: u'surname-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
231 |
'surname-subject:'+peid: u'Di Masci', |
1426 | 232 |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
233 |
'__type:Y': u'EmailAddress', |
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
|
234 |
'_cw_entity_fields:Y': u'address-subject,use_email-object', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
235 |
'address-subject:Y': u'dima@logilab.fr', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
236 |
'use_email-object:Y': peid, |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
237 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
238 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
0 | 239 |
# should be redirected on the created person |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
240 |
self.assertEqual(path, 'cwuser/adim') |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
241 |
e = self.execute('Any P WHERE P surname "Di Masci"').get_entity(0, 0) |
0 | 242 |
email = e.use_email[0] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
243 |
self.assertEqual(email.address, 'dima@logilab.fr') |
1426 | 244 |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
245 |
emaileid = u(email.eid) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
246 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
247 |
req.form = {'eid': [peid, emaileid], |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
248 |
|
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
249 |
'__type:'+peid: u'CWUser', |
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
|
250 |
'_cw_entity_fields:'+peid: u'surname-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
251 |
'surname-subject:'+peid: u'Di Masci', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
252 |
|
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
253 |
'__type:'+emaileid: u'EmailAddress', |
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
|
254 |
'_cw_entity_fields:'+emaileid: u'address-subject,use_email-object', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
255 |
'address-subject:'+emaileid: u'adim@logilab.fr', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
256 |
'use_email-object:'+emaileid: peid, |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
257 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
258 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
259 |
email.cw_clear_all_caches() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
260 |
self.assertEqual(email.address, 'adim@logilab.fr') |
0 | 261 |
|
1426 | 262 |
|
0 | 263 |
def test_password_confirm(self): |
264 |
"""test creation of two linked entities |
|
1426 | 265 |
""" |
0 | 266 |
user = self.user() |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
267 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
268 |
req.form = {'eid': 'X', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
269 |
'__cloned_eid:X': u(user.eid), '__type:X': 'CWUser', |
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
|
270 |
'_cw_entity_fields:X': 'login-subject,upassword-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
271 |
'login-subject:X': u'toto', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
272 |
'upassword-subject: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
|
273 |
} |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
274 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
275 |
self.ctrl_publish(req) |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
276 |
self.assertEqual(cm.exception.errors, {'upassword-subject': u'password and confirmation don\'t match'}) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
277 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
278 |
req.form = {'__cloned_eid:X': u(user.eid), |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
279 |
'eid': 'X', '__type:X': 'CWUser', |
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
|
280 |
'_cw_entity_fields:X': 'login-subject,upassword-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
281 |
'login-subject:X': u'toto', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
282 |
'upassword-subject:X': u'toto', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
283 |
'upassword-subject-confirm:X': u'tutu', |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
284 |
} |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
285 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
286 |
self.ctrl_publish(req) |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
287 |
self.assertEqual(cm.exception.errors, {'upassword-subject': u'password and confirmation don\'t match'}) |
0 | 288 |
|
289 |
||
290 |
def test_interval_bound_constraint_success(self): |
|
3587 | 291 |
feid = self.execute('INSERT File X: X data_name "toto.txt", X data %(data)s', |
0 | 292 |
{'data': Binary('yo')})[0][0] |
6365
a15cc5e16178
[test] must now commit file creation since the later ValidationError trigger a rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
293 |
self.commit() |
6410
2e7a7b0829ed
[test] fix tests broken by transaction behaviour on Unauthorized/ValidationError (no rollback but connection marked as non-commitable)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6365
diff
changeset
|
294 |
req = self.request(rollbackfirst=True) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
295 |
req.form = {'eid': ['X'], |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
296 |
'__type:X': 'Salesterm', |
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
|
297 |
'_cw_entity_fields:X': 'amount-subject,described_by_test-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
298 |
'amount-subject:X': u'-10', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
299 |
'described_by_test-subject:X': u(feid), |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
300 |
} |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
301 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
302 |
self.ctrl_publish(req) |
8594
001159e2e4f3
[validation api] properly use yams 0.36 validation error api and update message catalog. Follows bbe0d6985e59
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8556
diff
changeset
|
303 |
cm.exception.translate(unicode) |
7442
aee55fb4633c
[test] fix failure introduced by yams'changeset 644:f9c79356b758
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7293
diff
changeset
|
304 |
self.assertEqual(cm.exception.errors, {'amount-subject': 'value -10 must be >= 0'}) |
6410
2e7a7b0829ed
[test] fix tests broken by transaction behaviour on Unauthorized/ValidationError (no rollback but connection marked as non-commitable)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6365
diff
changeset
|
305 |
req = self.request(rollbackfirst=True) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
306 |
req.form = {'eid': ['X'], |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
307 |
'__type:X': 'Salesterm', |
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
|
308 |
'_cw_entity_fields:X': 'amount-subject,described_by_test-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
309 |
'amount-subject:X': u'110', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
310 |
'described_by_test-subject:X': u(feid), |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
311 |
} |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
312 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
313 |
self.ctrl_publish(req) |
8594
001159e2e4f3
[validation api] properly use yams 0.36 validation error api and update message catalog. Follows bbe0d6985e59
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8556
diff
changeset
|
314 |
cm.exception.translate(unicode) |
7442
aee55fb4633c
[test] fix failure introduced by yams'changeset 644:f9c79356b758
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7293
diff
changeset
|
315 |
self.assertEqual(cm.exception.errors, {'amount-subject': 'value 110 must be <= 100'}) |
9184
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
316 |
|
6410
2e7a7b0829ed
[test] fix tests broken by transaction behaviour on Unauthorized/ValidationError (no rollback but connection marked as non-commitable)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6365
diff
changeset
|
317 |
req = self.request(rollbackfirst=True) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
318 |
req.form = {'eid': ['X'], |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
319 |
'__type:X': 'Salesterm', |
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
|
320 |
'_cw_entity_fields:X': 'amount-subject,described_by_test-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
321 |
'amount-subject:X': u'10', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
322 |
'described_by_test-subject:X': u(feid), |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
323 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
324 |
self.expect_redirect_handle_request(req, 'edit') |
1426 | 325 |
# should be redirected on the created |
0 | 326 |
#eid = params['rql'].split()[-1] |
327 |
e = self.execute('Salesterm X').get_entity(0, 0) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
328 |
self.assertEqual(e.amount, 10) |
0 | 329 |
|
9184
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
330 |
def test_interval_bound_constraint_validateform(self): |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
331 |
"""Test the FormValidatorController controller on entity with |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
332 |
constrained attributes""" |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
333 |
feid = self.execute('INSERT File X: X data_name "toto.txt", X data %(data)s', |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
334 |
{'data': Binary('yo')})[0][0] |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
335 |
seid = self.request().create_entity('Salesterm', amount=0, described_by_test=feid).eid |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
336 |
self.commit() |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
337 |
|
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
338 |
# ensure a value that violate a constraint is properly detected |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
339 |
req = self.request(rollbackfirst=True) |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
340 |
req.form = {'eid': [unicode(seid)], |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
341 |
'__type:%s'%seid: 'Salesterm', |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
342 |
'_cw_entity_fields:%s'%seid: 'amount-subject', |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
343 |
'amount-subject:%s'%seid: u'-10', |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
344 |
} |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
345 |
self.assertEqual('''<script type="text/javascript"> |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
346 |
window.parent.handleFormValidationResponse('entityForm', null, null, [false, [%s, {"amount-subject": "value -10 must be >= 0"}], null], null); |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
347 |
</script>'''%seid, self.ctrl_publish(req, 'validateform')) |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
348 |
|
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
349 |
# ensure a value that comply a constraint is properly processed |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
350 |
req = self.request(rollbackfirst=True) |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
351 |
req.form = {'eid': [unicode(seid)], |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
352 |
'__type:%s'%seid: 'Salesterm', |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
353 |
'_cw_entity_fields:%s'%seid: 'amount-subject', |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
354 |
'amount-subject:%s'%seid: u'20', |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
355 |
} |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
356 |
self.assertEqual('''<script type="text/javascript"> |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
357 |
window.parent.handleFormValidationResponse('entityForm', null, null, [true, "http://testing.fr/cubicweb/view", null], null); |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
358 |
</script>''', self.ctrl_publish(req, 'validateform')) |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
359 |
self.assertEqual(20, self.execute('Any V WHERE X amount V, X eid %(eid)s', {'eid': seid})[0][0]) |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
360 |
|
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
361 |
req = self.request(rollbackfirst=True) |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
362 |
req.form = {'eid': ['X'], |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
363 |
'__type:X': 'Salesterm', |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
364 |
'_cw_entity_fields:X': 'amount-subject,described_by_test-subject', |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
365 |
'amount-subject:X': u'0', |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
366 |
'described_by_test-subject:X': u(feid), |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
367 |
} |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
368 |
|
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
369 |
# ensure a value that is modified in an operation on a modify |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
370 |
# hook works as it should (see |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
371 |
# https://www.cubicweb.org/ticket/2509729 ) |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
372 |
class MyOperation(Operation): |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
373 |
def precommit_event(self): |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
374 |
self.entity.cw_set(amount=-10) |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
375 |
class ValidationErrorInOpAfterHook(Hook): |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
376 |
__regid__ = 'valerror-op-after-hook' |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
377 |
__select__ = Hook.__select__ & is_instance('Salesterm') |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
378 |
events = ('after_add_entity',) |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
379 |
def __call__(self): |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
380 |
MyOperation(self._cw, entity=self.entity) |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
381 |
|
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
382 |
with self.temporary_appobjects(ValidationErrorInOpAfterHook): |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
383 |
self.assertEqual('''<script type="text/javascript"> |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
384 |
window.parent.handleFormValidationResponse('entityForm', null, null, [false, ["X", {"amount-subject": "value -10 must be >= 0"}], null], null); |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
385 |
</script>''', self.ctrl_publish(req, 'validateform')) |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
386 |
|
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
387 |
self.assertEqual('''<script type="text/javascript"> |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
388 |
window.parent.handleFormValidationResponse('entityForm', null, null, [true, "http://testing.fr/cubicweb/view", null], null); |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
389 |
</script>''', self.ctrl_publish(req, 'validateform')) |
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9179
diff
changeset
|
390 |
|
0 | 391 |
def test_req_pending_insert(self): |
392 |
"""make sure req's pending insertions are taken into account""" |
|
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
393 |
tmpgroup = self.request().create_entity('CWGroup', name=u"test") |
0 | 394 |
user = self.user() |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
395 |
req = self.request(**req_form(user)) |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
396 |
req.session.data['pending_insert'] = set([(user.eid, 'in_group', tmpgroup.eid)]) |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
397 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
0 | 398 |
usergroups = [gname for gname, in |
399 |
self.execute('Any N WHERE G name N, U in_group G, U eid %(u)s', {'u': user.eid})] |
|
9273
f3795da61959
[test] use assertCountEqual instead of assertItemsEqual
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9213
diff
changeset
|
400 |
self.assertCountEqual(usergroups, ['managers', 'test']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
401 |
self.assertEqual(get_pending_inserts(req), []) |
0 | 402 |
|
403 |
def test_req_pending_delete(self): |
|
404 |
"""make sure req's pending deletions are taken into account""" |
|
405 |
user = self.user() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
406 |
groupeid = self.execute('INSERT CWGroup G: G name "test", U in_group G WHERE U eid %(x)s', |
0 | 407 |
{'x': user.eid})[0][0] |
408 |
usergroups = [gname for gname, in |
|
409 |
self.execute('Any N WHERE G name N, U in_group G, U eid %(u)s', {'u': user.eid})] |
|
410 |
# just make sure everything was set correctly |
|
9273
f3795da61959
[test] use assertCountEqual instead of assertItemsEqual
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9213
diff
changeset
|
411 |
self.assertCountEqual(usergroups, ['managers', 'test']) |
0 | 412 |
# now try to delete the relation |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
413 |
req = self.request(**req_form(user)) |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
414 |
req.session.data['pending_delete'] = set([(user.eid, 'in_group', groupeid)]) |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
415 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
0 | 416 |
usergroups = [gname for gname, in |
417 |
self.execute('Any N WHERE G name N, U in_group G, U eid %(u)s', {'u': user.eid})] |
|
9273
f3795da61959
[test] use assertCountEqual instead of assertItemsEqual
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9213
diff
changeset
|
418 |
self.assertCountEqual(usergroups, ['managers']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
419 |
self.assertEqual(get_pending_deletes(req), []) |
0 | 420 |
|
421 |
def test_redirect_apply_button(self): |
|
422 |
redirectrql = rql_for_eid(4012) # whatever |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
423 |
req = self.request() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
424 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
425 |
'eid': 'A', '__maineid' : 'A', |
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
|
426 |
'__type:A': 'BlogEntry', '_cw_entity_fields:A': 'content-subject,title-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
427 |
'content-subject:A': u'"13:03:43"', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
428 |
'title-subject:A': u'huuu', |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
429 |
'__redirectrql': redirectrql, |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
430 |
'__redirectvid': 'primary', |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
431 |
'__redirectparams': 'toto=tutu&tata=titi', |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
432 |
'__form_id': 'edition', |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
433 |
'__action_apply': '', |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
434 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
435 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7702
diff
changeset
|
436 |
self.assertTrue(path.startswith('blogentry/')) |
0 | 437 |
eid = path.split('/')[1] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
438 |
self.assertEqual(params['vid'], 'edition') |
6412
370357e68837
[test] cleanup / unittest2 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
439 |
self.assertNotEqual(int(eid), 4012) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
440 |
self.assertEqual(params['__redirectrql'], redirectrql) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
441 |
self.assertEqual(params['__redirectvid'], 'primary') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
442 |
self.assertEqual(params['__redirectparams'], 'toto=tutu&tata=titi') |
0 | 443 |
|
444 |
def test_redirect_ok_button(self): |
|
445 |
redirectrql = rql_for_eid(4012) # whatever |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
446 |
req = self.request() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
447 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
448 |
'eid': 'A', '__maineid' : 'A', |
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
|
449 |
'__type:A': 'BlogEntry', '_cw_entity_fields:A': 'content-subject,title-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
450 |
'content-subject:A': u'"13:03:43"', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
451 |
'title-subject:A': u'huuu', |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
452 |
'__redirectrql': redirectrql, |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
453 |
'__redirectvid': 'primary', |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
454 |
'__redirectparams': 'toto=tutu&tata=titi', |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
455 |
'__form_id': 'edition', |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
456 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
457 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
458 |
self.assertEqual(path, 'view') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
459 |
self.assertEqual(params['rql'], redirectrql) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
460 |
self.assertEqual(params['vid'], 'primary') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
461 |
self.assertEqual(params['tata'], 'titi') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
462 |
self.assertEqual(params['toto'], 'tutu') |
0 | 463 |
|
464 |
def test_redirect_delete_button(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
|
465 |
req = self.request() |
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
466 |
eid = req.create_entity('BlogEntry', title=u'hop', content=u'hop').eid |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
467 |
req.form = {'eid': u(eid), '__type:%s'%eid: 'BlogEntry', |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
468 |
'__action_delete': ''} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
469 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
470 |
self.assertEqual(path, 'blogentry') |
4918 | 471 |
self.assertIn('_cwmsgid', params) |
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
472 |
eid = req.create_entity('EmailAddress', address=u'hop@logilab.fr').eid |
0 | 473 |
self.execute('SET X use_email E WHERE E eid %(e)s, X eid %(x)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5038
diff
changeset
|
474 |
{'x': self.session.user.eid, 'e': eid}) |
0 | 475 |
self.commit() |
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
476 |
req = req |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
477 |
req.form = {'eid': u(eid), '__type:%s'%eid: 'EmailAddress', |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
478 |
'__action_delete': ''} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
479 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
480 |
self.assertEqual(path, 'cwuser/admin') |
4918 | 481 |
self.assertIn('_cwmsgid', params) |
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
482 |
eid1 = req.create_entity('BlogEntry', title=u'hop', content=u'hop').eid |
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
483 |
eid2 = req.create_entity('EmailAddress', address=u'hop@logilab.fr').eid |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
484 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
485 |
req.form = {'eid': [u(eid1), u(eid2)], |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
486 |
'__type:%s'%eid1: 'BlogEntry', |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
487 |
'__type:%s'%eid2: 'EmailAddress', |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
488 |
'__action_delete': ''} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
489 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
490 |
self.assertEqual(path, 'view') |
4918 | 491 |
self.assertIn('_cwmsgid', params) |
0 | 492 |
|
7702
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
493 |
def test_simple_copy(self): |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
494 |
req = self.request() |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
495 |
blog = req.create_entity('Blog', title=u'my-blog') |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
496 |
blogentry = req.create_entity('BlogEntry', title=u'entry1', |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
497 |
content=u'content1', entry_of=blog) |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
498 |
req = self.request() |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
499 |
req.form = {'__maineid' : 'X', 'eid': 'X', |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
500 |
'__cloned_eid:X': blogentry.eid, '__type:X': 'BlogEntry', |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
501 |
'_cw_entity_fields:X': 'title-subject,content-subject', |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
502 |
'title-subject:X': u'entry1-copy', |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
503 |
'content-subject:X': u'content1', |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
504 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
505 |
self.expect_redirect_handle_request(req, 'edit') |
7702
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
506 |
blogentry2 = req.find_one_entity('BlogEntry', title=u'entry1-copy') |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
507 |
self.assertEqual(blogentry2.entry_of[0].eid, blog.eid) |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
508 |
|
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
509 |
def test_skip_copy_for(self): |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
510 |
req = self.request() |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
511 |
blog = req.create_entity('Blog', title=u'my-blog') |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
512 |
blogentry = req.create_entity('BlogEntry', title=u'entry1', |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
513 |
content=u'content1', entry_of=blog) |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
514 |
blogentry.__class__.cw_skip_copy_for = [('entry_of', 'subject')] |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
515 |
try: |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
516 |
req = self.request() |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
517 |
req.form = {'__maineid' : 'X', 'eid': 'X', |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
518 |
'__cloned_eid:X': blogentry.eid, '__type:X': 'BlogEntry', |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
519 |
'_cw_entity_fields:X': 'title-subject,content-subject', |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
520 |
'title-subject:X': u'entry1-copy', |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
521 |
'content-subject:X': u'content1', |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
522 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
523 |
self.expect_redirect_handle_request(req, 'edit') |
7702
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
524 |
blogentry2 = req.find_one_entity('BlogEntry', title=u'entry1-copy') |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
525 |
# entry_of should not be copied |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
526 |
self.assertEqual(len(blogentry2.entry_of), 0) |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
527 |
finally: |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
528 |
blogentry.__class__.cw_skip_copy_for = [] |
73cadb5d0097
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7584
diff
changeset
|
529 |
|
0 | 530 |
def test_nonregr_eetype_etype_editing(self): |
4389
14a993bc8d1e
useless, same as test_nonregr_eetype_etype_editing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4292
diff
changeset
|
531 |
"""non-regression test checking that a manager user can edit a CWEType entity |
0 | 532 |
""" |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
533 |
groupeids = sorted(eid for eid, in self.execute('CWGroup G WHERE G name in ("managers", "users")')) |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
534 |
groups = [u(eid) for eid in groupeids] |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
535 |
cwetypeeid = self.execute('CWEType X WHERE X name "CWEType"')[0][0] |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
536 |
basegroups = [u(eid) for eid, in self.execute('CWGroup G WHERE X read_permission G, X eid %(x)s', {'x': cwetypeeid})] |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
537 |
cwetypeeid = u(cwetypeeid) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
538 |
req = self.request() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
539 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
540 |
'eid': cwetypeeid, |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
541 |
'__type:'+cwetypeeid: 'CWEType', |
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
|
542 |
'_cw_entity_fields:'+cwetypeeid: 'name-subject,final-subject,description-subject,read_permission-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
543 |
'name-subject:'+cwetypeeid: u'CWEType', |
4390 | 544 |
'final-subject:'+cwetypeeid: '', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
545 |
'description-subject:'+cwetypeeid: u'users group', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
546 |
'read_permission-subject:'+cwetypeeid: groups, |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
547 |
} |
0 | 548 |
try: |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
549 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5038
diff
changeset
|
550 |
e = self.execute('Any X WHERE X eid %(x)s', {'x': cwetypeeid}).get_entity(0, 0) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
551 |
self.assertEqual(e.name, 'CWEType') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
552 |
self.assertEqual(sorted(g.eid for g in e.read_permission), groupeids) |
0 | 553 |
finally: |
554 |
# restore |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
555 |
self.execute('SET X read_permission Y WHERE X name "CWEType", Y eid IN (%s), NOT X read_permission Y' % (','.join(basegroups))) |
0 | 556 |
self.commit() |
1426 | 557 |
|
0 | 558 |
def test_nonregr_strange_text_input(self): |
559 |
"""non-regression test checking text input containing "13:03:43" |
|
560 |
||
561 |
this seems to be postgres (tsearch?) specific |
|
1426 | 562 |
""" |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
563 |
req = self.request() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
564 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
565 |
'eid': 'A', '__maineid' : 'A', |
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
|
566 |
'__type:A': 'BlogEntry', '_cw_entity_fields:A': 'title-subject,content-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
567 |
'title-subject:A': u'"13:03:40"', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
568 |
'content-subject:A': u'"13:03:43"',} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
569 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7702
diff
changeset
|
570 |
self.assertTrue(path.startswith('blogentry/')) |
0 | 571 |
eid = path.split('/')[1] |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5038
diff
changeset
|
572 |
e = self.execute('Any C, T WHERE C eid %(x)s, C content T', {'x': eid}).get_entity(0, 0) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
573 |
self.assertEqual(e.title, '"13:03:40"') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
574 |
self.assertEqual(e.content, '"13:03:43"') |
0 | 575 |
|
576 |
||
577 |
def test_nonregr_multiple_empty_email_addr(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
578 |
gueid = self.execute('CWGroup G WHERE G name "users"')[0][0] |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
579 |
req = self.request() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
580 |
req.form = {'eid': ['X', 'Y'], |
1426 | 581 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
582 |
'__type:X': 'CWUser', |
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
|
583 |
'_cw_entity_fields:X': 'login-subject,upassword-subject,in_group-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
584 |
'login-subject:X': u'adim', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
585 |
'upassword-subject:X': u'toto', 'upassword-subject-confirm:X': u'toto', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
586 |
'in_group-subject:X': `gueid`, |
1426 | 587 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
588 |
'__type:Y': 'EmailAddress', |
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
|
589 |
'_cw_entity_fields:Y': 'address-subject,alias-subject,use_email-object', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
590 |
'address-subject:Y': u'', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
591 |
'alias-subject:Y': u'', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
592 |
'use_email-object:Y': 'X', |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
593 |
} |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
594 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
595 |
self.ctrl_publish(req) |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
596 |
self.assertEqual(cm.exception.errors, {'address-subject': u'required field'}) |
0 | 597 |
|
598 |
def test_nonregr_copy(self): |
|
599 |
user = self.user() |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
600 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
601 |
req.form = {'__maineid' : 'X', 'eid': 'X', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
602 |
'__cloned_eid:X': user.eid, '__type:X': 'CWUser', |
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
|
603 |
'_cw_entity_fields:X': 'login-subject,upassword-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
604 |
'login-subject:X': u'toto', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
605 |
'upassword-subject:X': u'toto', '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
|
606 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
607 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
608 |
self.assertEqual(path, 'cwuser/toto') |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
609 |
e = self.execute('Any X WHERE X is CWUser, X login "toto"').get_entity(0, 0) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
610 |
self.assertEqual(e.login, 'toto') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
611 |
self.assertEqual(e.in_group[0].name, 'managers') |
0 | 612 |
|
613 |
||
614 |
def test_nonregr_rollback_on_validation_error(self): |
|
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6875
diff
changeset
|
615 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6875
diff
changeset
|
616 |
p = self.create_user(req, "doe") |
0 | 617 |
# do not try to skip 'primary_email' for this test |
618 |
old_skips = p.__class__.skip_copy_for |
|
619 |
p.__class__.skip_copy_for = () |
|
620 |
try: |
|
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
621 |
e = self.request().create_entity('EmailAddress', address=u'doe@doe.com') |
0 | 622 |
self.execute('SET P use_email E, P primary_email E WHERE P eid %(p)s, E eid %(e)s', |
623 |
{'p' : p.eid, 'e' : e.eid}) |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
624 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
625 |
req.form = {'eid': 'X', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
626 |
'__cloned_eid:X': p.eid, '__type:X': 'CWUser', |
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
|
627 |
'_cw_entity_fields:X': 'login-subject,surname-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
628 |
'login-subject': u'dodo', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
629 |
'surname-subject:X': u'Boom', |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
630 |
'__errorurl' : "whatever but required", |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
631 |
} |
0 | 632 |
# try to emulate what really happens in the web application |
633 |
# 1/ validate form => EditController.publish raises a ValidationError |
|
634 |
# which fires a Redirect |
|
635 |
# 2/ When re-publishing the copy form, the publisher implicitly commits |
|
636 |
try: |
|
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
637 |
self.app_handle_request(req, 'edit') |
0 | 638 |
except Redirect: |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
639 |
req = self.request() |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
640 |
req.form['rql'] = 'Any X WHERE X eid %s' % p.eid |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
641 |
req.form['vid'] = 'copy' |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
642 |
self.app_handle_request(req, 'view') |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
643 |
rset = self.execute('CWUser P WHERE P surname "Boom"') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
644 |
self.assertEqual(len(rset), 0) |
0 | 645 |
finally: |
646 |
p.__class__.skip_copy_for = old_skips |
|
647 |
||
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
|
648 |
def test_regr_inlined_forms(self): |
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
|
649 |
self.schema['described_by_test'].inlined = False |
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
|
650 |
try: |
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
|
651 |
req = self.request() |
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
|
652 |
req.data['eidmap'] = {} |
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
|
653 |
req.data['pending_others'] = set() |
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
|
654 |
req.data['pending_inlined'] = {} |
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
|
655 |
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
|
656 |
|
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
|
657 |
'__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
|
658 |
'_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
|
659 |
'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
|
660 |
|
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
|
661 |
'__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
|
662 |
'_cw_entity_fields:Y': 'data-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
|
663 |
'data-subject:Y': (u'coucou.txt', Binary('coucou')), |
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
|
664 |
} |
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
|
665 |
values_by_eid = dict((eid, req.extract_entity_params(eid, minparams=2)) |
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
|
666 |
for eid in req.edited_eids()) |
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
|
667 |
editctrl = self.vreg['controllers'].select('edit', req) |
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
|
668 |
# don't call publish to enforce select order |
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
|
669 |
editctrl.errors = [] |
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
|
670 |
editctrl._to_create = {} |
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
|
671 |
editctrl.edit_entity(values_by_eid['X']) # #3064653 raise ValidationError |
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
|
672 |
editctrl.edit_entity(values_by_eid['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
|
673 |
finally: |
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
|
674 |
self.schema['described_by_test'].inlined = False |
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
|
675 |
|
0 | 676 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
677 |
class ReportBugControllerTC(CubicWebTC): |
0 | 678 |
|
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6875
diff
changeset
|
679 |
def test_usable_by_guest(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
|
680 |
self.login('anon') |
4918 | 681 |
self.assertRaises(NoSelectableObject, |
682 |
self.vreg['controllers'].select, 'reportbug', self.request()) |
|
683 |
self.vreg['controllers'].select('reportbug', self.request(description='hop')) |
|
0 | 684 |
|
685 |
||
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
686 |
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
|
687 |
tested_controller = 'ajax' |
0 | 688 |
|
689 |
def ctrl(self, req=None): |
|
690 |
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
|
691 |
return self.vreg['controllers'].select(self.tested_controller, req) |
0 | 692 |
|
693 |
def setup_database(self): |
|
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
694 |
req = self.request() |
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
695 |
self.pytag = req.create_entity('Tag', name=u'python') |
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
696 |
self.cubicwebtag = req.create_entity('Tag', name=u'cubicweb') |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6875
diff
changeset
|
697 |
self.john = self.create_user(req, u'John') |
0 | 698 |
|
699 |
||
700 |
## tests ################################################################## |
|
701 |
def test_simple_exec(self): |
|
1654 | 702 |
req = self.request(rql='CWUser P WHERE P login "John"', |
703 |
pageid='123', fname='view') |
|
704 |
ctrl = self.ctrl(req) |
|
705 |
rset = self.john.as_rset() |
|
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1654
diff
changeset
|
706 |
rset.req = req |
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
|
707 |
source = ctrl.publish() |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7702
diff
changeset
|
708 |
self.assertTrue(source.startswith('<div>')) |
0 | 709 |
|
1654 | 710 |
# def test_json_exec(self): |
711 |
# rql = 'Any T,N WHERE T is Tag, T name N' |
|
712 |
# 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
|
713 |
# self.assertEqual(ctrl.publish(), |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
714 |
# json_dumps(self.execute(rql).rows)) |
0 | 715 |
|
716 |
def test_remote_add_existing_tag(self): |
|
717 |
self.remote_call('tag_entity', self.john.eid, ['python']) |
|
9273
f3795da61959
[test] use assertCountEqual instead of assertItemsEqual
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9213
diff
changeset
|
718 |
self.assertCountEqual( |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
719 |
[tname for tname, in self.execute('Any N WHERE T is Tag, T name N')], |
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
720 |
['python', 'cubicweb']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
721 |
self.assertEqual( |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
722 |
self.execute('Any N WHERE T tags P, P is CWUser, T name N').rows, |
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
723 |
[['python']]) |
1426 | 724 |
|
0 | 725 |
def test_remote_add_new_tag(self): |
726 |
self.remote_call('tag_entity', self.john.eid, ['javascript']) |
|
9273
f3795da61959
[test] use assertCountEqual instead of assertItemsEqual
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9213
diff
changeset
|
727 |
self.assertCountEqual( |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
728 |
[tname for tname, in self.execute('Any N WHERE T is Tag, T name N')], |
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
729 |
['python', 'cubicweb', 'javascript']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
730 |
self.assertEqual( |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
731 |
self.execute('Any N WHERE T tags P, P is CWUser, T name N').rows, |
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
732 |
[['javascript']]) |
0 | 733 |
|
734 |
def test_pending_insertion(self): |
|
1654 | 735 |
res, req = self.remote_call('add_pending_inserts', [['12', 'tags', '13']]) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
736 |
deletes = get_pending_deletes(req) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
737 |
self.assertEqual(deletes, []) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
738 |
inserts = get_pending_inserts(req) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
739 |
self.assertEqual(inserts, ['12:tags:13']) |
1654 | 740 |
res, req = self.remote_call('add_pending_inserts', [['12', 'tags', '14']]) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
741 |
deletes = get_pending_deletes(req) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
742 |
self.assertEqual(deletes, []) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
743 |
inserts = get_pending_inserts(req) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
744 |
self.assertEqual(inserts, ['12:tags:13', '12:tags:14']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
745 |
inserts = get_pending_inserts(req, 12) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
746 |
self.assertEqual(inserts, ['12:tags:13', '12:tags:14']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
747 |
inserts = get_pending_inserts(req, 13) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
748 |
self.assertEqual(inserts, ['12:tags:13']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
749 |
inserts = get_pending_inserts(req, 14) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
750 |
self.assertEqual(inserts, ['12:tags:14']) |
0 | 751 |
req.remove_pending_operations() |
752 |
||
753 |
def test_pending_deletion(self): |
|
754 |
res, req = self.remote_call('add_pending_delete', ['12', 'tags', '13']) |
|
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
755 |
inserts = get_pending_inserts(req) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
756 |
self.assertEqual(inserts, []) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
757 |
deletes = get_pending_deletes(req) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
758 |
self.assertEqual(deletes, ['12:tags:13']) |
0 | 759 |
res, req = self.remote_call('add_pending_delete', ['12', 'tags', '14']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
760 |
inserts = get_pending_inserts(req) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
761 |
self.assertEqual(inserts, []) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
762 |
deletes = get_pending_deletes(req) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
763 |
self.assertEqual(deletes, ['12:tags:13', '12:tags:14']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
764 |
deletes = get_pending_deletes(req, 12) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
765 |
self.assertEqual(deletes, ['12:tags:13', '12:tags:14']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
766 |
deletes = get_pending_deletes(req, 13) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
767 |
self.assertEqual(deletes, ['12:tags:13']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
768 |
deletes = get_pending_deletes(req, 14) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
769 |
self.assertEqual(deletes, ['12:tags:14']) |
0 | 770 |
req.remove_pending_operations() |
771 |
||
772 |
def test_remove_pending_operations(self): |
|
773 |
self.remote_call('add_pending_delete', ['12', 'tags', '13']) |
|
1654 | 774 |
_, req = self.remote_call('add_pending_inserts', [['12', 'tags', '14']]) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
775 |
inserts = get_pending_inserts(req) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
776 |
self.assertEqual(inserts, ['12:tags:14']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
777 |
deletes = get_pending_deletes(req) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
778 |
self.assertEqual(deletes, ['12:tags:13']) |
0 | 779 |
req.remove_pending_operations() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
780 |
self.assertEqual(get_pending_deletes(req), []) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
781 |
self.assertEqual(get_pending_inserts(req), []) |
1426 | 782 |
|
0 | 783 |
|
784 |
def test_add_inserts(self): |
|
785 |
res, req = self.remote_call('add_pending_inserts', |
|
786 |
[('12', 'tags', '13'), ('12', 'tags', '14')]) |
|
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
787 |
inserts = get_pending_inserts(req) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
788 |
self.assertEqual(inserts, ['12:tags:13', '12:tags:14']) |
0 | 789 |
req.remove_pending_operations() |
1426 | 790 |
|
0 | 791 |
|
792 |
# silly tests |
|
793 |
def test_external_resource(self): |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
794 |
self.assertEqual(self.remote_call('external_resource', 'RSS_LOGO')[0], |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
795 |
json_dumps(self.config.uiprops['RSS_LOGO'])) |
0 | 796 |
def test_i18n(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
797 |
self.assertEqual(self.remote_call('i18n', ['bimboom'])[0], |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
798 |
json_dumps(['bimboom'])) |
0 | 799 |
|
800 |
def test_format_date(self): |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
801 |
self.assertEqual(self.remote_call('format_date', '2007-01-01 12:00:00')[0], |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
802 |
json_dumps('2007/01/01')) |
0 | 803 |
|
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
804 |
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
|
805 |
@ajaxfunc |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
806 |
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
|
807 |
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
|
808 |
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
|
809 |
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
|
810 |
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
|
811 |
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
|
812 |
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
|
813 |
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
|
814 |
req = self.request() |
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
|
815 |
f = appobject(req) |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
816 |
self.assertEqual(f(12, 13), 'hello') |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
817 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
818 |
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
|
819 |
@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
|
820 |
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
|
821 |
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
|
822 |
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
|
823 |
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
|
824 |
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
|
825 |
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
|
826 |
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
|
827 |
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
|
828 |
# no pageid |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
829 |
req = self.request() |
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
|
830 |
f = appobject(req) |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
831 |
self.assertRaises(RemoteCallFailed, f, 12, 13) |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
832 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
833 |
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
|
834 |
@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
|
835 |
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
|
836 |
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
|
837 |
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
|
838 |
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
|
839 |
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
|
840 |
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
|
841 |
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
|
842 |
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
|
843 |
# no pageid |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
844 |
req = self.request() |
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
|
845 |
f = appobject(req) |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
846 |
self.assertEqual(f(12, 13), '25') |
1426 | 847 |
|
0 | 848 |
|
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
849 |
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
|
850 |
# 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
|
851 |
# 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
|
852 |
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
|
853 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
854 |
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
|
855 |
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
|
856 |
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
|
857 |
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
|
858 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
859 |
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
|
860 |
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
|
861 |
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
|
862 |
# 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
|
863 |
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
|
864 |
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
|
865 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
866 |
def test_monkeypatch_jsoncontroller(self): |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
867 |
self.assertRaises(RemoteCallFailed, self.remote_call, 'foo') |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
868 |
@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
|
869 |
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
|
870 |
return u'hello' |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
871 |
res, req = self.remote_call('foo') |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
872 |
self.assertEqual(res, u'hello') |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
873 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
874 |
def test_monkeypatch_jsoncontroller_xhtmlize(self): |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
875 |
self.assertRaises(RemoteCallFailed, self.remote_call, 'foo') |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
876 |
@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
|
877 |
@xhtmlize |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
878 |
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
|
879 |
return u'hello' |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
880 |
res, req = self.remote_call('foo') |
8941
7b26fe71404f
drop xhtml content-type support (closes #2065651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8849
diff
changeset
|
881 |
self.assertEqual(u'<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
|
882 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
883 |
def test_monkeypatch_jsoncontroller_jsonize(self): |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
884 |
self.assertRaises(RemoteCallFailed, self.remote_call, 'foo') |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
885 |
@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
|
886 |
@jsonize |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
887 |
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
|
888 |
return 12 |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
889 |
res, req = self.remote_call('foo') |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
890 |
self.assertEqual(res, '12') |
1426 | 891 |
|
8504
f21c72928662
[ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8487
diff
changeset
|
892 |
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
|
893 |
@monkeypatch(JSonController) |
f21c72928662
[ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8487
diff
changeset
|
894 |
@jsonize |
f21c72928662
[ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8487
diff
changeset
|
895 |
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
|
896 |
return 12 |
f21c72928662
[ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8487
diff
changeset
|
897 |
res, req = self.remote_call('reledit_form') |
f21c72928662
[ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8487
diff
changeset
|
898 |
self.assertEqual(res, '12') |
f21c72928662
[ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8487
diff
changeset
|
899 |
|
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
|
900 |
|
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
|
901 |
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
|
902 |
|
8812
52af67a2f0a5
[session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8803
diff
changeset
|
903 |
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
|
904 |
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
|
905 |
"""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
|
906 |
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
|
907 |
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
|
908 |
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
|
909 |
|
52af67a2f0a5
[session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8803
diff
changeset
|
910 |
def tearDown(self): |
52af67a2f0a5
[session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8803
diff
changeset
|
911 |
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
|
912 |
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
|
913 |
|
52af67a2f0a5
[session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8803
diff
changeset
|
914 |
|
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
|
915 |
def setup_database(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
|
916 |
req = self.request() |
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
|
917 |
self.toto = self.create_user(req, 'toto', password='toto', groups=('users',), |
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
|
918 |
commit=False) |
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
|
919 |
self.txuuid_toto = self.commit() |
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
|
920 |
self.toto_email = self.session.create_entity('EmailAddress', |
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
|
921 |
address=u'toto@logilab.org', |
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
|
922 |
reverse_use_email=self.toto) |
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
|
923 |
self.txuuid_toto_email = self.commit() |
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
|
924 |
|
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
|
925 |
def test_no_such_transaction(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
|
926 |
req = self.request() |
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
|
927 |
txuuid = u"12345acbd" |
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
|
928 |
req.form['txuuid'] = txuuid |
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
|
929 |
controller = self.vreg['controllers'].select('undo', req) |
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
|
930 |
with self.assertRaises(tx.NoSuchTransaction) as cm: |
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
|
931 |
result = controller.publish(rset=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
|
932 |
self.assertEqual(cm.exception.txuuid, txuuid) |
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
|
933 |
|
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
|
934 |
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
|
935 |
""" 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
|
936 |
|
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
|
937 |
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
|
938 |
""" |
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
|
939 |
req = self.request() |
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
|
940 |
scheme, netloc, path, query, fragment = urlsplit(url) |
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
|
941 |
query_dict = url_parse_query(query) |
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
|
942 |
expected_url = urljoin(req.base_url(), 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
|
943 |
self.assertEqual( urlunsplit((scheme, netloc, path, None, None)), expected_url) |
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
|
944 |
|
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
|
945 |
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
|
946 |
"Check that the potential __redirectpath is honored" |
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
|
947 |
req = self.request() |
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
|
948 |
txuuid = self.txuuid_toto_email |
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
|
949 |
req.form['txuuid'] = txuuid |
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
|
950 |
rpath = "toto" |
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
|
951 |
req.form['__redirectpath'] = rpath |
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
|
952 |
controller = self.vreg['controllers'].select('undo', req) |
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
|
953 |
with self.assertRaises(Redirect) as cm: |
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
|
954 |
result = controller.publish(rset=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
|
955 |
self.assertURLPath(cm.exception.location, rpath) |
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
|
956 |
|
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
|
957 |
def test_redirect_default(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
|
958 |
req = self.request() |
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
|
959 |
txuuid = self.txuuid_toto_email |
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
|
960 |
req.form['txuuid'] = txuuid |
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
|
961 |
req.session.data['breadcrumbs'] = [ urljoin(req.base_url(), 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
|
962 |
for path in ('tata', 'toto',)] |
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
|
963 |
controller = self.vreg['controllers'].select('undo', req) |
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
|
964 |
with self.assertRaises(Redirect) as cm: |
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
|
965 |
result = controller.publish(rset=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
|
966 |
self.assertURLPath(cm.exception.location, 'toto') |
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
|
967 |
|
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
|
968 |
|
8311
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8267
diff
changeset
|
969 |
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
|
970 |
|
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8267
diff
changeset
|
971 |
def test_login_with_dest(self): |
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8267
diff
changeset
|
972 |
req = self.request() |
8487
017af22e7678
[web test] fix tests broken by 8de41063d629
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8444
diff
changeset
|
973 |
req.form = {'postlogin_path': 'elephants/babar'} |
8311
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8267
diff
changeset
|
974 |
with self.assertRaises(Redirect) as cm: |
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8267
diff
changeset
|
975 |
self.ctrl_publish(req, ctrl='login') |
8487
017af22e7678
[web test] fix tests broken by 8de41063d629
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8444
diff
changeset
|
976 |
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
|
977 |
|
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8267
diff
changeset
|
978 |
def test_login_no_dest(self): |
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8267
diff
changeset
|
979 |
req = self.request() |
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8267
diff
changeset
|
980 |
with self.assertRaises(Redirect) as cm: |
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8267
diff
changeset
|
981 |
self.ctrl_publish(req, ctrl='login') |
8487
017af22e7678
[web test] fix tests broken by 8de41063d629
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8444
diff
changeset
|
982 |
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
|
983 |
|
0 | 984 |
if __name__ == '__main__': |
985 |
unittest_main() |