author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 26 Mar 2010 08:28:22 +0100 | |
branch | stable |
changeset 5030 | 5238d9a8dfee |
parent 4276 | e2ed81c20e74 |
child 5038 | 90493551b1eb |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: iso-8859-1 -*- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
2 |
"""unit tests for cubicweb.web.application |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
3 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
4 |
:organization: Logilab |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3801
diff
changeset
|
5 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
7 |
: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:
1802
diff
changeset
|
8 |
""" |
0 | 9 |
|
10 |
import base64, Cookie |
|
11 |
import sys |
|
12 |
from urllib import unquote |
|
2661
f8df42c9da6b
[vreg api update] remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
13 |
|
f8df42c9da6b
[vreg api update] remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
14 |
from logilab.common.testlib import TestCase, unittest_main |
0 | 15 |
from logilab.common.decorators import clear_cache |
16 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
17 |
from cubicweb.devtools.testlib import CubicWebTC |
2661
f8df42c9da6b
[vreg api update] remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
18 |
from cubicweb.devtools.fake import FakeRequest |
0 | 19 |
from cubicweb.web import Redirect, AuthenticationError, ExplicitLogin, INTERNAL_FIELD_VALUE |
20 |
from cubicweb.web.views.basecontrollers import ViewController |
|
21 |
||
22 |
class FakeMapping: |
|
23 |
"""emulates a mapping module""" |
|
24 |
def __init__(self): |
|
25 |
self.ENTITIES_MAP = {} |
|
26 |
self.ATTRIBUTES_MAP = {} |
|
27 |
self.RELATIONS_MAP = {} |
|
28 |
||
29 |
class MockCursor: |
|
30 |
def __init__(self): |
|
31 |
self.executed = [] |
|
32 |
def execute(self, rql, args=None, cachekey=None): |
|
33 |
args = args or {} |
|
34 |
self.executed.append(rql % args) |
|
35 |
||
36 |
||
37 |
class FakeController(ViewController): |
|
38 |
||
39 |
def __init__(self, form=None): |
|
3462
3a79fecdd2b4
[magicsearch] make tests pass again: base preprocessor must have access to vreg
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3293
diff
changeset
|
40 |
self._cw = FakeRequest() |
3a79fecdd2b4
[magicsearch] make tests pass again: base preprocessor must have access to vreg
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3293
diff
changeset
|
41 |
self._cw.form = form or {} |
3a79fecdd2b4
[magicsearch] make tests pass again: base preprocessor must have access to vreg
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3293
diff
changeset
|
42 |
self._cursor = self._cw.cursor = MockCursor() |
0 | 43 |
|
44 |
def new_cursor(self): |
|
3462
3a79fecdd2b4
[magicsearch] make tests pass again: base preprocessor must have access to vreg
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3293
diff
changeset
|
45 |
self._cursor = self._cw.cursor = MockCursor() |
0 | 46 |
|
47 |
def set_form(self, form): |
|
3462
3a79fecdd2b4
[magicsearch] make tests pass again: base preprocessor must have access to vreg
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3293
diff
changeset
|
48 |
self._cw.form = form |
0 | 49 |
|
50 |
||
51 |
class RequestBaseTC(TestCase): |
|
52 |
def setUp(self): |
|
3462
3a79fecdd2b4
[magicsearch] make tests pass again: base preprocessor must have access to vreg
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3293
diff
changeset
|
53 |
self._cw = FakeRequest() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
54 |
|
0 | 55 |
|
56 |
def test_list_arg(self): |
|
57 |
"""tests the list_arg() function""" |
|
3462
3a79fecdd2b4
[magicsearch] make tests pass again: base preprocessor must have access to vreg
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3293
diff
changeset
|
58 |
list_arg = self._cw.list_form_param |
0 | 59 |
self.assertEquals(list_arg('arg3', {}), []) |
60 |
d = {'arg1' : "value1", |
|
61 |
'arg2' : ('foo', INTERNAL_FIELD_VALUE,), |
|
62 |
'arg3' : ['bar']} |
|
63 |
self.assertEquals(list_arg('arg1', d, True), ['value1']) |
|
64 |
self.assertEquals(d, {'arg2' : ('foo', INTERNAL_FIELD_VALUE), 'arg3' : ['bar'],}) |
|
65 |
self.assertEquals(list_arg('arg2', d, True), ['foo']) |
|
66 |
self.assertEquals({'arg3' : ['bar'],}, d) |
|
67 |
self.assertEquals(list_arg('arg3', d), ['bar',]) |
|
68 |
self.assertEquals({'arg3' : ['bar'],}, d) |
|
69 |
||
70 |
||
71 |
def test_from_controller(self): |
|
3462
3a79fecdd2b4
[magicsearch] make tests pass again: base preprocessor must have access to vreg
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3293
diff
changeset
|
72 |
self._cw.vreg['controllers'] = {'view': 1, 'login': 1} |
3a79fecdd2b4
[magicsearch] make tests pass again: base preprocessor must have access to vreg
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3293
diff
changeset
|
73 |
self.assertEquals(self._cw.from_controller(), 'view') |
0 | 74 |
req = FakeRequest(url='project?vid=list') |
3265
96c8363b8f64
test update, no more a FakeVReg, needs to hack it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
75 |
req.vreg['controllers'] = {'view': 1, 'login': 1} |
0 | 76 |
# this assertion is just to make sure that relative_path can be |
77 |
# correctly computed as it is used in from_controller() |
|
78 |
self.assertEquals(req.relative_path(False), 'project') |
|
79 |
self.assertEquals(req.from_controller(), 'view') |
|
80 |
# test on a valid non-view controller |
|
81 |
req = FakeRequest(url='login?x=1&y=2') |
|
3265
96c8363b8f64
test update, no more a FakeVReg, needs to hack it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
82 |
req.vreg['controllers'] = {'view': 1, 'login': 1} |
0 | 83 |
self.assertEquals(req.relative_path(False), 'login') |
84 |
self.assertEquals(req.from_controller(), 'login') |
|
85 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
86 |
|
0 | 87 |
class UtilsTC(TestCase): |
88 |
"""test suite for misc application utilities""" |
|
89 |
||
90 |
def setUp(self): |
|
91 |
self.ctrl = FakeController() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
92 |
|
0 | 93 |
#def test_which_mapping(self): |
94 |
# """tests which mapping is used (application or core)""" |
|
95 |
# init_mapping() |
|
96 |
# from cubicweb.common import mapping |
|
97 |
# self.assertEquals(mapping.MAPPING_USED, 'core') |
|
98 |
# sys.modules['mapping'] = FakeMapping() |
|
99 |
# init_mapping() |
|
100 |
# self.assertEquals(mapping.MAPPING_USED, 'application') |
|
101 |
# del sys.modules['mapping'] |
|
102 |
||
103 |
def test_execute_linkto(self): |
|
104 |
"""tests the execute_linkto() function""" |
|
105 |
self.assertEquals(self.ctrl.execute_linkto(), None) |
|
106 |
self.assertEquals(self.ctrl._cursor.executed, |
|
107 |
[]) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
108 |
|
0 | 109 |
self.ctrl.set_form({'__linkto' : 'works_for:12_13_14:object', |
110 |
'eid': 8}) |
|
111 |
self.ctrl.execute_linkto() |
|
112 |
self.assertEquals(self.ctrl._cursor.executed, |
|
113 |
['SET Y works_for X WHERE X eid 8, Y eid %s' % i |
|
114 |
for i in (12, 13, 14)]) |
|
115 |
||
116 |
self.ctrl.new_cursor() |
|
117 |
self.ctrl.set_form({'__linkto' : 'works_for:12_13_14:subject', |
|
118 |
'eid': 8}) |
|
119 |
self.ctrl.execute_linkto() |
|
120 |
self.assertEquals(self.ctrl._cursor.executed, |
|
121 |
['SET X works_for Y WHERE X eid 8, Y eid %s' % i |
|
122 |
for i in (12, 13, 14)]) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
123 |
|
0 | 124 |
|
125 |
self.ctrl.new_cursor() |
|
3462
3a79fecdd2b4
[magicsearch] make tests pass again: base preprocessor must have access to vreg
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3293
diff
changeset
|
126 |
self.ctrl._cw.form = {'__linkto' : 'works_for:12_13_14:object'} |
0 | 127 |
self.ctrl.execute_linkto(eid=8) |
128 |
self.assertEquals(self.ctrl._cursor.executed, |
|
129 |
['SET Y works_for X WHERE X eid 8, Y eid %s' % i |
|
130 |
for i in (12, 13, 14)]) |
|
131 |
||
132 |
self.ctrl.new_cursor() |
|
133 |
self.ctrl.set_form({'__linkto' : 'works_for:12_13_14:subject'}) |
|
134 |
self.ctrl.execute_linkto(eid=8) |
|
135 |
self.assertEquals(self.ctrl._cursor.executed, |
|
136 |
['SET X works_for Y WHERE X eid 8, Y eid %s' % i |
|
137 |
for i in (12, 13, 14)]) |
|
138 |
||
139 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
140 |
class ApplicationTC(CubicWebTC): |
3523
16880e7ee3fa
don't accept None to avoid error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3265
diff
changeset
|
141 |
def setUp(self): |
16880e7ee3fa
don't accept None to avoid error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3265
diff
changeset
|
142 |
super(ApplicationTC, self).setUp() |
16880e7ee3fa
don't accept None to avoid error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3265
diff
changeset
|
143 |
def raise_hdlr(*args, **kwargs): |
16880e7ee3fa
don't accept None to avoid error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3265
diff
changeset
|
144 |
raise |
16880e7ee3fa
don't accept None to avoid error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3265
diff
changeset
|
145 |
self.app.error_handler = raise_hdlr |
0 | 146 |
|
147 |
def test_cnx_user_groups_sync(self): |
|
148 |
user = self.user() |
|
149 |
self.assertEquals(user.groups, set(('managers',))) |
|
150 |
self.execute('SET X in_group G WHERE X eid %s, G name "guests"' % user.eid) |
|
151 |
user = self.user() |
|
152 |
self.assertEquals(user.groups, set(('managers',))) |
|
153 |
self.commit() |
|
154 |
user = self.user() |
|
155 |
self.assertEquals(user.groups, set(('managers', 'guests'))) |
|
156 |
# cleanup |
|
157 |
self.execute('DELETE X in_group G WHERE X eid %s, G name "guests"' % user.eid) |
|
158 |
self.commit() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
159 |
|
0 | 160 |
def test_nonregr_publish1(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
161 |
req = self.request(u'CWEType X WHERE X final FALSE, X meta FALSE') |
0 | 162 |
self.app.publish('view', req) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
163 |
|
0 | 164 |
def test_nonregr_publish2(self): |
165 |
req = self.request(u'Any count(N) WHERE N todo_by U, N is Note, U eid %s' |
|
166 |
% self.user().eid) |
|
167 |
self.app.publish('view', req) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
168 |
|
0 | 169 |
def test_publish_validation_error(self): |
170 |
req = self.request() |
|
171 |
user = self.user() |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
172 |
eid = unicode(user.eid) |
0 | 173 |
req.form = { |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
174 |
'eid': eid, |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
175 |
'__type:'+eid: 'CWUser', '_cw_edited_fields:'+eid: 'login-subject', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
176 |
'login-subject:'+eid: '', # ERROR: no login specified |
0 | 177 |
# just a sample, missing some necessary information for real life |
178 |
'__errorurl': 'view?vid=edition...' |
|
179 |
} |
|
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
180 |
path, params = self.expect_redirect(lambda x: self.app_publish(x, 'edit'), req) |
0 | 181 |
forminfo = req.get_session_data('view?vid=edition...') |
182 |
eidmap = forminfo['eidmap'] |
|
183 |
self.assertEquals(eidmap, {}) |
|
184 |
values = forminfo['values'] |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
185 |
self.assertEquals(values['login-subject:'+eid], '') |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
186 |
self.assertEquals(values['eid'], eid) |
4276 | 187 |
error = forminfo['error'] |
188 |
self.assertEquals(error.entity, user.eid) |
|
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4276
diff
changeset
|
189 |
self.assertEquals(error.errors['login-subject'], 'required attribute') |
0 | 190 |
|
191 |
||
192 |
def test_validation_error_dont_loose_subentity_data(self): |
|
193 |
"""test creation of two linked entities |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
194 |
""" |
0 | 195 |
req = self.request() |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
196 |
form = {'eid': ['X', 'Y'], '__maineid': 'X', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
197 |
'__type:X': 'CWUser', '_cw_edited_fields:X': 'login-subject,surname-subject', |
0 | 198 |
# missing required field |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
199 |
'login-subject:X': u'', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
200 |
'surname-subject:X': u'Mr Ouaoua', |
0 | 201 |
# but email address is set |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
202 |
'__type:Y': 'EmailAddress', '_cw_edited_fields:Y': 'address-subject,alias-subject,use_email-object', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
203 |
'address-subject:Y': u'bougloup@logilab.fr', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
204 |
'alias-subject:Y': u'', |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
205 |
'use_email-object:Y': 'X', |
0 | 206 |
# necessary to get validation error handling |
207 |
'__errorurl': 'view?vid=edition...', |
|
208 |
} |
|
209 |
req.form = form |
|
210 |
# monkey patch edited_eid to ensure both entities are edited, not only X |
|
211 |
req.edited_eids = lambda : ('Y', 'X') |
|
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
212 |
path, params = self.expect_redirect(lambda x: self.app_publish(x, 'edit'), req) |
0 | 213 |
forminfo = req.get_session_data('view?vid=edition...') |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
214 |
self.assertEquals(set(forminfo['eidmap']), set('XY')) |
4276 | 215 |
self.assertEquals(forminfo['error'].entity, forminfo['eidmap']['X']) |
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4276
diff
changeset
|
216 |
self.assertEquals(forminfo['error'].errors, |
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4276
diff
changeset
|
217 |
{'login-subject': 'required attribute', |
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4276
diff
changeset
|
218 |
'upassword-subject': 'required attribute'}) |
0 | 219 |
self.assertEquals(forminfo['values'], form) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
220 |
|
0 | 221 |
def _test_cleaned(self, kwargs, injected, cleaned): |
222 |
req = self.request(**kwargs) |
|
223 |
page = self.app.publish('view', req) |
|
224 |
self.failIf(injected in page, (kwargs, injected)) |
|
225 |
self.failUnless(cleaned in page, (kwargs, cleaned)) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
226 |
|
0 | 227 |
def test_nonregr_script_kiddies(self): |
228 |
"""test against current script injection""" |
|
229 |
injected = '<i>toto</i>' |
|
230 |
cleaned = 'toto' |
|
231 |
for kwargs in ({'__message': injected}, |
|
232 |
{'vid': injected}, |
|
233 |
{'vtitle': injected}, |
|
234 |
): |
|
235 |
yield self._test_cleaned, kwargs, injected, cleaned |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
236 |
|
0 | 237 |
def test_site_wide_eproperties_sync(self): |
238 |
# XXX work in all-in-one configuration but not in twisted for instance |
|
239 |
# in which case we need a kindof repo -> http server notification |
|
240 |
# protocol |
|
241 |
vreg = self.app.vreg |
|
242 |
# default value |
|
243 |
self.assertEquals(vreg.property_value('ui.language'), 'en') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
244 |
self.execute('INSERT CWProperty X: X value "fr", X pkey "ui.language"') |
0 | 245 |
self.assertEquals(vreg.property_value('ui.language'), 'en') |
246 |
self.commit() |
|
247 |
self.assertEquals(vreg.property_value('ui.language'), 'fr') |
|
248 |
self.execute('SET X value "de" WHERE X pkey "ui.language"') |
|
249 |
self.assertEquals(vreg.property_value('ui.language'), 'fr') |
|
250 |
self.commit() |
|
251 |
self.assertEquals(vreg.property_value('ui.language'), 'de') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
252 |
self.execute('DELETE CWProperty X WHERE X pkey "ui.language"') |
0 | 253 |
self.assertEquals(vreg.property_value('ui.language'), 'de') |
254 |
self.commit() |
|
255 |
self.assertEquals(vreg.property_value('ui.language'), 'en') |
|
256 |
||
257 |
def test_fb_login_concept(self): |
|
258 |
"""see data/views.py""" |
|
259 |
self.set_option('auth-mode', 'cookie') |
|
260 |
self.set_option('anonymous-user', 'anon') |
|
261 |
self.login('anon') |
|
262 |
req = self.request() |
|
263 |
origcnx = req.cnx |
|
264 |
req.form['__fblogin'] = u'turlututu' |
|
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
265 |
page = self.app_publish(req) |
0 | 266 |
self.failIf(req.cnx is origcnx) |
267 |
self.assertEquals(req.user.login, 'turlututu') |
|
268 |
self.failUnless('turlututu' in page, page) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
269 |
|
0 | 270 |
# authentication tests #################################################### |
271 |
||
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
272 |
def test_http_auth_no_anon(self): |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
273 |
req, origcnx = self.init_authentication('http') |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
274 |
self.assertAuthFailure(req) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
275 |
self.assertRaises(ExplicitLogin, self.app_publish, req, 'login') |
0 | 276 |
self.assertEquals(req.cnx, None) |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
277 |
authstr = base64.encodestring('%s:%s' % (origcnx.login, origcnx.authinfo['password'])) |
0 | 278 |
req._headers['Authorization'] = 'basic %s' % authstr |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
279 |
self.assertAuthSuccess(req, origcnx) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
280 |
self.assertEquals(req.cnx.authinfo, {'password': origcnx.authinfo['password']}) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
281 |
self.assertRaises(AuthenticationError, self.app_publish, req, 'logout') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
282 |
self.assertEquals(len(self.open_sessions), 0) |
0 | 283 |
|
284 |
def test_cookie_auth_no_anon(self): |
|
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
285 |
req, origcnx = self.init_authentication('cookie') |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
286 |
self.assertAuthFailure(req) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
287 |
form = self.app_publish(req, 'login') |
0 | 288 |
self.failUnless('__login' in form) |
289 |
self.failUnless('__password' in form) |
|
290 |
self.assertEquals(req.cnx, None) |
|
291 |
req.form['__login'] = origcnx.login |
|
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
292 |
req.form['__password'] = origcnx.authinfo['password'] |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
293 |
self.assertAuthSuccess(req, origcnx) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
294 |
self.assertEquals(req.cnx.authinfo, {'password': origcnx.authinfo['password']}) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
295 |
self.assertRaises(AuthenticationError, self.app_publish, req, 'logout') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
296 |
self.assertEquals(len(self.open_sessions), 0) |
0 | 297 |
|
1490
6b024694d493
add allow-email-login option
Florent <florent@secondweb.fr>
parents:
1489
diff
changeset
|
298 |
def test_login_by_email(self): |
1489
08acef58ad08
add a test regarding login with a primary email
Florent <florent@secondweb.fr>
parents:
1398
diff
changeset
|
299 |
login = self.request().user.login |
08acef58ad08
add a test regarding login with a primary email
Florent <florent@secondweb.fr>
parents:
1398
diff
changeset
|
300 |
address = login + u'@localhost' |
08acef58ad08
add a test regarding login with a primary email
Florent <florent@secondweb.fr>
parents:
1398
diff
changeset
|
301 |
self.execute('INSERT EmailAddress X: X address %(address)s, U primary_email X ' |
08acef58ad08
add a test regarding login with a primary email
Florent <florent@secondweb.fr>
parents:
1398
diff
changeset
|
302 |
'WHERE U login %(login)s', {'address': address, 'login': login}) |
08acef58ad08
add a test regarding login with a primary email
Florent <florent@secondweb.fr>
parents:
1398
diff
changeset
|
303 |
self.commit() |
1490
6b024694d493
add allow-email-login option
Florent <florent@secondweb.fr>
parents:
1489
diff
changeset
|
304 |
# option allow-email-login not set |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
305 |
req, origcnx = self.init_authentication('cookie') |
1490
6b024694d493
add allow-email-login option
Florent <florent@secondweb.fr>
parents:
1489
diff
changeset
|
306 |
req.form['__login'] = address |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
307 |
req.form['__password'] = origcnx.authinfo['password'] |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
308 |
self.assertAuthFailure(req) |
1490
6b024694d493
add allow-email-login option
Florent <florent@secondweb.fr>
parents:
1489
diff
changeset
|
309 |
# option allow-email-login set |
2267
e1d2df3f1091
move login by email functionnality on the repository side to avoid buggy call to internal_session from the web interface side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
310 |
origcnx.login = address |
1490
6b024694d493
add allow-email-login option
Florent <florent@secondweb.fr>
parents:
1489
diff
changeset
|
311 |
self.set_option('allow-email-login', True) |
1489
08acef58ad08
add a test regarding login with a primary email
Florent <florent@secondweb.fr>
parents:
1398
diff
changeset
|
312 |
req.form['__login'] = address |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
313 |
req.form['__password'] = origcnx.authinfo['password'] |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
314 |
self.assertAuthSuccess(req, origcnx) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
315 |
self.assertEquals(req.cnx.authinfo, {'password': origcnx.authinfo['password']}) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
316 |
self.assertRaises(AuthenticationError, self.app_publish, req, 'logout') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
317 |
self.assertEquals(len(self.open_sessions), 0) |
1489
08acef58ad08
add a test regarding login with a primary email
Florent <florent@secondweb.fr>
parents:
1398
diff
changeset
|
318 |
|
0 | 319 |
def _reset_cookie(self, req): |
320 |
# preparing the suite of the test |
|
321 |
# set session id in cookie |
|
322 |
cookie = Cookie.SimpleCookie() |
|
323 |
cookie['__session'] = req.cnx.sessionid |
|
324 |
req._headers['Cookie'] = cookie['__session'].OutputString() |
|
325 |
clear_cache(req, 'get_authorization') |
|
326 |
# reset cnx as if it was a new incoming request |
|
327 |
req.cnx = None |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
328 |
|
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
329 |
def _test_auth_anon(self, req): |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
330 |
self.app.connect(req) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
331 |
acnx = req.cnx |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
332 |
self.assertEquals(len(self.open_sessions), 1) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
333 |
self.assertEquals(acnx.login, 'anon') |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
334 |
self.assertEquals(acnx.authinfo['password'], 'anon') |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
335 |
self.failUnless(acnx.anonymous_connection) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
336 |
self._reset_cookie(req) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
337 |
|
0 | 338 |
def _test_anon_auth_fail(self, req): |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
339 |
self.assertEquals(len(self.open_sessions), 1) |
0 | 340 |
self.app.connect(req) |
341 |
self.assertEquals(req.message, 'authentication failure') |
|
342 |
self.assertEquals(req.cnx.anonymous_connection, True) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
343 |
self.assertEquals(len(self.open_sessions), 1) |
0 | 344 |
self._reset_cookie(req) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
345 |
|
0 | 346 |
def test_http_auth_anon_allowed(self): |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
347 |
req, origcnx = self.init_authentication('http', 'anon') |
0 | 348 |
self._test_auth_anon(req) |
349 |
authstr = base64.encodestring('toto:pouet') |
|
350 |
req._headers['Authorization'] = 'basic %s' % authstr |
|
351 |
self._test_anon_auth_fail(req) |
|
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
352 |
authstr = base64.encodestring('%s:%s' % (origcnx.login, origcnx.authinfo['password'])) |
0 | 353 |
req._headers['Authorization'] = 'basic %s' % authstr |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
354 |
self.assertAuthSuccess(req, origcnx) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
355 |
self.assertEquals(req.cnx.authinfo, {'password': origcnx.authinfo['password']}) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
356 |
self.assertRaises(AuthenticationError, self.app_publish, req, 'logout') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
357 |
self.assertEquals(len(self.open_sessions), 0) |
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
358 |
|
0 | 359 |
def test_cookie_auth_anon_allowed(self): |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
360 |
req, origcnx = self.init_authentication('cookie', 'anon') |
0 | 361 |
self._test_auth_anon(req) |
362 |
req.form['__login'] = 'toto' |
|
363 |
req.form['__password'] = 'pouet' |
|
364 |
self._test_anon_auth_fail(req) |
|
365 |
req.form['__login'] = origcnx.login |
|
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
366 |
req.form['__password'] = origcnx.authinfo['password'] |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
367 |
self.assertAuthSuccess(req, origcnx) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
368 |
self.assertEquals(req.cnx.authinfo, {'password': origcnx.authinfo['password']}) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
369 |
self.assertRaises(AuthenticationError, self.app_publish, req, 'logout') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
370 |
self.assertEquals(len(self.open_sessions), 0) |
0 | 371 |
|
3523
16880e7ee3fa
don't accept None to avoid error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3265
diff
changeset
|
372 |
def test_non_regr_optional_first_var(self): |
16880e7ee3fa
don't accept None to avoid error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3265
diff
changeset
|
373 |
req = self.request() |
16880e7ee3fa
don't accept None to avoid error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3265
diff
changeset
|
374 |
# expect a rset with None in [0][0] |
16880e7ee3fa
don't accept None to avoid error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3265
diff
changeset
|
375 |
req.form['rql'] = 'rql:Any OV1, X WHERE X custom_workflow OV1?' |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
376 |
self.app_publish(req) |
0 | 377 |
|
378 |
if __name__ == '__main__': |
|
379 |
unittest_main() |