author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Tue, 19 Mar 2013 15:17:34 +0100 | |
changeset 8734 | 3530b7494195 |
parent 8694 | d901c36bcfce |
child 8803 | 47dd517d6c6f |
permissions | -rw-r--r-- |
8544
3d049071957e
massive copyright update to avoid clutering later patches
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8504
diff
changeset
|
1 |
# copyright 2003-2012 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 |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
35 |
from cubicweb.entities.authobjs import CWUser |
4390 | 36 |
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
|
37 |
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
|
38 |
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
|
39 |
import cubicweb.transaction as tx |
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
40 |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
41 |
u = unicode |
0 | 42 |
|
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
43 |
def req_form(user): |
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
44 |
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
|
45 |
'_cw_entity_fields:%s' % user.eid: '_cw_generic_field', |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
46 |
'__type:%s' % user.eid: user.__regid__ |
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
47 |
} |
0 | 48 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
49 |
class EditControllerTC(CubicWebTC): |
0 | 50 |
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
|
51 |
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
|
52 |
self.assertTrue('users' in self.schema.eschema('CWGroup').get_groups('read')) |
1426 | 53 |
|
0 | 54 |
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
|
55 |
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
|
56 |
self.assertTrue('users' in self.schema.eschema('CWGroup').get_groups('read')) |
1426 | 57 |
|
0 | 58 |
def test_noparam_edit(self): |
59 |
"""check behaviour of this controller without any form parameter |
|
60 |
""" |
|
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
61 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
62 |
self.ctrl_publish(self.request()) |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
63 |
self.assertEqual(cm.exception.errors, {None: u'no selected entities'}) |
1426 | 64 |
|
0 | 65 |
def test_validation_unique(self): |
66 |
"""test creation of two linked entities |
|
1426 | 67 |
""" |
0 | 68 |
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
|
69 |
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
|
70 |
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
|
71 |
'_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
|
72 |
'login-subject:X': u'admin', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
73 |
'upassword-subject:X': u'toto', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
74 |
'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
|
75 |
} |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
76 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
77 |
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
|
78 |
cm.exception.translate(unicode) |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
79 |
self.assertEqual(cm.exception.errors, {'login-subject': 'the value "admin" is already used, use another one'}) |
0 | 80 |
|
81 |
def test_user_editing_itself(self): |
|
82 |
"""checking that a manager user can edit itself |
|
83 |
""" |
|
84 |
user = self.user() |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
85 |
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
|
86 |
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
|
87 |
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
|
88 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
89 |
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
|
90 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
91 |
'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
|
92 |
'_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
|
93 |
'login-subject:'+eid: u(user.login), |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
94 |
'surname-subject:'+eid: u'Th\xe9nault', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
95 |
'firstname-subject:'+eid: u'Sylvain', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
96 |
'in_group-subject:'+eid: groups, |
0 | 97 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
98 |
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
|
99 |
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
|
100 |
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
|
101 |
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
|
102 |
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
|
103 |
self.assertEqual([g.eid for g in e.in_group], groupeids) |
0 | 104 |
|
105 |
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
|
106 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6875
diff
changeset
|
107 |
user = self.create_user(req, 'user') |
0 | 108 |
cnx = self.login('user') |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
109 |
eid = u(user.eid) |
0 | 110 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
111 |
'eid': eid, '__maineid' : eid, |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
112 |
'__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
|
113 |
'_cw_entity_fields:'+eid: 'upassword-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
114 |
'upassword-subject:'+eid: 'tournicoton', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
115 |
'upassword-subject-confirm:'+eid: 'tournicoton', |
0 | 116 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
117 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
0 | 118 |
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
|
119 |
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
|
120 |
self.assertFalse('vid' in params) |
0 | 121 |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
122 |
def test_user_editing_itself_no_relation(self): |
0 | 123 |
"""checking we can edit an entity without specifying some required |
124 |
relations (meaning no changes) |
|
125 |
""" |
|
126 |
user = self.user() |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
127 |
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
|
128 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
129 |
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
|
130 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
131 |
'eid': eid, |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
132 |
'__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
|
133 |
'_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
|
134 |
'login-subject:'+eid: u(user.login), |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
135 |
'firstname-subject:'+eid: u'Th\xe9nault', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
136 |
'surname-subject:'+eid: u'Sylvain', |
0 | 137 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
138 |
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
|
139 |
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
|
140 |
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
|
141 |
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
|
142 |
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
|
143 |
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
|
144 |
self.assertEqual(e.cw_adapt_to('IWorkflowable').state, 'activated') |
1426 | 145 |
|
146 |
||
0 | 147 |
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
|
148 |
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
|
149 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
150 |
req.form = {'eid': ['X', 'Y'], '__maineid' : 'X', |
0 | 151 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
152 |
'__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
|
153 |
'_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
|
154 |
'login-subject:X': u'adim', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
155 |
'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
|
156 |
'surname-subject:X': u'Di Mascio', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
157 |
'in_group-subject:X': u(gueid), |
1426 | 158 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
159 |
'__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
|
160 |
'_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
|
161 |
'address-subject:Y': u'dima@logilab.fr', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
162 |
'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
|
163 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
164 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
0 | 165 |
# 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
|
166 |
self.assertEqual(path, 'cwuser/adim') |
0 | 167 |
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
|
168 |
self.assertEqual(e.surname, 'Di Mascio') |
0 | 169 |
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
|
170 |
self.assertEqual(email.address, 'dima@logilab.fr') |
1426 | 171 |
|
0 | 172 |
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
|
173 |
req = self.request() |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6875
diff
changeset
|
174 |
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
|
175 |
req.form = {'eid': [peid, 'Y'], '__maineid': peid, |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
176 |
|
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
177 |
'__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
|
178 |
'_cw_entity_fields:'+peid: u'surname-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
179 |
'surname-subject:'+peid: u'Di Masci', |
1426 | 180 |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
181 |
'__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
|
182 |
'_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
|
183 |
'address-subject:Y': u'dima@logilab.fr', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
184 |
'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
|
185 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
186 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
0 | 187 |
# 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
|
188 |
self.assertEqual(path, 'cwuser/adim') |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
189 |
e = self.execute('Any P WHERE P surname "Di Masci"').get_entity(0, 0) |
0 | 190 |
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
|
191 |
self.assertEqual(email.address, 'dima@logilab.fr') |
1426 | 192 |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
193 |
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
|
194 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
195 |
req.form = {'eid': [peid, emaileid], |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
196 |
|
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
197 |
'__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
|
198 |
'_cw_entity_fields:'+peid: u'surname-subject', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
199 |
'surname-subject:'+peid: u'Di Masci', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
200 |
|
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
201 |
'__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
|
202 |
'_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
|
203 |
'address-subject:'+emaileid: u'adim@logilab.fr', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
204 |
'use_email-object:'+emaileid: peid, |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
205 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
206 |
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
|
207 |
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
|
208 |
self.assertEqual(email.address, 'adim@logilab.fr') |
0 | 209 |
|
1426 | 210 |
|
0 | 211 |
def test_password_confirm(self): |
212 |
"""test creation of two linked entities |
|
1426 | 213 |
""" |
0 | 214 |
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
|
215 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
216 |
req.form = {'eid': 'X', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
217 |
'__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
|
218 |
'_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
|
219 |
'login-subject:X': u'toto', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
220 |
'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
|
221 |
} |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
222 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
223 |
self.ctrl_publish(req) |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
224 |
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
|
225 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
226 |
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
|
227 |
'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
|
228 |
'_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
|
229 |
'login-subject:X': u'toto', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
230 |
'upassword-subject:X': u'toto', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
231 |
'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
|
232 |
} |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
233 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
234 |
self.ctrl_publish(req) |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
235 |
self.assertEqual(cm.exception.errors, {'upassword-subject': u'password and confirmation don\'t match'}) |
0 | 236 |
|
237 |
||
238 |
def test_interval_bound_constraint_success(self): |
|
3587 | 239 |
feid = self.execute('INSERT File X: X data_name "toto.txt", X data %(data)s', |
0 | 240 |
{'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
|
241 |
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
|
242 |
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
|
243 |
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
|
244 |
'__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
|
245 |
'_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
|
246 |
'amount-subject:X': u'-10', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
247 |
'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
|
248 |
} |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
249 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
250 |
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
|
251 |
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
|
252 |
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
|
253 |
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
|
254 |
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
|
255 |
'__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
|
256 |
'_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
|
257 |
'amount-subject:X': u'110', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
258 |
'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
|
259 |
} |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
260 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
261 |
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
|
262 |
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
|
263 |
self.assertEqual(cm.exception.errors, {'amount-subject': 'value 110 must be <= 100'}) |
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
|
264 |
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
|
265 |
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
|
266 |
'__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
|
267 |
'_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
|
268 |
'amount-subject:X': u'10', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
269 |
'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
|
270 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
271 |
self.expect_redirect_handle_request(req, 'edit') |
1426 | 272 |
# should be redirected on the created |
0 | 273 |
#eid = params['rql'].split()[-1] |
274 |
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
|
275 |
self.assertEqual(e.amount, 10) |
0 | 276 |
|
277 |
def test_req_pending_insert(self): |
|
278 |
"""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
|
279 |
tmpgroup = self.request().create_entity('CWGroup', name=u"test") |
0 | 280 |
user = self.user() |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
281 |
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
|
282 |
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
|
283 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
0 | 284 |
usergroups = [gname for gname, in |
285 |
self.execute('Any N WHERE G name N, U in_group G, U eid %(u)s', {'u': user.eid})] |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
286 |
self.assertItemsEqual(usergroups, ['managers', 'test']) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
287 |
self.assertEqual(get_pending_inserts(req), []) |
0 | 288 |
|
289 |
||
290 |
def test_req_pending_delete(self): |
|
291 |
"""make sure req's pending deletions are taken into account""" |
|
292 |
user = self.user() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
293 |
groupeid = self.execute('INSERT CWGroup G: G name "test", U in_group G WHERE U eid %(x)s', |
0 | 294 |
{'x': user.eid})[0][0] |
295 |
usergroups = [gname for gname, in |
|
296 |
self.execute('Any N WHERE G name N, U in_group G, U eid %(u)s', {'u': user.eid})] |
|
297 |
# just make sure everything was set correctly |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
298 |
self.assertItemsEqual(usergroups, ['managers', 'test']) |
0 | 299 |
# now try to delete the relation |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
300 |
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
|
301 |
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
|
302 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
0 | 303 |
usergroups = [gname for gname, in |
304 |
self.execute('Any N WHERE G name N, U in_group G, U eid %(u)s', {'u': user.eid})] |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
305 |
self.assertItemsEqual(usergroups, ['managers']) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
306 |
self.assertEqual(get_pending_deletes(req), []) |
0 | 307 |
|
308 |
def test_redirect_apply_button(self): |
|
309 |
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
|
310 |
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
|
311 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
312 |
'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
|
313 |
'__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
|
314 |
'content-subject:A': u'"13:03:43"', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
315 |
'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
|
316 |
'__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
|
317 |
'__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
|
318 |
'__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
|
319 |
'__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
|
320 |
'__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
|
321 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
322 |
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
|
323 |
self.assertTrue(path.startswith('blogentry/')) |
0 | 324 |
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
|
325 |
self.assertEqual(params['vid'], 'edition') |
6412
370357e68837
[test] cleanup / unittest2 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
326 |
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
|
327 |
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
|
328 |
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
|
329 |
self.assertEqual(params['__redirectparams'], 'toto=tutu&tata=titi') |
0 | 330 |
|
331 |
def test_redirect_ok_button(self): |
|
332 |
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
|
333 |
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
|
334 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
335 |
'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
|
336 |
'__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
|
337 |
'content-subject:A': u'"13:03:43"', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
338 |
'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
|
339 |
'__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
|
340 |
'__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
|
341 |
'__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
|
342 |
'__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
|
343 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
344 |
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
|
345 |
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
|
346 |
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
|
347 |
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
|
348 |
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
|
349 |
self.assertEqual(params['toto'], 'tutu') |
0 | 350 |
|
351 |
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
|
352 |
req = self.request() |
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
353 |
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
|
354 |
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
|
355 |
'__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
|
356 |
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
|
357 |
self.assertEqual(path, 'blogentry') |
4918 | 358 |
self.assertIn('_cwmsgid', params) |
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
359 |
eid = req.create_entity('EmailAddress', address=u'hop@logilab.fr').eid |
0 | 360 |
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
|
361 |
{'x': self.session.user.eid, 'e': eid}) |
0 | 362 |
self.commit() |
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
363 |
req = req |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
364 |
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
|
365 |
'__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
|
366 |
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
|
367 |
self.assertEqual(path, 'cwuser/admin') |
4918 | 368 |
self.assertIn('_cwmsgid', params) |
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
369 |
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
|
370 |
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
|
371 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
372 |
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
|
373 |
'__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
|
374 |
'__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
|
375 |
'__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
|
376 |
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
|
377 |
self.assertEqual(path, 'view') |
4918 | 378 |
self.assertIn('_cwmsgid', params) |
0 | 379 |
|
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
|
380 |
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
|
381 |
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
|
382 |
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
|
383 |
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
|
384 |
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
|
385 |
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
|
386 |
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
|
387 |
'__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
|
388 |
'_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
|
389 |
'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
|
390 |
'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
|
391 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
392 |
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
|
393 |
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
|
394 |
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
|
395 |
|
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
|
396 |
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
|
397 |
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
|
398 |
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
|
399 |
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
|
400 |
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
|
401 |
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
|
402 |
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
|
403 |
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
|
404 |
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
|
405 |
'__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
|
406 |
'_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
|
407 |
'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
|
408 |
'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
|
409 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
410 |
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
|
411 |
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
|
412 |
# 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
|
413 |
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
|
414 |
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
|
415 |
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
|
416 |
|
0 | 417 |
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
|
418 |
"""non-regression test checking that a manager user can edit a CWEType entity |
0 | 419 |
""" |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
420 |
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
|
421 |
groups = [u(eid) for eid in groupeids] |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
422 |
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
|
423 |
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
|
424 |
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
|
425 |
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
|
426 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
427 |
'eid': cwetypeeid, |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
428 |
'__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
|
429 |
'_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
|
430 |
'name-subject:'+cwetypeeid: u'CWEType', |
4390 | 431 |
'final-subject:'+cwetypeeid: '', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
432 |
'description-subject:'+cwetypeeid: u'users group', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
433 |
'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
|
434 |
} |
0 | 435 |
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
|
436 |
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
|
437 |
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
|
438 |
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
|
439 |
self.assertEqual(sorted(g.eid for g in e.read_permission), groupeids) |
0 | 440 |
finally: |
441 |
# restore |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
442 |
self.execute('SET X read_permission Y WHERE X name "CWEType", Y eid IN (%s), NOT X read_permission Y' % (','.join(basegroups))) |
0 | 443 |
self.commit() |
1426 | 444 |
|
0 | 445 |
def test_nonregr_strange_text_input(self): |
446 |
"""non-regression test checking text input containing "13:03:43" |
|
447 |
||
448 |
this seems to be postgres (tsearch?) specific |
|
1426 | 449 |
""" |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
450 |
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
|
451 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
452 |
'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
|
453 |
'__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
|
454 |
'title-subject:A': u'"13:03:40"', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
455 |
'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
|
456 |
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
|
457 |
self.assertTrue(path.startswith('blogentry/')) |
0 | 458 |
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
|
459 |
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
|
460 |
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
|
461 |
self.assertEqual(e.content, '"13:03:43"') |
0 | 462 |
|
463 |
||
464 |
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
|
465 |
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
|
466 |
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
|
467 |
req.form = {'eid': ['X', 'Y'], |
1426 | 468 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
469 |
'__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
|
470 |
'_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
|
471 |
'login-subject:X': u'adim', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
472 |
'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
|
473 |
'in_group-subject:X': `gueid`, |
1426 | 474 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
475 |
'__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
|
476 |
'_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
|
477 |
'address-subject:Y': u'', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
478 |
'alias-subject:Y': u'', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
479 |
'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
|
480 |
} |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
481 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
482 |
self.ctrl_publish(req) |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
483 |
self.assertEqual(cm.exception.errors, {'address-subject': u'required field'}) |
0 | 484 |
|
485 |
def test_nonregr_copy(self): |
|
486 |
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
|
487 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
488 |
req.form = {'__maineid' : 'X', 'eid': 'X', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
489 |
'__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
|
490 |
'_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
|
491 |
'login-subject:X': u'toto', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
492 |
'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
|
493 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
494 |
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
|
495 |
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
|
496 |
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
|
497 |
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
|
498 |
self.assertEqual(e.in_group[0].name, 'managers') |
0 | 499 |
|
500 |
||
501 |
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
|
502 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6875
diff
changeset
|
503 |
p = self.create_user(req, "doe") |
0 | 504 |
# do not try to skip 'primary_email' for this test |
505 |
old_skips = p.__class__.skip_copy_for |
|
506 |
p.__class__.skip_copy_for = () |
|
507 |
try: |
|
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
508 |
e = self.request().create_entity('EmailAddress', address=u'doe@doe.com') |
0 | 509 |
self.execute('SET P use_email E, P primary_email E WHERE P eid %(p)s, E eid %(e)s', |
510 |
{'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
|
511 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
512 |
req.form = {'eid': 'X', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
513 |
'__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
|
514 |
'_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
|
515 |
'login-subject': u'dodo', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
516 |
'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
|
517 |
'__errorurl' : "whatever but required", |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
518 |
} |
0 | 519 |
# try to emulate what really happens in the web application |
520 |
# 1/ validate form => EditController.publish raises a ValidationError |
|
521 |
# which fires a Redirect |
|
522 |
# 2/ When re-publishing the copy form, the publisher implicitly commits |
|
523 |
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
|
524 |
self.app_handle_request(req, 'edit') |
0 | 525 |
except Redirect: |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
526 |
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
|
527 |
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
|
528 |
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
|
529 |
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
|
530 |
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
|
531 |
self.assertEqual(len(rset), 0) |
0 | 532 |
finally: |
533 |
p.__class__.skip_copy_for = old_skips |
|
534 |
||
535 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
536 |
class EmbedControllerTC(CubicWebTC): |
0 | 537 |
|
538 |
def test_nonregr_embed_publish(self): |
|
539 |
# This test looks a bit stupid but at least it will probably |
|
540 |
# fail if the controller API changes and if EmbedController is not |
|
541 |
# updated (which is what happened before this test) |
|
542 |
req = self.request() |
|
4824
b01973eff0f7
[test] don't use an internal url for test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4390
diff
changeset
|
543 |
req.form['url'] = 'http://www.logilab.fr/' |
2661
f8df42c9da6b
[vreg api update] remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2559
diff
changeset
|
544 |
controller = self.vreg['controllers'].select('embed', req) |
0 | 545 |
result = controller.publish(rset=None) |
546 |
||
547 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
548 |
class ReportBugControllerTC(CubicWebTC): |
0 | 549 |
|
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6875
diff
changeset
|
550 |
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
|
551 |
self.login('anon') |
4918 | 552 |
self.assertRaises(NoSelectableObject, |
553 |
self.vreg['controllers'].select, 'reportbug', self.request()) |
|
554 |
self.vreg['controllers'].select('reportbug', self.request(description='hop')) |
|
0 | 555 |
|
556 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
557 |
class SendMailControllerTC(CubicWebTC): |
0 | 558 |
|
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6875
diff
changeset
|
559 |
def test_not_usable_by_guest(self): |
4918 | 560 |
self.assertRaises(NoSelectableObject, |
561 |
self.vreg['controllers'].select, 'sendmail', self.request()) |
|
562 |
self.vreg['controllers'].select('sendmail', |
|
563 |
self.request(subject='toto', |
|
564 |
recipient='toto@logilab.fr', |
|
565 |
mailbody='hop')) |
|
0 | 566 |
self.login('anon') |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
567 |
self.assertRaises(NoSelectableObject, |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
568 |
self.vreg['controllers'].select, 'sendmail', self.request()) |
1426 | 569 |
|
0 | 570 |
|
571 |
||
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
572 |
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
|
573 |
tested_controller = 'ajax' |
0 | 574 |
|
575 |
def ctrl(self, req=None): |
|
576 |
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
|
577 |
return self.vreg['controllers'].select(self.tested_controller, req) |
0 | 578 |
|
579 |
def setup_database(self): |
|
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
580 |
req = self.request() |
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
581 |
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
|
582 |
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
|
583 |
self.john = self.create_user(req, u'John') |
0 | 584 |
|
585 |
||
586 |
## tests ################################################################## |
|
587 |
def test_simple_exec(self): |
|
1654 | 588 |
req = self.request(rql='CWUser P WHERE P login "John"', |
589 |
pageid='123', fname='view') |
|
590 |
ctrl = self.ctrl(req) |
|
591 |
rset = self.john.as_rset() |
|
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1654
diff
changeset
|
592 |
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
|
593 |
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
|
594 |
self.assertTrue(source.startswith('<?xml version="1.0"?>\n' + STRICT_DOCTYPE + |
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
|
595 |
u'<div xmlns="http://www.w3.org/1999/xhtml" xmlns:cubicweb="http://www.logilab.org/2008/cubicweb">') |
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
|
596 |
) |
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
|
597 |
req.xhtml_browser = lambda: False |
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
|
598 |
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
|
599 |
self.assertTrue(source.startswith('<div>')) |
0 | 600 |
|
1654 | 601 |
# def test_json_exec(self): |
602 |
# rql = 'Any T,N WHERE T is Tag, T name N' |
|
603 |
# 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
|
604 |
# self.assertEqual(ctrl.publish(), |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
605 |
# json_dumps(self.execute(rql).rows)) |
0 | 606 |
|
607 |
def test_remote_add_existing_tag(self): |
|
608 |
self.remote_call('tag_entity', self.john.eid, ['python']) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5941
diff
changeset
|
609 |
self.assertItemsEqual( |
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
|
610 |
[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
|
611 |
['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
|
612 |
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
|
613 |
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
|
614 |
[['python']]) |
1426 | 615 |
|
0 | 616 |
def test_remote_add_new_tag(self): |
617 |
self.remote_call('tag_entity', self.john.eid, ['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
|
618 |
self.assertItemsEqual( |
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
|
619 |
[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
|
620 |
['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
|
621 |
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
|
622 |
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
|
623 |
[['javascript']]) |
0 | 624 |
|
625 |
def test_pending_insertion(self): |
|
1654 | 626 |
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
|
627 |
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
|
628 |
self.assertEqual(deletes, []) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
629 |
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
|
630 |
self.assertEqual(inserts, ['12:tags:13']) |
1654 | 631 |
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
|
632 |
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
|
633 |
self.assertEqual(deletes, []) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
634 |
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
|
635 |
self.assertEqual(inserts, ['12:tags:13', '12:tags:14']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
636 |
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
|
637 |
self.assertEqual(inserts, ['12:tags:13', '12:tags:14']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
638 |
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
|
639 |
self.assertEqual(inserts, ['12:tags:13']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
640 |
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
|
641 |
self.assertEqual(inserts, ['12:tags:14']) |
0 | 642 |
req.remove_pending_operations() |
643 |
||
644 |
def test_pending_deletion(self): |
|
645 |
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
|
646 |
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
|
647 |
self.assertEqual(inserts, []) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
648 |
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
|
649 |
self.assertEqual(deletes, ['12:tags:13']) |
0 | 650 |
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
|
651 |
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
|
652 |
self.assertEqual(inserts, []) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
653 |
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
|
654 |
self.assertEqual(deletes, ['12:tags:13', '12:tags:14']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
655 |
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
|
656 |
self.assertEqual(deletes, ['12:tags:13', '12:tags:14']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
657 |
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
|
658 |
self.assertEqual(deletes, ['12:tags:13']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
659 |
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
|
660 |
self.assertEqual(deletes, ['12:tags:14']) |
0 | 661 |
req.remove_pending_operations() |
662 |
||
663 |
def test_remove_pending_operations(self): |
|
664 |
self.remote_call('add_pending_delete', ['12', 'tags', '13']) |
|
1654 | 665 |
_, 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
|
666 |
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
|
667 |
self.assertEqual(inserts, ['12:tags:14']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
668 |
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
|
669 |
self.assertEqual(deletes, ['12:tags:13']) |
0 | 670 |
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
|
671 |
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
|
672 |
self.assertEqual(get_pending_inserts(req), []) |
1426 | 673 |
|
0 | 674 |
|
675 |
def test_add_inserts(self): |
|
676 |
res, req = self.remote_call('add_pending_inserts', |
|
677 |
[('12', 'tags', '13'), ('12', 'tags', '14')]) |
|
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
678 |
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
|
679 |
self.assertEqual(inserts, ['12:tags:13', '12:tags:14']) |
0 | 680 |
req.remove_pending_operations() |
1426 | 681 |
|
0 | 682 |
|
683 |
# silly tests |
|
684 |
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
|
685 |
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
|
686 |
json_dumps(self.config.uiprops['RSS_LOGO'])) |
0 | 687 |
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
|
688 |
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
|
689 |
json_dumps(['bimboom'])) |
0 | 690 |
|
691 |
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
|
692 |
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
|
693 |
json_dumps('2007/01/01')) |
0 | 694 |
|
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
695 |
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
|
696 |
@ajaxfunc |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
697 |
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
|
698 |
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
|
699 |
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
|
700 |
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
|
701 |
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
|
702 |
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
|
703 |
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
|
704 |
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
|
705 |
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
|
706 |
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
|
707 |
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
|
708 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
709 |
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
|
710 |
@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
|
711 |
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
|
712 |
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
|
713 |
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
|
714 |
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
|
715 |
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
|
716 |
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
|
717 |
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
|
718 |
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
|
719 |
# 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
|
720 |
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
|
721 |
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
|
722 |
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
|
723 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
724 |
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
|
725 |
@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
|
726 |
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
|
727 |
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
|
728 |
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
|
729 |
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
|
730 |
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
|
731 |
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
|
732 |
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
|
733 |
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
|
734 |
# 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
|
735 |
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
|
736 |
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
|
737 |
self.assertEqual(f(12, 13), '25') |
1426 | 738 |
|
0 | 739 |
|
8128
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
740 |
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
|
741 |
# 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
|
742 |
# 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
|
743 |
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
|
744 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
745 |
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
|
746 |
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
|
747 |
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
|
748 |
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
|
749 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
750 |
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
|
751 |
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
|
752 |
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
|
753 |
# 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
|
754 |
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
|
755 |
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
|
756 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
757 |
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
|
758 |
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
|
759 |
@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
|
760 |
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
|
761 |
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
|
762 |
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
|
763 |
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
|
764 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
765 |
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
|
766 |
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
|
767 |
@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
|
768 |
@xhtmlize |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
769 |
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
|
770 |
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
|
771 |
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
|
772 |
self.assertEqual(res, |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
773 |
'<?xml version="1.0"?>\n' + STRICT_DOCTYPE + |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
774 |
u'<div xmlns="http://www.w3.org/1999/xhtml" xmlns:cubicweb="http://www.logilab.org/2008/cubicweb">hello</div>') |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
775 |
|
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
776 |
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
|
777 |
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
|
778 |
@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
|
779 |
@jsonize |
0a927fe4541b
[controllers] deprecate JSonController and implement AjaxController / ajax-func registry (closes #2110265)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
780 |
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
|
781 |
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
|
782 |
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
|
783 |
self.assertEqual(res, '12') |
1426 | 784 |
|
8504
f21c72928662
[ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8487
diff
changeset
|
785 |
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
|
786 |
@monkeypatch(JSonController) |
f21c72928662
[ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8487
diff
changeset
|
787 |
@jsonize |
f21c72928662
[ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8487
diff
changeset
|
788 |
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
|
789 |
return 12 |
f21c72928662
[ajax] improve backward compatibility for redefined ajax functions (closes #2447189)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8487
diff
changeset
|
790 |
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
|
791 |
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
|
792 |
|
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
|
793 |
|
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
|
794 |
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
|
795 |
|
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
|
796 |
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
|
797 |
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
|
798 |
self.session.undo_actions = True |
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
|
799 |
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
|
800 |
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
|
801 |
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
|
802 |
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
|
803 |
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
|
804 |
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
|
805 |
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
|
806 |
|
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
|
807 |
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
|
808 |
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
|
809 |
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
|
810 |
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
|
811 |
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
|
812 |
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
|
813 |
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
|
814 |
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
|
815 |
|
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
|
816 |
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
|
817 |
""" 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
|
818 |
|
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
|
819 |
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
|
820 |
""" |
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
|
821 |
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
|
822 |
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
|
823 |
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
|
824 |
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
|
825 |
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
|
826 |
|
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
|
827 |
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
|
828 |
"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
|
829 |
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
|
830 |
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
|
831 |
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
|
832 |
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
|
833 |
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
|
834 |
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
|
835 |
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
|
836 |
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
|
837 |
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
|
838 |
|
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
|
839 |
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
|
840 |
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
|
841 |
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
|
842 |
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
|
843 |
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
|
844 |
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
|
845 |
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
|
846 |
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
|
847 |
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
|
848 |
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
|
849 |
|
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
|
850 |
|
8311
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8267
diff
changeset
|
851 |
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
|
852 |
|
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8267
diff
changeset
|
853 |
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
|
854 |
req = self.request() |
8487
017af22e7678
[web test] fix tests broken by 8de41063d629
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8444
diff
changeset
|
855 |
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
|
856 |
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
|
857 |
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
|
858 |
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
|
859 |
|
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8267
diff
changeset
|
860 |
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
|
861 |
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
|
862 |
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
|
863 |
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
|
864 |
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
|
865 |
|
0 | 866 |
if __name__ == '__main__': |
867 |
unittest_main() |