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