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