author | Julien Cristau <julien.cristau@logilab.fr> |
Wed, 02 Apr 2014 15:42:25 +0200 | |
changeset 9624 | a42fae4cd45a |
parent 9478 | 2d7521881d3d |
child 9641 | 4147cc32371d |
permissions | -rw-r--r-- |
9428
946aded614f3
[web error] exception may not have a 'status' attribute, generating an AttributeError that hides the original error. Closes #3381670
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8695
diff
changeset
|
1 |
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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 |
# 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
|
3 |
# |
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 |
# 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
|
5 |
# |
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 |
# 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
|
7 |
# 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
|
8 |
# 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
|
9 |
# 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
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
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
|
12 |
# 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
|
13 |
# 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
|
14 |
# 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
|
15 |
# |
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 |
# 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
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5584
c1823448f81d
[web] disallow authenticated users to access to the login form (closes #914873)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
18 |
"""unit tests for cubicweb.web.application""" |
0 | 19 |
|
20 |
import base64, Cookie |
|
21 |
import sys |
|
9428
946aded614f3
[web error] exception may not have a 'status' attribute, generating an AttributeError that hides the original error. Closes #3381670
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8695
diff
changeset
|
22 |
import httplib |
0 | 23 |
from urllib import unquote |
2661
f8df42c9da6b
[vreg api update] remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
24 |
|
f8df42c9da6b
[vreg api update] remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
25 |
from logilab.common.testlib import TestCase, unittest_main |
6849
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6848
diff
changeset
|
26 |
from logilab.common.decorators import clear_cache, classproperty |
0 | 27 |
|
5584
c1823448f81d
[web] disallow authenticated users to access to the login form (closes #914873)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
28 |
from cubicweb import AuthenticationError, Unauthorized |
9428
946aded614f3
[web error] exception may not have a 'status' attribute, generating an AttributeError that hides the original error. Closes #3381670
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8695
diff
changeset
|
29 |
from cubicweb import view |
946aded614f3
[web error] exception may not have a 'status' attribute, generating an AttributeError that hides the original error. Closes #3381670
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8695
diff
changeset
|
30 |
from cubicweb.devtools.testlib import CubicWebTC, real_error_handling |
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 |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
32 |
from cubicweb.web import LogOut, Redirect, INTERNAL_FIELD_VALUE |
0 | 33 |
from cubicweb.web.views.basecontrollers import ViewController |
7876
df15d194a134
[views] implement json / jsonp export views (closes #1942658)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
34 |
from cubicweb.web.application import anonymized_request |
9065
b1cad8e4557f
[web/test] properly reset the request connection related attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9064
diff
changeset
|
35 |
from cubicweb.dbapi import DBAPISession, _NeedAuthAccessMock |
9071
46885bfa4150
Use new repoapi for the web stack
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9069
diff
changeset
|
36 |
from cubicweb import repoapi |
0 | 37 |
|
38 |
class FakeMapping: |
|
39 |
"""emulates a mapping module""" |
|
40 |
def __init__(self): |
|
41 |
self.ENTITIES_MAP = {} |
|
42 |
self.ATTRIBUTES_MAP = {} |
|
43 |
self.RELATIONS_MAP = {} |
|
44 |
||
45 |
class MockCursor: |
|
46 |
def __init__(self): |
|
47 |
self.executed = [] |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5038
diff
changeset
|
48 |
def execute(self, rql, args=None, build_descr=False): |
0 | 49 |
args = args or {} |
50 |
self.executed.append(rql % args) |
|
51 |
||
52 |
||
53 |
class FakeController(ViewController): |
|
54 |
||
55 |
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
|
56 |
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
|
57 |
self._cw.form = form or {} |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
58 |
self._cursor = MockCursor() |
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
59 |
self._cw.execute = self._cursor.execute |
0 | 60 |
|
61 |
def new_cursor(self): |
|
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
62 |
self._cursor = MockCursor() |
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
63 |
self._cw.execute = self._cursor.execute |
0 | 64 |
|
65 |
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
|
66 |
self._cw.form = form |
0 | 67 |
|
68 |
||
69 |
class RequestBaseTC(TestCase): |
|
70 |
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
|
71 |
self._cw = FakeRequest() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
72 |
|
0 | 73 |
|
74 |
def test_list_arg(self): |
|
75 |
"""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
|
76 |
list_arg = self._cw.list_form_param |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
77 |
self.assertEqual(list_arg('arg3', {}), []) |
0 | 78 |
d = {'arg1' : "value1", |
79 |
'arg2' : ('foo', INTERNAL_FIELD_VALUE,), |
|
80 |
'arg3' : ['bar']} |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
81 |
self.assertEqual(list_arg('arg1', d, True), ['value1']) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
82 |
self.assertEqual(d, {'arg2' : ('foo', INTERNAL_FIELD_VALUE), 'arg3' : ['bar'],}) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
83 |
self.assertEqual(list_arg('arg2', d, True), ['foo']) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
84 |
self.assertEqual({'arg3' : ['bar'],}, d) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
85 |
self.assertEqual(list_arg('arg3', d), ['bar',]) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
86 |
self.assertEqual({'arg3' : ['bar'],}, d) |
0 | 87 |
|
88 |
||
89 |
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
|
90 |
self._cw.vreg['controllers'] = {'view': 1, 'login': 1} |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
91 |
self.assertEqual(self._cw.from_controller(), 'view') |
0 | 92 |
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
|
93 |
req.vreg['controllers'] = {'view': 1, 'login': 1} |
0 | 94 |
# this assertion is just to make sure that relative_path can be |
95 |
# correctly computed as it is used in from_controller() |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
96 |
self.assertEqual(req.relative_path(False), 'project') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
97 |
self.assertEqual(req.from_controller(), 'view') |
0 | 98 |
# test on a valid non-view controller |
99 |
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
|
100 |
req.vreg['controllers'] = {'view': 1, 'login': 1} |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
101 |
self.assertEqual(req.relative_path(False), 'login') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
102 |
self.assertEqual(req.from_controller(), 'login') |
0 | 103 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
104 |
|
0 | 105 |
class UtilsTC(TestCase): |
106 |
"""test suite for misc application utilities""" |
|
107 |
||
108 |
def setUp(self): |
|
109 |
self.ctrl = FakeController() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
110 |
|
0 | 111 |
#def test_which_mapping(self): |
112 |
# """tests which mapping is used (application or core)""" |
|
113 |
# init_mapping() |
|
114 |
# from cubicweb.common import mapping |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
115 |
# self.assertEqual(mapping.MAPPING_USED, 'core') |
0 | 116 |
# sys.modules['mapping'] = FakeMapping() |
117 |
# init_mapping() |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
118 |
# self.assertEqual(mapping.MAPPING_USED, 'application') |
0 | 119 |
# del sys.modules['mapping'] |
120 |
||
121 |
def test_execute_linkto(self): |
|
122 |
"""tests the execute_linkto() function""" |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
123 |
self.assertEqual(self.ctrl.execute_linkto(), None) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
124 |
self.assertEqual(self.ctrl._cursor.executed, |
0 | 125 |
[]) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
126 |
|
0 | 127 |
self.ctrl.set_form({'__linkto' : 'works_for:12_13_14:object', |
128 |
'eid': 8}) |
|
129 |
self.ctrl.execute_linkto() |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
130 |
self.assertEqual(self.ctrl._cursor.executed, |
0 | 131 |
['SET Y works_for X WHERE X eid 8, Y eid %s' % i |
132 |
for i in (12, 13, 14)]) |
|
133 |
||
134 |
self.ctrl.new_cursor() |
|
135 |
self.ctrl.set_form({'__linkto' : 'works_for:12_13_14:subject', |
|
136 |
'eid': 8}) |
|
137 |
self.ctrl.execute_linkto() |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
138 |
self.assertEqual(self.ctrl._cursor.executed, |
0 | 139 |
['SET X works_for Y WHERE X eid 8, Y eid %s' % i |
140 |
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
|
141 |
|
0 | 142 |
|
143 |
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
|
144 |
self.ctrl._cw.form = {'__linkto' : 'works_for:12_13_14:object'} |
0 | 145 |
self.ctrl.execute_linkto(eid=8) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
146 |
self.assertEqual(self.ctrl._cursor.executed, |
0 | 147 |
['SET Y works_for X WHERE X eid 8, Y eid %s' % i |
148 |
for i in (12, 13, 14)]) |
|
149 |
||
150 |
self.ctrl.new_cursor() |
|
151 |
self.ctrl.set_form({'__linkto' : 'works_for:12_13_14:subject'}) |
|
152 |
self.ctrl.execute_linkto(eid=8) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
153 |
self.assertEqual(self.ctrl._cursor.executed, |
0 | 154 |
['SET X works_for Y WHERE X eid 8, Y eid %s' % i |
155 |
for i in (12, 13, 14)]) |
|
156 |
||
157 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
158 |
class ApplicationTC(CubicWebTC): |
0 | 159 |
|
6849
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6848
diff
changeset
|
160 |
@classproperty |
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6848
diff
changeset
|
161 |
def config(cls): |
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6848
diff
changeset
|
162 |
try: |
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6848
diff
changeset
|
163 |
return cls.__dict__['_config'] |
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6848
diff
changeset
|
164 |
except KeyError: |
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6848
diff
changeset
|
165 |
config = super(ApplicationTC, cls).config |
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6848
diff
changeset
|
166 |
config.global_set_option('allow-email-login', True) |
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6848
diff
changeset
|
167 |
return config |
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6848
diff
changeset
|
168 |
|
0 | 169 |
def test_cnx_user_groups_sync(self): |
170 |
user = self.user() |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
171 |
self.assertEqual(user.groups, set(('managers',))) |
0 | 172 |
self.execute('SET X in_group G WHERE X eid %s, G name "guests"' % user.eid) |
173 |
user = self.user() |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
174 |
self.assertEqual(user.groups, set(('managers',))) |
0 | 175 |
self.commit() |
176 |
user = self.user() |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
177 |
self.assertEqual(user.groups, set(('managers', 'guests'))) |
0 | 178 |
# cleanup |
179 |
self.execute('DELETE X in_group G WHERE X eid %s, G name "guests"' % user.eid) |
|
180 |
self.commit() |
|
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, |
7584
e1881933f366
[form, controller] closes #1787233: form should provide a method to process posted content
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7235
diff
changeset
|
188 |
'__type:'+eid: 'CWUser', '_cw_entity_fields:'+eid: 'login-subject', |
4172
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 |
} |
|
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
193 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
194 |
forminfo = req.session.data['view?vid=edition...'] |
0 | 195 |
eidmap = forminfo['eidmap'] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
196 |
self.assertEqual(eidmap, {}) |
0 | 197 |
values = forminfo['values'] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
198 |
self.assertEqual(values['login-subject:'+eid], '') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
199 |
self.assertEqual(values['eid'], eid) |
4276 | 200 |
error = forminfo['error'] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
201 |
self.assertEqual(error.entity, user.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
202 |
self.assertEqual(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', |
7584
e1881933f366
[form, controller] closes #1787233: form should provide a method to process posted content
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7235
diff
changeset
|
213 |
'__type:X': 'CWUser', '_cw_entity_fields:X': 'login-subject', |
5038
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 |
7584
e1881933f366
[form, controller] closes #1787233: form should provide a method to process posted content
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7235
diff
changeset
|
217 |
'__type:Y': 'EmailAddress', '_cw_entity_fields:Y': 'address-subject', |
5038
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 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
223 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
224 |
forminfo = req.session.data['view?vid=edition...'] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
225 |
self.assertEqual(set(forminfo['eidmap']), set('XY')) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
226 |
self.assertEqual(forminfo['eidmap']['X'], None) |
5038
90493551b1eb
[form] fix validation error handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
227 |
self.assertIsInstance(forminfo['eidmap']['Y'], int) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
228 |
self.assertEqual(forminfo['error'].entity, 'X') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
229 |
self.assertEqual(forminfo['error'].errors, |
5038
90493551b1eb
[form] fix validation error handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
230 |
{'login-subject': 'required field'}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
231 |
self.assertEqual(forminfo['values'], req.form) |
5038
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', |
7584
e1881933f366
[form, controller] closes #1787233: form should provide a method to process posted content
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7235
diff
changeset
|
242 |
'__type:X': 'CWUser', '_cw_entity_fields:X': 'login-subject,upassword-subject', |
5038
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', |
7584
e1881933f366
[form, controller] closes #1787233: form should provide a method to process posted content
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7235
diff
changeset
|
246 |
'__type:Y': 'EmailAddress', '_cw_entity_fields:Y': 'address-subject', |
5038
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 |
} |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
252 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
253 |
forminfo = req.session.data['view?vid=edition...'] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
254 |
self.assertEqual(set(forminfo['eidmap']), set('XY')) |
5038
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) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
257 |
self.assertEqual(forminfo['error'].entity, forminfo['eidmap']['X']) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
258 |
self.assertEqual(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'}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
260 |
self.assertEqual(forminfo['values'], req.form) |
5038
90493551b1eb
[form] fix validation error handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
261 |
|
9428
946aded614f3
[web error] exception may not have a 'status' attribute, generating an AttributeError that hides the original error. Closes #3381670
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8695
diff
changeset
|
262 |
def test_ajax_view_raise_arbitrary_error(self): |
946aded614f3
[web error] exception may not have a 'status' attribute, generating an AttributeError that hides the original error. Closes #3381670
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8695
diff
changeset
|
263 |
class ErrorAjaxView(view.View): |
946aded614f3
[web error] exception may not have a 'status' attribute, generating an AttributeError that hides the original error. Closes #3381670
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8695
diff
changeset
|
264 |
__regid__ = 'test.ajax.error' |
946aded614f3
[web error] exception may not have a 'status' attribute, generating an AttributeError that hides the original error. Closes #3381670
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8695
diff
changeset
|
265 |
def call(self): |
946aded614f3
[web error] exception may not have a 'status' attribute, generating an AttributeError that hides the original error. Closes #3381670
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8695
diff
changeset
|
266 |
raise Exception('whatever') |
946aded614f3
[web error] exception may not have a 'status' attribute, generating an AttributeError that hides the original error. Closes #3381670
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8695
diff
changeset
|
267 |
with self.temporary_appobjects(ErrorAjaxView): |
946aded614f3
[web error] exception may not have a 'status' attribute, generating an AttributeError that hides the original error. Closes #3381670
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8695
diff
changeset
|
268 |
with real_error_handling(self.app) as app: |
946aded614f3
[web error] exception may not have a 'status' attribute, generating an AttributeError that hides the original error. Closes #3381670
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8695
diff
changeset
|
269 |
req = self.request(vid='test.ajax.error') |
946aded614f3
[web error] exception may not have a 'status' attribute, generating an AttributeError that hides the original error. Closes #3381670
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8695
diff
changeset
|
270 |
req.ajax_request = True |
946aded614f3
[web error] exception may not have a 'status' attribute, generating an AttributeError that hides the original error. Closes #3381670
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8695
diff
changeset
|
271 |
page = app.handle_request(req, '') |
946aded614f3
[web error] exception may not have a 'status' attribute, generating an AttributeError that hides the original error. Closes #3381670
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8695
diff
changeset
|
272 |
self.assertEqual(httplib.INTERNAL_SERVER_ERROR, |
946aded614f3
[web error] exception may not have a 'status' attribute, generating an AttributeError that hides the original error. Closes #3381670
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8695
diff
changeset
|
273 |
req.status_out) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
274 |
|
0 | 275 |
def _test_cleaned(self, kwargs, injected, cleaned): |
276 |
req = self.request(**kwargs) |
|
9017
aa709bc6b6c1
[application/connect] simplify connection logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8695
diff
changeset
|
277 |
page = self.app_handle_request(req, 'view') |
aa709bc6b6c1
[application/connect] simplify connection logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8695
diff
changeset
|
278 |
self.assertNotIn(injected, page) |
aa709bc6b6c1
[application/connect] simplify connection logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8695
diff
changeset
|
279 |
self.assertIn(cleaned, page) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
280 |
|
0 | 281 |
def test_nonregr_script_kiddies(self): |
282 |
"""test against current script injection""" |
|
283 |
injected = '<i>toto</i>' |
|
284 |
cleaned = 'toto' |
|
285 |
for kwargs in ({'__message': injected}, |
|
286 |
{'vid': injected}, |
|
287 |
{'vtitle': injected}, |
|
288 |
): |
|
289 |
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
|
290 |
|
0 | 291 |
def test_site_wide_eproperties_sync(self): |
292 |
# XXX work in all-in-one configuration but not in twisted for instance |
|
293 |
# in which case we need a kindof repo -> http server notification |
|
294 |
# protocol |
|
295 |
vreg = self.app.vreg |
|
296 |
# default value |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
297 |
self.assertEqual(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
|
298 |
self.execute('INSERT CWProperty X: X value "fr", X pkey "ui.language"') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
299 |
self.assertEqual(vreg.property_value('ui.language'), 'en') |
0 | 300 |
self.commit() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
301 |
self.assertEqual(vreg.property_value('ui.language'), 'fr') |
0 | 302 |
self.execute('SET X value "de" WHERE X pkey "ui.language"') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
303 |
self.assertEqual(vreg.property_value('ui.language'), 'fr') |
0 | 304 |
self.commit() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
305 |
self.assertEqual(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
|
306 |
self.execute('DELETE CWProperty X WHERE X pkey "ui.language"') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
307 |
self.assertEqual(vreg.property_value('ui.language'), 'de') |
0 | 308 |
self.commit() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
309 |
self.assertEqual(vreg.property_value('ui.language'), 'en') |
0 | 310 |
|
311 |
# authentication tests #################################################### |
|
312 |
||
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
313 |
def test_http_auth_no_anon(self): |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
314 |
req, origsession = self.init_authentication('http') |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
315 |
self.assertAuthFailure(req) |
9017
aa709bc6b6c1
[application/connect] simplify connection logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8695
diff
changeset
|
316 |
self.app.handle_request(req, 'login') |
aa709bc6b6c1
[application/connect] simplify connection logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8695
diff
changeset
|
317 |
self.assertEqual(401, req.status_out) |
aa709bc6b6c1
[application/connect] simplify connection logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8695
diff
changeset
|
318 |
clear_cache(req, 'get_authorization') |
6848
f87cd875c6db
[web session] cleanup session/authentication api: we don't have anymore to store authentication information on web session since the auto-reconnection feature has been dropped (eg in 3.10)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6797
diff
changeset
|
319 |
authstr = base64.encodestring('%s:%s' % (self.admlogin, self.admpassword)) |
7224
e5833657c646
[testlib] make a clear distinction between input / output HTTP headers
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7163
diff
changeset
|
320 |
req.set_request_header('Authorization', 'basic %s' % authstr) |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
321 |
self.assertAuthSuccess(req, origsession) |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
322 |
self.assertRaises(LogOut, self.app_handle_request, req, 'logout') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
323 |
self.assertEqual(len(self.open_sessions), 0) |
0 | 324 |
|
325 |
def test_cookie_auth_no_anon(self): |
|
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
326 |
req, origsession = self.init_authentication('cookie') |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
327 |
self.assertAuthFailure(req) |
8311
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7876
diff
changeset
|
328 |
try: |
9017
aa709bc6b6c1
[application/connect] simplify connection logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8695
diff
changeset
|
329 |
form = self.app.handle_request(req, 'login') |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8694
diff
changeset
|
330 |
except Redirect as redir: |
8311
76a44a0d7f4b
[login] split authentication logic from post authentication logic (closes #2200755)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7876
diff
changeset
|
331 |
self.fail('anonymous user should get login form') |
9017
aa709bc6b6c1
[application/connect] simplify connection logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8695
diff
changeset
|
332 |
clear_cache(req, 'get_authorization') |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7584
diff
changeset
|
333 |
self.assertTrue('__login' in form) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7584
diff
changeset
|
334 |
self.assertTrue('__password' in form) |
9039
488255d1cf3b
[testlib] rework request building in init_authentication
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9019
diff
changeset
|
335 |
self.assertFalse(req.cnx) # Mock cnx are False |
6848
f87cd875c6db
[web session] cleanup session/authentication api: we don't have anymore to store authentication information on web session since the auto-reconnection feature has been dropped (eg in 3.10)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6797
diff
changeset
|
336 |
req.form['__login'] = self.admlogin |
f87cd875c6db
[web session] cleanup session/authentication api: we don't have anymore to store authentication information on web session since the auto-reconnection feature has been dropped (eg in 3.10)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6797
diff
changeset
|
337 |
req.form['__password'] = self.admpassword |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
338 |
self.assertAuthSuccess(req, origsession) |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
339 |
self.assertRaises(LogOut, self.app_handle_request, req, 'logout') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
340 |
self.assertEqual(len(self.open_sessions), 0) |
0 | 341 |
|
1490
6b024694d493
add allow-email-login option
Florent <florent@secondweb.fr>
parents:
1489
diff
changeset
|
342 |
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
|
343 |
login = self.request().user.login |
08acef58ad08
add a test regarding login with a primary email
Florent <florent@secondweb.fr>
parents:
1398
diff
changeset
|
344 |
address = login + u'@localhost' |
08acef58ad08
add a test regarding login with a primary email
Florent <florent@secondweb.fr>
parents:
1398
diff
changeset
|
345 |
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
|
346 |
'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
|
347 |
self.commit() |
6849
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6848
diff
changeset
|
348 |
# # option allow-email-login not set |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
349 |
req, origsession = self.init_authentication('cookie') |
6848
f87cd875c6db
[web session] cleanup session/authentication api: we don't have anymore to store authentication information on web session since the auto-reconnection feature has been dropped (eg in 3.10)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6797
diff
changeset
|
350 |
# req.form['__login'] = address |
f87cd875c6db
[web session] cleanup session/authentication api: we don't have anymore to store authentication information on web session since the auto-reconnection feature has been dropped (eg in 3.10)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6797
diff
changeset
|
351 |
# req.form['__password'] = self.admpassword |
f87cd875c6db
[web session] cleanup session/authentication api: we don't have anymore to store authentication information on web session since the auto-reconnection feature has been dropped (eg in 3.10)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6797
diff
changeset
|
352 |
# self.assertAuthFailure(req) |
1490
6b024694d493
add allow-email-login option
Florent <florent@secondweb.fr>
parents:
1489
diff
changeset
|
353 |
# option allow-email-login set |
9071
46885bfa4150
Use new repoapi for the web stack
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9069
diff
changeset
|
354 |
#origsession.login = address |
1490
6b024694d493
add allow-email-login option
Florent <florent@secondweb.fr>
parents:
1489
diff
changeset
|
355 |
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
|
356 |
req.form['__login'] = address |
6848
f87cd875c6db
[web session] cleanup session/authentication api: we don't have anymore to store authentication information on web session since the auto-reconnection feature has been dropped (eg in 3.10)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6797
diff
changeset
|
357 |
req.form['__password'] = self.admpassword |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
358 |
self.assertAuthSuccess(req, origsession) |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
359 |
self.assertRaises(LogOut, self.app_handle_request, req, 'logout') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
360 |
self.assertEqual(len(self.open_sessions), 0) |
1489
08acef58ad08
add a test regarding login with a primary email
Florent <florent@secondweb.fr>
parents:
1398
diff
changeset
|
361 |
|
0 | 362 |
def _reset_cookie(self, req): |
363 |
# preparing the suite of the test |
|
364 |
# set session id in cookie |
|
365 |
cookie = Cookie.SimpleCookie() |
|
6797
90d687bd4c52
[web test] fix authentication test: session cookie should now be computed by the session handler (changed in cw 3.10.6)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
366 |
sessioncookie = self.app.session_handler.session_cookie(req) |
90d687bd4c52
[web test] fix authentication test: session cookie should now be computed by the session handler (changed in cw 3.10.6)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
367 |
cookie[sessioncookie] = req.session.sessionid |
7224
e5833657c646
[testlib] make a clear distinction between input / output HTTP headers
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7163
diff
changeset
|
368 |
req.set_request_header('Cookie', cookie[sessioncookie].OutputString(), |
e5833657c646
[testlib] make a clear distinction between input / output HTTP headers
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7163
diff
changeset
|
369 |
raw=True) |
0 | 370 |
clear_cache(req, 'get_authorization') |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
371 |
# reset session as if it was a new incoming request |
9065
b1cad8e4557f
[web/test] properly reset the request connection related attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9064
diff
changeset
|
372 |
req.session = DBAPISession(None) |
b1cad8e4557f
[web/test] properly reset the request connection related attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9064
diff
changeset
|
373 |
req.user = req.cnx = _NeedAuthAccessMock |
b1cad8e4557f
[web/test] properly reset the request connection related attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9064
diff
changeset
|
374 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
375 |
|
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
376 |
def _test_auth_anon(self, req): |
9019
e08f9c55dab5
[application] call req.set_session in application.main_handle_request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9017
diff
changeset
|
377 |
asession = self.app.get_session(req) |
9071
46885bfa4150
Use new repoapi for the web stack
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9069
diff
changeset
|
378 |
# important otherwise _reset_cookie will not use the right session |
46885bfa4150
Use new repoapi for the web stack
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9069
diff
changeset
|
379 |
req.set_cnx(repoapi.ClientConnection(asession)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
380 |
self.assertEqual(len(self.open_sessions), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
381 |
self.assertEqual(asession.login, 'anon') |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7584
diff
changeset
|
382 |
self.assertTrue(asession.anonymous_session) |
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
383 |
self._reset_cookie(req) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
384 |
|
0 | 385 |
def _test_anon_auth_fail(self, req): |
9071
46885bfa4150
Use new repoapi for the web stack
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9069
diff
changeset
|
386 |
self.assertEqual(1, len(self.open_sessions)) |
9019
e08f9c55dab5
[application] call req.set_session in application.main_handle_request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9017
diff
changeset
|
387 |
session = self.app.get_session(req) |
9071
46885bfa4150
Use new repoapi for the web stack
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9069
diff
changeset
|
388 |
# important otherwise _reset_cookie will not use the right session |
46885bfa4150
Use new repoapi for the web stack
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9069
diff
changeset
|
389 |
req.set_cnx(repoapi.ClientConnection(session)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
390 |
self.assertEqual(req.message, 'authentication failure') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
391 |
self.assertEqual(req.session.anonymous_session, True) |
9071
46885bfa4150
Use new repoapi for the web stack
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9069
diff
changeset
|
392 |
self.assertEqual(1, len(self.open_sessions)) |
0 | 393 |
self._reset_cookie(req) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
394 |
|
0 | 395 |
def test_http_auth_anon_allowed(self): |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
396 |
req, origsession = self.init_authentication('http', 'anon') |
0 | 397 |
self._test_auth_anon(req) |
398 |
authstr = base64.encodestring('toto:pouet') |
|
7224
e5833657c646
[testlib] make a clear distinction between input / output HTTP headers
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7163
diff
changeset
|
399 |
req.set_request_header('Authorization', 'basic %s' % authstr) |
0 | 400 |
self._test_anon_auth_fail(req) |
6848
f87cd875c6db
[web session] cleanup session/authentication api: we don't have anymore to store authentication information on web session since the auto-reconnection feature has been dropped (eg in 3.10)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6797
diff
changeset
|
401 |
authstr = base64.encodestring('%s:%s' % (self.admlogin, self.admpassword)) |
7224
e5833657c646
[testlib] make a clear distinction between input / output HTTP headers
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7163
diff
changeset
|
402 |
req.set_request_header('Authorization', 'basic %s' % authstr) |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
403 |
self.assertAuthSuccess(req, origsession) |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
404 |
self.assertRaises(LogOut, self.app_handle_request, req, 'logout') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5584
diff
changeset
|
405 |
self.assertEqual(len(self.open_sessions), 0) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
406 |
|
0 | 407 |
def test_cookie_auth_anon_allowed(self): |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
408 |
req, origsession = self.init_authentication('cookie', 'anon') |
0 | 409 |
self._test_auth_anon(req) |
410 |
req.form['__login'] = 'toto' |
|
411 |
req.form['__password'] = 'pouet' |
|
412 |
self._test_anon_auth_fail(req) |
|
6848
f87cd875c6db
[web session] cleanup session/authentication api: we don't have anymore to store authentication information on web session since the auto-reconnection feature has been dropped (eg in 3.10)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6797
diff
changeset
|
413 |
req.form['__login'] = self.admlogin |
f87cd875c6db
[web session] cleanup session/authentication api: we don't have anymore to store authentication information on web session since the auto-reconnection feature has been dropped (eg in 3.10)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6797
diff
changeset
|
414 |
req.form['__password'] = self.admpassword |
5223
6abd6e3599f4
#773448: refactor session and 'no connection' handling, by introducing proper web session. We should now be able to see page even when no anon is configured, and be redirected to the login form as soon as one tries to do a query.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
415 |
self.assertAuthSuccess(req, origsession) |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
416 |
self.assertRaises(LogOut, self.app_handle_request, req, 'logout') |
9071
46885bfa4150
Use new repoapi for the web stack
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9069
diff
changeset
|
417 |
self.assertEqual(0, len(self.open_sessions)) |
0 | 418 |
|
7876
df15d194a134
[views] implement json / jsonp export views (closes #1942658)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
419 |
def test_anonymized_request(self): |
df15d194a134
[views] implement json / jsonp export views (closes #1942658)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
420 |
req = self.request() |
9071
46885bfa4150
Use new repoapi for the web stack
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9069
diff
changeset
|
421 |
self.assertEqual(self.admlogin, req.session.user.login) |
7876
df15d194a134
[views] implement json / jsonp export views (closes #1942658)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
422 |
# admin should see anon + admin |
9071
46885bfa4150
Use new repoapi for the web stack
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9069
diff
changeset
|
423 |
self.assertEqual(2, len(list(req.find_entities('CWUser')))) |
7876
df15d194a134
[views] implement json / jsonp export views (closes #1942658)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
424 |
with anonymized_request(req): |
9071
46885bfa4150
Use new repoapi for the web stack
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9069
diff
changeset
|
425 |
self.assertEqual('anon', req.session.login, 'anon') |
7876
df15d194a134
[views] implement json / jsonp export views (closes #1942658)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
426 |
# anon should only see anon user |
9071
46885bfa4150
Use new repoapi for the web stack
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9069
diff
changeset
|
427 |
self.assertEqual(1, len(list(req.find_entities('CWUser')))) |
46885bfa4150
Use new repoapi for the web stack
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9069
diff
changeset
|
428 |
self.assertEqual(self.admlogin, req.session.login) |
46885bfa4150
Use new repoapi for the web stack
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9069
diff
changeset
|
429 |
self.assertEqual(2, len(list(req.find_entities('CWUser')))) |
7876
df15d194a134
[views] implement json / jsonp export views (closes #1942658)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
430 |
|
3523
16880e7ee3fa
don't accept None to avoid error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3265
diff
changeset
|
431 |
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
|
432 |
req = self.request() |
16880e7ee3fa
don't accept None to avoid error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3265
diff
changeset
|
433 |
# 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
|
434 |
req.form['rql'] = 'rql:Any OV1, X WHERE X custom_workflow OV1?' |
8312
6c2119509fac
[web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8311
diff
changeset
|
435 |
self.app_handle_request(req) |
0 | 436 |
|
9428
946aded614f3
[web error] exception may not have a 'status' attribute, generating an AttributeError that hides the original error. Closes #3381670
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8695
diff
changeset
|
437 |
|
0 | 438 |
if __name__ == '__main__': |
439 |
unittest_main() |