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