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