author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 26 Mar 2010 08:28:22 +0100 | |
branch | stable |
changeset 5030 | 5238d9a8dfee |
parent 4918 | 520e7fb542cf |
child 5038 | 90493551b1eb |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1901
diff
changeset
|
1 |
"""cubicweb.web.views.basecontrollers unit tests |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1901
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1901
diff
changeset
|
3 |
:organization: Logilab |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3772
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1901
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1901
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1901
diff
changeset
|
7 |
""" |
0 | 8 |
import simplejson |
9 |
||
1899
361774742f3e
[test] fix test after xhml_wrap changed signature
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1797
diff
changeset
|
10 |
from logilab.common.testlib import unittest_main, mock_object |
0 | 11 |
|
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
|
12 |
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
|
13 |
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
|
14 |
from cubicweb.devtools.testlib import CubicWebTC |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
15 |
from cubicweb.uilib import rql_for_eid |
0 | 16 |
from cubicweb.web import INTERNAL_FIELD_VALUE, Redirect, RequestError |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
17 |
from cubicweb.entities.authobjs import CWUser |
4390 | 18 |
from cubicweb.web.views.autoform import get_pending_inserts, get_pending_deletes |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
19 |
u = unicode |
0 | 20 |
|
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
21 |
def req_form(user): |
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
22 |
return {'eid': [str(user.eid)], |
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
23 |
'_cw_edited_fields:%s' % user.eid: '_cw_generic_field', |
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
24 |
'__type:%s' % user.eid: user.__regid__ |
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
25 |
} |
0 | 26 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
27 |
class EditControllerTC(CubicWebTC): |
0 | 28 |
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
|
29 |
CubicWebTC.setUp(self) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
30 |
self.failUnless('users' in self.schema.eschema('CWGroup').get_groups('read')) |
1426 | 31 |
|
0 | 32 |
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
|
33 |
CubicWebTC.tearDown(self) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
34 |
self.failUnless('users' in self.schema.eschema('CWGroup').get_groups('read')) |
1426 | 35 |
|
0 | 36 |
def test_noparam_edit(self): |
37 |
"""check behaviour of this controller without any form parameter |
|
38 |
""" |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
39 |
ex = self.assertRaises(ValidationError, self.ctrl_publish, self.request()) |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
40 |
self.assertEquals(ex.errors, {None: u'no selected entities'}) |
1426 | 41 |
|
0 | 42 |
def test_validation_unique(self): |
43 |
"""test creation of two linked entities |
|
1426 | 44 |
""" |
0 | 45 |
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
|
46 |
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
|
47 |
req.form = {'eid': 'X', '__type:X': 'CWUser', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
48 |
'_cw_edited_fields:X': 'login-subject,upassword-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
49 |
'login-subject:X': u'admin', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
50 |
'upassword-subject:X': u'toto', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
51 |
'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
|
52 |
} |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
53 |
ex = self.assertRaises(ValidationError, self.ctrl_publish, req) |
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4918
diff
changeset
|
54 |
self.assertEquals(ex.errors, {'login-subject': 'the value "admin" is already used, use another one'}) |
0 | 55 |
|
56 |
def test_user_editing_itself(self): |
|
57 |
"""checking that a manager user can edit itself |
|
58 |
""" |
|
59 |
user = self.user() |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
64 |
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
|
65 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
66 |
'eid': eid, '__type:'+eid: 'CWUser', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
67 |
'_cw_edited_fields:'+eid: 'login-subject,firstname-subject,surname-subject,in_group-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
68 |
'login-subject:'+eid: u(user.login), |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
69 |
'surname-subject:'+eid: u'Th\xe9nault', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
70 |
'firstname-subject:'+eid: u'Sylvain', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
71 |
'in_group-subject:'+eid: groups, |
0 | 72 |
} |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
73 |
path, params = self.expect_redirect_publish(req, 'edit') |
0 | 74 |
e = self.execute('Any X WHERE X eid %(x)s', {'x': user.eid}, 'x').get_entity(0, 0) |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
75 |
self.assertEquals(e.firstname, u'Sylvain') |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
76 |
self.assertEquals(e.surname, u'Th\xe9nault') |
0 | 77 |
self.assertEquals(e.login, user.login) |
78 |
self.assertEquals([g.eid for g in e.in_group], groupeids) |
|
79 |
||
80 |
def test_user_can_change_its_password(self): |
|
81 |
user = self.create_user('user') |
|
82 |
cnx = self.login('user') |
|
83 |
req = self.request() |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
84 |
eid = u(user.eid) |
0 | 85 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
86 |
'eid': eid, '__maineid' : eid, |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
87 |
'__type:'+eid: 'CWUser', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
88 |
'_cw_edited_fields:'+eid: 'upassword-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
89 |
'upassword-subject:'+eid: 'tournicoton', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
90 |
'upassword-subject-confirm:'+eid: 'tournicoton', |
0 | 91 |
} |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
92 |
path, params = self.expect_redirect_publish(req, 'edit') |
0 | 93 |
cnx.commit() # commit to check we don't get late validation error for instance |
1654 | 94 |
self.assertEquals(path, 'cwuser/user') |
0 | 95 |
self.failIf('vid' in params) |
96 |
||
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
97 |
def test_user_editing_itself_no_relation(self): |
0 | 98 |
"""checking we can edit an entity without specifying some required |
99 |
relations (meaning no changes) |
|
100 |
""" |
|
101 |
user = self.user() |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
102 |
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
|
103 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
104 |
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
|
105 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
106 |
'eid': eid, |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
107 |
'__type:'+eid: 'CWUser', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
108 |
'_cw_edited_fields:'+eid: 'login-subject,firstname-subject,surname-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
109 |
'login-subject:'+eid: u(user.login), |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
110 |
'firstname-subject:'+eid: u'Th\xe9nault', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
111 |
'surname-subject:'+eid: u'Sylvain', |
0 | 112 |
} |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
113 |
path, params = self.expect_redirect_publish(req, 'edit') |
0 | 114 |
e = self.execute('Any X WHERE X eid %(x)s', {'x': user.eid}, 'x').get_entity(0, 0) |
115 |
self.assertEquals(e.login, user.login) |
|
116 |
self.assertEquals(e.firstname, u'Th\xe9nault') |
|
117 |
self.assertEquals(e.surname, u'Sylvain') |
|
118 |
self.assertEquals([g.eid for g in e.in_group], groupeids) |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
119 |
self.assertEquals(e.state, 'activated') |
1426 | 120 |
|
121 |
||
0 | 122 |
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
|
123 |
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
|
124 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
125 |
req.form = {'eid': ['X', 'Y'], '__maineid' : 'X', |
0 | 126 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
127 |
'__type:X': 'CWUser', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
128 |
'_cw_edited_fields:X': 'login-subject,upassword-subject,surname-subject,in_group-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
129 |
'login-subject:X': u'adim', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
130 |
'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
|
131 |
'surname-subject:X': u'Di Mascio', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
132 |
'in_group-subject:X': u(gueid), |
1426 | 133 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
134 |
'__type:Y': 'EmailAddress', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
135 |
'_cw_edited_fields:Y': 'address-subject,use_email-object', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
136 |
'address-subject:Y': u'dima@logilab.fr', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
137 |
'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
|
138 |
} |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
139 |
path, params = self.expect_redirect_publish(req, 'edit') |
0 | 140 |
# should be redirected on the created person |
1654 | 141 |
self.assertEquals(path, 'cwuser/adim') |
0 | 142 |
e = self.execute('Any P WHERE P surname "Di Mascio"').get_entity(0, 0) |
143 |
self.assertEquals(e.surname, 'Di Mascio') |
|
144 |
email = e.use_email[0] |
|
145 |
self.assertEquals(email.address, 'dima@logilab.fr') |
|
1426 | 146 |
|
0 | 147 |
def test_edit_multiple_linked(self): |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
148 |
peid = u(self.create_user('adim').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
|
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': [peid, 'Y'], '__maineid': peid, |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
151 |
|
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
152 |
'__type:'+peid: u'CWUser', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
153 |
'_cw_edited_fields:'+peid: u'surname-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
154 |
'surname-subject:'+peid: u'Di Masci', |
1426 | 155 |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
156 |
'__type:Y': u'EmailAddress', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
157 |
'_cw_edited_fields:Y': u'address-subject,use_email-object', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
158 |
'address-subject:Y': u'dima@logilab.fr', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
159 |
'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
|
160 |
} |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
161 |
path, params = self.expect_redirect_publish(req, 'edit') |
0 | 162 |
# should be redirected on the created person |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
163 |
self.assertEquals(path, 'cwuser/adim') |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
164 |
e = self.execute('Any P WHERE P surname "Di Masci"').get_entity(0, 0) |
0 | 165 |
email = e.use_email[0] |
166 |
self.assertEquals(email.address, 'dima@logilab.fr') |
|
1426 | 167 |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
168 |
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
|
169 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
170 |
req.form = {'eid': [peid, emaileid], |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
171 |
|
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
172 |
'__type:'+peid: u'CWUser', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
173 |
'_cw_edited_fields:'+peid: u'surname-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
174 |
'surname-subject:'+peid: u'Di Masci', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
175 |
|
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
176 |
'__type:'+emaileid: u'EmailAddress', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
177 |
'_cw_edited_fields:'+emaileid: u'address-subject,use_email-object', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
178 |
'address-subject:'+emaileid: u'adim@logilab.fr', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
179 |
'use_email-object:'+emaileid: peid, |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
180 |
} |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
181 |
path, params = self.expect_redirect_publish(req, 'edit') |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
182 |
email.clear_all_caches() |
0 | 183 |
self.assertEquals(email.address, 'adim@logilab.fr') |
184 |
||
1426 | 185 |
|
0 | 186 |
def test_password_confirm(self): |
187 |
"""test creation of two linked entities |
|
1426 | 188 |
""" |
0 | 189 |
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
|
190 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
191 |
req.form = {'eid': 'X', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
192 |
'__cloned_eid:X': u(user.eid), '__type:X': 'CWUser', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
193 |
'_cw_edited_fields:X': 'login-subject,upassword-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
194 |
'login-subject:X': u'toto', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
195 |
'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
|
196 |
} |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
197 |
ex = self.assertRaises(ValidationError, self.ctrl_publish, req) |
4266 | 198 |
self.assertEquals(ex.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
|
199 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
200 |
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
|
201 |
'eid': 'X', '__type:X': 'CWUser', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
202 |
'_cw_edited_fields:X': 'login-subject,upassword-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
203 |
'login-subject:X': u'toto', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
204 |
'upassword-subject:X': u'toto', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
205 |
'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
|
206 |
} |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
207 |
ex = self.assertRaises(ValidationError, self.ctrl_publish, req) |
4266 | 208 |
self.assertEquals(ex.errors, {'upassword-subject': u'password and confirmation don\'t match'}) |
0 | 209 |
|
210 |
||
211 |
def test_interval_bound_constraint_success(self): |
|
3587 | 212 |
feid = self.execute('INSERT File X: X data_name "toto.txt", X data %(data)s', |
0 | 213 |
{'data': Binary('yo')})[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
|
214 |
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
|
215 |
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
|
216 |
'__type:X': 'Salesterm', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
217 |
'_cw_edited_fields:X': 'amount-subject,described_by_test-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
218 |
'amount-subject:X': u'-10', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
219 |
'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
|
220 |
} |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
221 |
ex = self.assertRaises(ValidationError, self.ctrl_publish, req) |
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4918
diff
changeset
|
222 |
self.assertEquals(ex.errors, {'amount-subject': 'value [0;100] constraint failed for value -10'}) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
223 |
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
|
224 |
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
|
225 |
'__type:X': 'Salesterm', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
226 |
'_cw_edited_fields:X': 'amount-subject,described_by_test-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
227 |
'amount-subject:X': u'110', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
228 |
'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
|
229 |
} |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
230 |
ex = self.assertRaises(ValidationError, self.ctrl_publish, req) |
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4918
diff
changeset
|
231 |
self.assertEquals(ex.errors, {'amount-subject': 'value [0;100] constraint failed for value 110'}) |
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 |
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
|
233 |
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
|
234 |
'__type:X': 'Salesterm', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
235 |
'_cw_edited_fields:X': 'amount-subject,described_by_test-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
236 |
'amount-subject:X': u'10', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
237 |
'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
|
238 |
} |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
239 |
self.expect_redirect_publish(req, 'edit') |
1426 | 240 |
# should be redirected on the created |
0 | 241 |
#eid = params['rql'].split()[-1] |
242 |
e = self.execute('Salesterm X').get_entity(0, 0) |
|
243 |
self.assertEquals(e.amount, 10) |
|
244 |
||
245 |
def test_req_pending_insert(self): |
|
246 |
"""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
|
247 |
tmpgroup = self.request().create_entity('CWGroup', name=u"test") |
0 | 248 |
user = self.user() |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
249 |
req = self.request(**req_form(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
|
250 |
req.set_session_data('pending_insert', set([(user.eid, 'in_group', tmpgroup.eid)])) |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
251 |
path, params = self.expect_redirect_publish(req, 'edit') |
0 | 252 |
usergroups = [gname for gname, in |
253 |
self.execute('Any N WHERE G name N, U in_group G, U eid %(u)s', {'u': user.eid})] |
|
254 |
self.assertUnorderedIterableEquals(usergroups, ['managers', 'test']) |
|
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
255 |
self.assertEquals(get_pending_inserts(req), []) |
0 | 256 |
|
257 |
||
258 |
def test_req_pending_delete(self): |
|
259 |
"""make sure req's pending deletions are taken into account""" |
|
260 |
user = self.user() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
261 |
groupeid = self.execute('INSERT CWGroup G: G name "test", U in_group G WHERE U eid %(x)s', |
0 | 262 |
{'x': user.eid})[0][0] |
263 |
usergroups = [gname for gname, in |
|
264 |
self.execute('Any N WHERE G name N, U in_group G, U eid %(u)s', {'u': user.eid})] |
|
265 |
# just make sure everything was set correctly |
|
266 |
self.assertUnorderedIterableEquals(usergroups, ['managers', 'test']) |
|
267 |
# now try to delete the relation |
|
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
268 |
req = self.request(**req_form(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
|
269 |
req.set_session_data('pending_delete', set([(user.eid, 'in_group', groupeid)])) |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
270 |
path, params = self.expect_redirect_publish(req, 'edit') |
0 | 271 |
usergroups = [gname for gname, in |
272 |
self.execute('Any N WHERE G name N, U in_group G, U eid %(u)s', {'u': user.eid})] |
|
273 |
self.assertUnorderedIterableEquals(usergroups, ['managers']) |
|
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
274 |
self.assertEquals(get_pending_deletes(req), []) |
0 | 275 |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
276 |
# def test_custom_attribute_handler(self): |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
277 |
# def custom_login_edit(self, formparams, value, relations): |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
278 |
# formparams['login'] = value.upper() |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
279 |
# relations.append('X login %(login)s') |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
280 |
# CWUser.custom_login_edit = custom_login_edit |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
281 |
# try: |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
282 |
# user = self.user() |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
283 |
# eid = repr(user.eid) |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
284 |
# req = self.request() |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
285 |
# req.form = { |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
286 |
# 'eid': eid, |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
287 |
# '__type:'+eid: 'CWUser', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
288 |
# 'login:'+eid: u'foo', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
289 |
# } |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
290 |
# path, params = self.expect_redirect_publish(req, 'edit') |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
291 |
# rset = self.execute('Any L WHERE X eid %(x)s, X login L', {'x': user.eid}, 'x') |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
292 |
# self.assertEquals(rset[0][0], 'FOO') |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
293 |
# finally: |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
294 |
# del CWUser.custom_login_edit |
1426 | 295 |
|
0 | 296 |
def test_redirect_apply_button(self): |
297 |
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
|
298 |
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
|
299 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
300 |
'eid': 'A', '__maineid' : 'A', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
301 |
'__type:A': 'BlogEntry', '_cw_edited_fields:A': 'content-subject,title-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
302 |
'content-subject:A': u'"13:03:43"', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
303 |
'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
|
304 |
'__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
|
305 |
'__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
|
306 |
'__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
|
307 |
'__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
|
308 |
'__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
|
309 |
} |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
310 |
path, params = self.expect_redirect_publish(req, 'edit') |
0 | 311 |
self.failUnless(path.startswith('blogentry/')) |
312 |
eid = path.split('/')[1] |
|
313 |
self.assertEquals(params['vid'], 'edition') |
|
314 |
self.assertNotEquals(int(eid), 4012) |
|
315 |
self.assertEquals(params['__redirectrql'], redirectrql) |
|
316 |
self.assertEquals(params['__redirectvid'], 'primary') |
|
317 |
self.assertEquals(params['__redirectparams'], 'toto=tutu&tata=titi') |
|
318 |
||
319 |
def test_redirect_ok_button(self): |
|
320 |
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
|
321 |
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
|
322 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
323 |
'eid': 'A', '__maineid' : 'A', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
324 |
'__type:A': 'BlogEntry', '_cw_edited_fields:A': 'content-subject,title-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
325 |
'content-subject:A': u'"13:03:43"', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
326 |
'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
|
327 |
'__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
|
328 |
'__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
|
329 |
'__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
|
330 |
'__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
|
331 |
} |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
332 |
path, params = self.expect_redirect_publish(req, 'edit') |
0 | 333 |
self.assertEquals(path, 'view') |
334 |
self.assertEquals(params['rql'], redirectrql) |
|
335 |
self.assertEquals(params['vid'], 'primary') |
|
336 |
self.assertEquals(params['tata'], 'titi') |
|
337 |
self.assertEquals(params['toto'], 'tutu') |
|
338 |
||
339 |
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
|
340 |
req = self.request() |
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
341 |
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
|
342 |
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
|
343 |
'__action_delete': ''} |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
344 |
path, params = self.expect_redirect_publish(req, 'edit') |
0 | 345 |
self.assertEquals(path, 'blogentry') |
4918 | 346 |
self.assertIn('_cwmsgid', params) |
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
347 |
eid = req.create_entity('EmailAddress', address=u'hop@logilab.fr').eid |
0 | 348 |
self.execute('SET X use_email E WHERE E eid %(e)s, X eid %(x)s', |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
349 |
{'x': self.session.user.eid, 'e': eid}, 'x') |
0 | 350 |
self.commit() |
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
351 |
req = req |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
352 |
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
|
353 |
'__action_delete': ''} |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
354 |
path, params = self.expect_redirect_publish(req, 'edit') |
1654 | 355 |
self.assertEquals(path, 'cwuser/admin') |
4918 | 356 |
self.assertIn('_cwmsgid', params) |
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
357 |
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
|
358 |
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
|
359 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
360 |
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
|
361 |
'__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
|
362 |
'__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
|
363 |
'__action_delete': ''} |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
364 |
path, params = self.expect_redirect_publish(req, 'edit') |
0 | 365 |
self.assertEquals(path, 'view') |
4918 | 366 |
self.assertIn('_cwmsgid', params) |
0 | 367 |
|
368 |
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
|
369 |
"""non-regression test checking that a manager user can edit a CWEType entity |
0 | 370 |
""" |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
371 |
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
|
372 |
groups = [u(eid) for eid in groupeids] |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
373 |
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
|
374 |
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
|
375 |
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
|
376 |
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
|
377 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
378 |
'eid': cwetypeeid, |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
379 |
'__type:'+cwetypeeid: 'CWEType', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
380 |
'_cw_edited_fields:'+cwetypeeid: 'name-subject,final-subject,description-subject,read_permission-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
381 |
'name-subject:'+cwetypeeid: u'CWEType', |
4390 | 382 |
'final-subject:'+cwetypeeid: '', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
383 |
'description-subject:'+cwetypeeid: u'users group', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
384 |
'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
|
385 |
} |
0 | 386 |
try: |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
387 |
path, params = self.expect_redirect_publish(req, 'edit') |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
388 |
e = self.execute('Any X WHERE X eid %(x)s', {'x': cwetypeeid}, 'x').get_entity(0, 0) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
389 |
self.assertEquals(e.name, 'CWEType') |
0 | 390 |
self.assertEquals(sorted(g.eid for g in e.read_permission), groupeids) |
391 |
finally: |
|
392 |
# restore |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
393 |
self.execute('SET X read_permission Y WHERE X name "CWEType", Y eid IN (%s), NOT X read_permission Y' % (','.join(basegroups))) |
0 | 394 |
self.commit() |
1426 | 395 |
|
0 | 396 |
def test_nonregr_strange_text_input(self): |
397 |
"""non-regression test checking text input containing "13:03:43" |
|
398 |
||
399 |
this seems to be postgres (tsearch?) specific |
|
1426 | 400 |
""" |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
401 |
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
|
402 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
403 |
'eid': 'A', '__maineid' : 'A', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
404 |
'__type:A': 'BlogEntry', '_cw_edited_fields:A': 'title-subject,content-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
405 |
'title-subject:A': u'"13:03:40"', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
406 |
'content-subject:A': u'"13:03:43"',} |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
407 |
path, params = self.expect_redirect_publish(req, 'edit') |
0 | 408 |
self.failUnless(path.startswith('blogentry/')) |
409 |
eid = path.split('/')[1] |
|
410 |
e = self.execute('Any C, T WHERE C eid %(x)s, C content T', {'x': eid}, 'x').get_entity(0, 0) |
|
411 |
self.assertEquals(e.title, '"13:03:40"') |
|
412 |
self.assertEquals(e.content, '"13:03:43"') |
|
413 |
||
414 |
||
415 |
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
|
416 |
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
|
417 |
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
|
418 |
req.form = {'eid': ['X', 'Y'], |
1426 | 419 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
420 |
'__type:X': 'CWUser', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
421 |
'_cw_edited_fields:X': 'login-subject,upassword-subject,in_group-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
422 |
'login-subject:X': u'adim', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
423 |
'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
|
424 |
'in_group-subject:X': `gueid`, |
1426 | 425 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
426 |
'__type:Y': 'EmailAddress', |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
427 |
'_cw_edited_fields:Y': 'address-subject,alias-subject,use_email-object', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
428 |
'address-subject:Y': u'', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
429 |
'alias-subject:Y': u'', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
430 |
'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
|
431 |
} |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
432 |
ex = self.assertRaises(ValidationError, self.ctrl_publish, req) |
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4918
diff
changeset
|
433 |
self.assertEquals(ex.errors, {'address-subject': u'required attribute'}) |
0 | 434 |
|
435 |
def test_nonregr_copy(self): |
|
436 |
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
|
437 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
438 |
req.form = {'__maineid' : 'X', 'eid': 'X', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
439 |
'__cloned_eid:X': user.eid, '__type:X': 'CWUser', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
440 |
'_cw_edited_fields:X': 'login-subject,upassword-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
441 |
'login-subject:X': u'toto', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
442 |
'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
|
443 |
} |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
444 |
path, params = self.expect_redirect_publish(req, 'edit') |
1654 | 445 |
self.assertEquals(path, 'cwuser/toto') |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
446 |
e = self.execute('Any X WHERE X is CWUser, X login "toto"').get_entity(0, 0) |
0 | 447 |
self.assertEquals(e.login, 'toto') |
448 |
self.assertEquals(e.in_group[0].name, 'managers') |
|
449 |
||
450 |
||
451 |
def test_nonregr_rollback_on_validation_error(self): |
|
452 |
p = self.create_user("doe") |
|
453 |
# do not try to skip 'primary_email' for this test |
|
454 |
old_skips = p.__class__.skip_copy_for |
|
455 |
p.__class__.skip_copy_for = () |
|
456 |
try: |
|
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
457 |
e = self.request().create_entity('EmailAddress', address=u'doe@doe.com') |
0 | 458 |
self.execute('SET P use_email E, P primary_email E WHERE P eid %(p)s, E eid %(e)s', |
459 |
{'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
|
460 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
461 |
req.form = {'eid': 'X', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
462 |
'__cloned_eid:X': p.eid, '__type:X': 'CWUser', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
463 |
'_cw_edited_fields:X': 'login-subject,surname-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
464 |
'login-subject': u'dodo', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
465 |
'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
|
466 |
'__errorurl' : "whatever but required", |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
467 |
} |
0 | 468 |
# try to emulate what really happens in the web application |
469 |
# 1/ validate form => EditController.publish raises a ValidationError |
|
470 |
# which fires a Redirect |
|
471 |
# 2/ When re-publishing the copy form, the publisher implicitly commits |
|
472 |
try: |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
473 |
self.app_publish(req, 'edit') |
0 | 474 |
except Redirect: |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
475 |
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
|
476 |
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
|
477 |
req.form['vid'] = 'copy' |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4083
diff
changeset
|
478 |
self.app_publish(req, 'view') |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
479 |
rset = self.execute('CWUser P WHERE P surname "Boom"') |
0 | 480 |
self.assertEquals(len(rset), 0) |
481 |
finally: |
|
482 |
p.__class__.skip_copy_for = old_skips |
|
483 |
||
484 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
485 |
class EmbedControllerTC(CubicWebTC): |
0 | 486 |
|
487 |
def test_nonregr_embed_publish(self): |
|
488 |
# This test looks a bit stupid but at least it will probably |
|
489 |
# fail if the controller API changes and if EmbedController is not |
|
490 |
# updated (which is what happened before this test) |
|
491 |
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
|
492 |
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
|
493 |
controller = self.vreg['controllers'].select('embed', req) |
0 | 494 |
result = controller.publish(rset=None) |
495 |
||
496 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
497 |
class ReportBugControllerTC(CubicWebTC): |
0 | 498 |
|
499 |
def test_usable_by_guets(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
|
500 |
self.login('anon') |
4918 | 501 |
self.assertRaises(NoSelectableObject, |
502 |
self.vreg['controllers'].select, 'reportbug', self.request()) |
|
503 |
self.vreg['controllers'].select('reportbug', self.request(description='hop')) |
|
0 | 504 |
|
505 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
506 |
class SendMailControllerTC(CubicWebTC): |
0 | 507 |
|
508 |
def test_not_usable_by_guets(self): |
|
4918 | 509 |
self.assertRaises(NoSelectableObject, |
510 |
self.vreg['controllers'].select, 'sendmail', self.request()) |
|
511 |
self.vreg['controllers'].select('sendmail', |
|
512 |
self.request(subject='toto', |
|
513 |
recipient='toto@logilab.fr', |
|
514 |
mailbody='hop')) |
|
0 | 515 |
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
|
516 |
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
|
517 |
self.vreg['controllers'].select, 'sendmail', self.request()) |
1426 | 518 |
|
0 | 519 |
|
520 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
521 |
class JSONControllerTC(CubicWebTC): |
0 | 522 |
|
523 |
def ctrl(self, req=None): |
|
524 |
req = req or self.request(url='http://whatever.fr/') |
|
2661
f8df42c9da6b
[vreg api update] remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2559
diff
changeset
|
525 |
return self.vreg['controllers'].select('json', req) |
0 | 526 |
|
527 |
def setup_database(self): |
|
4083
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
528 |
req = self.request() |
3b285889b8e9
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
529 |
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
|
530 |
self.cubicwebtag = req.create_entity('Tag', name=u'cubicweb') |
0 | 531 |
self.john = self.create_user(u'John') |
532 |
||
533 |
||
534 |
## tests ################################################################## |
|
535 |
def test_simple_exec(self): |
|
1654 | 536 |
req = self.request(rql='CWUser P WHERE P login "John"', |
537 |
pageid='123', fname='view') |
|
538 |
ctrl = self.ctrl(req) |
|
539 |
rset = self.john.as_rset() |
|
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1654
diff
changeset
|
540 |
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
|
541 |
source = ctrl.publish() |
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
|
542 |
self.failUnless(source.startswith('<?xml version="1.0"?>\n' + STRICT_DOCTYPE + |
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
|
543 |
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
|
544 |
) |
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
|
545 |
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
|
546 |
source = ctrl.publish() |
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
|
547 |
self.failUnless(source.startswith('<div>')) |
0 | 548 |
|
1654 | 549 |
# def test_json_exec(self): |
550 |
# rql = 'Any T,N WHERE T is Tag, T name N' |
|
551 |
# ctrl = self.ctrl(self.request(mode='json', rql=rql, pageid='123')) |
|
552 |
# self.assertEquals(ctrl.publish(), |
|
553 |
# simplejson.dumps(self.execute(rql).rows)) |
|
0 | 554 |
|
555 |
def test_remote_add_existing_tag(self): |
|
556 |
self.remote_call('tag_entity', self.john.eid, ['python']) |
|
557 |
self.assertUnorderedIterableEquals([tname for tname, in self.execute('Any N WHERE T is Tag, T name N')], |
|
558 |
['python', 'cubicweb']) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
559 |
self.assertEquals(self.execute('Any N WHERE T tags P, P is CWUser, T name N').rows, |
0 | 560 |
[['python']]) |
1426 | 561 |
|
0 | 562 |
def test_remote_add_new_tag(self): |
563 |
self.remote_call('tag_entity', self.john.eid, ['javascript']) |
|
564 |
self.assertUnorderedIterableEquals([tname for tname, in self.execute('Any N WHERE T is Tag, T name N')], |
|
565 |
['python', 'cubicweb', 'javascript']) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
566 |
self.assertEquals(self.execute('Any N WHERE T tags P, P is CWUser, T name N').rows, |
0 | 567 |
[['javascript']]) |
568 |
||
569 |
def test_pending_insertion(self): |
|
1654 | 570 |
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
|
571 |
deletes = get_pending_deletes(req) |
0 | 572 |
self.assertEquals(deletes, []) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
573 |
inserts = get_pending_inserts(req) |
0 | 574 |
self.assertEquals(inserts, ['12:tags:13']) |
1654 | 575 |
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
|
576 |
deletes = get_pending_deletes(req) |
0 | 577 |
self.assertEquals(deletes, []) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
578 |
inserts = get_pending_inserts(req) |
0 | 579 |
self.assertEquals(inserts, ['12:tags:13', '12:tags:14']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
580 |
inserts = get_pending_inserts(req, 12) |
0 | 581 |
self.assertEquals(inserts, ['12:tags:13', '12:tags:14']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
582 |
inserts = get_pending_inserts(req, 13) |
0 | 583 |
self.assertEquals(inserts, ['12:tags:13']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
584 |
inserts = get_pending_inserts(req, 14) |
0 | 585 |
self.assertEquals(inserts, ['12:tags:14']) |
586 |
req.remove_pending_operations() |
|
587 |
||
588 |
def test_pending_deletion(self): |
|
589 |
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
|
590 |
inserts = get_pending_inserts(req) |
0 | 591 |
self.assertEquals(inserts, []) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
592 |
deletes = get_pending_deletes(req) |
0 | 593 |
self.assertEquals(deletes, ['12:tags:13']) |
594 |
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
|
595 |
inserts = get_pending_inserts(req) |
0 | 596 |
self.assertEquals(inserts, []) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
597 |
deletes = get_pending_deletes(req) |
0 | 598 |
self.assertEquals(deletes, ['12:tags:13', '12:tags:14']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
599 |
deletes = get_pending_deletes(req, 12) |
0 | 600 |
self.assertEquals(deletes, ['12:tags:13', '12:tags:14']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
601 |
deletes = get_pending_deletes(req, 13) |
0 | 602 |
self.assertEquals(deletes, ['12:tags:13']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
603 |
deletes = get_pending_deletes(req, 14) |
0 | 604 |
self.assertEquals(deletes, ['12:tags:14']) |
605 |
req.remove_pending_operations() |
|
606 |
||
607 |
def test_remove_pending_operations(self): |
|
608 |
self.remote_call('add_pending_delete', ['12', 'tags', '13']) |
|
1654 | 609 |
_, 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
|
610 |
inserts = get_pending_inserts(req) |
0 | 611 |
self.assertEquals(inserts, ['12:tags:14']) |
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
612 |
deletes = get_pending_deletes(req) |
0 | 613 |
self.assertEquals(deletes, ['12:tags:13']) |
614 |
req.remove_pending_operations() |
|
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
615 |
self.assertEquals(get_pending_deletes(req), []) |
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
616 |
self.assertEquals(get_pending_inserts(req), []) |
1426 | 617 |
|
0 | 618 |
|
619 |
def test_add_inserts(self): |
|
620 |
res, req = self.remote_call('add_pending_inserts', |
|
621 |
[('12', 'tags', '13'), ('12', 'tags', '14')]) |
|
4292
3fc808b0490b
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4266
diff
changeset
|
622 |
inserts = get_pending_inserts(req) |
0 | 623 |
self.assertEquals(inserts, ['12:tags:13', '12:tags:14']) |
624 |
req.remove_pending_operations() |
|
1426 | 625 |
|
0 | 626 |
|
627 |
# silly tests |
|
628 |
def test_external_resource(self): |
|
629 |
self.assertEquals(self.remote_call('external_resource', 'RSS_LOGO')[0], |
|
630 |
simplejson.dumps(self.request().external_resource('RSS_LOGO'))) |
|
631 |
def test_i18n(self): |
|
632 |
self.assertEquals(self.remote_call('i18n', ['bimboom'])[0], |
|
633 |
simplejson.dumps(['bimboom'])) |
|
634 |
||
635 |
def test_format_date(self): |
|
1654 | 636 |
self.assertEquals(self.remote_call('format_date', '2007-01-01 12:00:00')[0], |
0 | 637 |
simplejson.dumps('2007/01/01')) |
638 |
||
1426 | 639 |
|
0 | 640 |
|
1426 | 641 |
|
0 | 642 |
if __name__ == '__main__': |
643 |
unittest_main() |