author | Denis Laxalde <denis.laxalde@logilab.fr> |
Fri, 24 Jun 2016 13:08:52 +0200 | |
branch | 3.22 |
changeset 11387 | 51e988f9870e |
parent 11127 | 6464edfa95bb |
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 |
|
10605
61521bee2b68
[py3k] import SimpleCookie using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10604
diff
changeset
|
20 |
import base64 |
10604
d4bf85db41f2
[py3k] import HTTP client constants and exceptions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10356
diff
changeset
|
21 |
|
10734
e64738c093e5
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10605
diff
changeset
|
22 |
from six import text_type |
10604
d4bf85db41f2
[py3k] import HTTP client constants and exceptions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10356
diff
changeset
|
23 |
from six.moves import http_client |
10605
61521bee2b68
[py3k] import SimpleCookie using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10604
diff
changeset
|
24 |
from six.moves.http_cookies import SimpleCookie |
2661
f8df42c9da6b
[vreg api update] remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
25 |
|
f8df42c9da6b
[vreg api update] remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
26 |
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
|
27 |
from logilab.common.decorators import clear_cache, classproperty |
0 | 28 |
|
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 |
9071
46885bfa4150
Use new repoapi for the web stack
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9069
diff
changeset
|
35 |
from cubicweb import repoapi |
0 | 36 |
|
37 |
class FakeMapping: |
|
38 |
"""emulates a mapping module""" |
|
39 |
def __init__(self): |
|
40 |
self.ENTITIES_MAP = {} |
|
41 |
self.ATTRIBUTES_MAP = {} |
|
42 |
self.RELATIONS_MAP = {} |
|
43 |
||
44 |
class MockCursor: |
|
45 |
def __init__(self): |
|
46 |
self.executed = [] |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5038
diff
changeset
|
47 |
def execute(self, rql, args=None, build_descr=False): |
0 | 48 |
args = args or {} |
49 |
self.executed.append(rql % args) |
|
50 |
||
51 |
||
52 |
class FakeController(ViewController): |
|
53 |
||
54 |
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
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
self._cw.execute = self._cursor.execute |
0 | 59 |
|
60 |
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
|
61 |
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
|
62 |
self._cw.execute = self._cursor.execute |
0 | 63 |
|
64 |
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
|
65 |
self._cw.form = form |
0 | 66 |
|
67 |
||
68 |
class RequestBaseTC(TestCase): |
|
69 |
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
|
70 |
self._cw = FakeRequest() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
71 |
|
0 | 72 |
|
73 |
def test_list_arg(self): |
|
74 |
"""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
|
75 |
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
|
76 |
self.assertEqual(list_arg('arg3', {}), []) |
0 | 77 |
d = {'arg1' : "value1", |
78 |
'arg2' : ('foo', INTERNAL_FIELD_VALUE,), |
|
79 |
'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
|
80 |
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
|
81 |
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
|
82 |
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
|
83 |
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
|
84 |
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
|
85 |
self.assertEqual({'arg3' : ['bar'],}, d) |
0 | 86 |
|
87 |
||
88 |
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
|
89 |
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
|
90 |
self.assertEqual(self._cw.from_controller(), 'view') |
0 | 91 |
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
|
92 |
req.vreg['controllers'] = {'view': 1, 'login': 1} |
0 | 93 |
# this assertion is just to make sure that relative_path can be |
94 |
# 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
|
95 |
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
|
96 |
self.assertEqual(req.from_controller(), 'view') |
0 | 97 |
# test on a valid non-view controller |
98 |
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
|
99 |
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
|
100 |
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
|
101 |
self.assertEqual(req.from_controller(), 'login') |
0 | 102 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
103 |
|
0 | 104 |
class UtilsTC(TestCase): |
105 |
"""test suite for misc application utilities""" |
|
106 |
||
107 |
def setUp(self): |
|
108 |
self.ctrl = FakeController() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
109 |
|
0 | 110 |
#def test_which_mapping(self): |
111 |
# """tests which mapping is used (application or core)""" |
|
112 |
# init_mapping() |
|
113 |
# 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
|
114 |
# self.assertEqual(mapping.MAPPING_USED, 'core') |
0 | 115 |
# sys.modules['mapping'] = FakeMapping() |
116 |
# 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
|
117 |
# self.assertEqual(mapping.MAPPING_USED, 'application') |
0 | 118 |
# del sys.modules['mapping'] |
119 |
||
120 |
def test_execute_linkto(self): |
|
121 |
"""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
|
122 |
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
|
123 |
self.assertEqual(self.ctrl._cursor.executed, |
0 | 124 |
[]) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
125 |
|
0 | 126 |
self.ctrl.set_form({'__linkto' : 'works_for:12_13_14:object', |
127 |
'eid': 8}) |
|
128 |
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
|
129 |
self.assertEqual(self.ctrl._cursor.executed, |
0 | 130 |
['SET Y works_for X WHERE X eid 8, Y eid %s' % i |
131 |
for i in (12, 13, 14)]) |
|
132 |
||
133 |
self.ctrl.new_cursor() |
|
134 |
self.ctrl.set_form({'__linkto' : 'works_for:12_13_14:subject', |
|
135 |
'eid': 8}) |
|
136 |
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
|
137 |
self.assertEqual(self.ctrl._cursor.executed, |
0 | 138 |
['SET X works_for Y WHERE X eid 8, Y eid %s' % i |
139 |
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
|
140 |
|
0 | 141 |
|
142 |
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
|
143 |
self.ctrl._cw.form = {'__linkto' : 'works_for:12_13_14:object'} |
0 | 144 |
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
|
145 |
self.assertEqual(self.ctrl._cursor.executed, |
0 | 146 |
['SET Y works_for X WHERE X eid 8, Y eid %s' % i |
147 |
for i in (12, 13, 14)]) |
|
148 |
||
149 |
self.ctrl.new_cursor() |
|
150 |
self.ctrl.set_form({'__linkto' : 'works_for:12_13_14:subject'}) |
|
151 |
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
|
152 |
self.assertEqual(self.ctrl._cursor.executed, |
0 | 153 |
['SET X works_for Y WHERE X eid 8, Y eid %s' % i |
154 |
for i in (12, 13, 14)]) |
|
155 |
||
156 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
157 |
class ApplicationTC(CubicWebTC): |
0 | 158 |
|
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
|
159 |
@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
|
160 |
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
|
161 |
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
|
162 |
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
|
163 |
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
|
164 |
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
|
165 |
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
|
166 |
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
|
167 |
|
0 | 168 |
def test_cnx_user_groups_sync(self): |
9641
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
169 |
with self.admin_access.client_cnx() as cnx: |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
170 |
user = cnx.user |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
171 |
self.assertEqual(user.groups, set(('managers',))) |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
172 |
cnx.execute('SET X in_group G WHERE X eid %s, G name "guests"' % user.eid) |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
173 |
user = cnx.user |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
174 |
self.assertEqual(user.groups, set(('managers',))) |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
175 |
cnx.commit() |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
176 |
user = cnx.user |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
177 |
self.assertEqual(user.groups, set(('managers', 'guests'))) |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
178 |
# cleanup |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
179 |
cnx.execute('DELETE X in_group G WHERE X eid %s, G name "guests"' % user.eid) |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
180 |
cnx.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): |
9641
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
183 |
with self.admin_access.web_request() as req: |
10890
504a67206fdc
[web/test] Remove use of old test API to silence warning
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10780
diff
changeset
|
184 |
user = req.user |
10734
e64738c093e5
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10605
diff
changeset
|
185 |
eid = text_type(user.eid) |
9641
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
186 |
req.form = { |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
187 |
'eid': eid, |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
188 |
'__type:'+eid: 'CWUser', '_cw_entity_fields:'+eid: 'login-subject', |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
189 |
'login-subject:'+eid: '', # ERROR: no login specified |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
190 |
# just a sample, missing some necessary information for real life |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
191 |
'__errorurl': 'view?vid=edition...' |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
192 |
} |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
193 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
194 |
forminfo = req.session.data['view?vid=edition...'] |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
195 |
eidmap = forminfo['eidmap'] |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
196 |
self.assertEqual(eidmap, {}) |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
197 |
values = forminfo['values'] |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
198 |
self.assertEqual(values['login-subject:'+eid], '') |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
199 |
self.assertEqual(values['eid'], eid) |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
200 |
error = forminfo['error'] |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
201 |
self.assertEqual(error.entity, user.eid) |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
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 |
""" |
9641
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
210 |
with self.admin_access.web_request() as req: |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
211 |
# set Y before X to ensure both entities are edited, not only X |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
212 |
req.form = {'eid': ['Y', 'X'], '__maineid': 'X', |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
213 |
'__type:X': 'CWUser', '_cw_entity_fields:X': 'login-subject', |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
214 |
# missing required field |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
215 |
'login-subject:X': u'', |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
216 |
# but email address is set |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
217 |
'__type:Y': 'EmailAddress', '_cw_entity_fields:Y': 'address-subject', |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
218 |
'address-subject:Y': u'bougloup@logilab.fr', |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
219 |
'use_email-object:Y': 'X', |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
220 |
# necessary to get validation error handling |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
221 |
'__errorurl': 'view?vid=edition...', |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
222 |
} |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
223 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
224 |
forminfo = req.session.data['view?vid=edition...'] |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
225 |
self.assertEqual(set(forminfo['eidmap']), set('XY')) |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
226 |
self.assertEqual(forminfo['eidmap']['X'], None) |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
227 |
self.assertIsInstance(forminfo['eidmap']['Y'], int) |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
228 |
self.assertEqual(forminfo['error'].entity, 'X') |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
229 |
self.assertEqual(forminfo['error'].errors, |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
230 |
{'login-subject': 'required field'}) |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
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 |
""" |
9641
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
239 |
with self.admin_access.web_request() as req: |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
240 |
# set Y before X to ensure both entities are edited, not only X |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
241 |
req.form = {'eid': ['Y', 'X'], '__maineid': 'X', |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
242 |
'__type:X': 'CWUser', '_cw_entity_fields:X': 'login-subject,upassword-subject', |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
243 |
# already existent user |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
244 |
'login-subject:X': u'admin', |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
245 |
'upassword-subject:X': u'admin', 'upassword-subject-confirm:X': u'admin', |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
246 |
'__type:Y': 'EmailAddress', '_cw_entity_fields:Y': 'address-subject', |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
247 |
'address-subject:Y': u'bougloup@logilab.fr', |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
248 |
'use_email-object:Y': 'X', |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
249 |
# necessary to get validation error handling |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
250 |
'__errorurl': 'view?vid=edition...', |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
251 |
} |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
252 |
path, params = self.expect_redirect_handle_request(req, 'edit') |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
253 |
forminfo = req.session.data['view?vid=edition...'] |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
254 |
self.assertEqual(set(forminfo['eidmap']), set('XY')) |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
255 |
self.assertIsInstance(forminfo['eidmap']['X'], int) |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
256 |
self.assertIsInstance(forminfo['eidmap']['Y'], int) |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
257 |
self.assertEqual(forminfo['error'].entity, forminfo['eidmap']['X']) |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
258 |
self.assertEqual(forminfo['error'].errors, |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
259 |
{'login-subject': u'the value "admin" is already used, use another one'}) |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
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 |
|
11063
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
262 |
def _edit_parent(self, dir_eid, parent_eid, role='subject', |
11064
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
263 |
etype='Directory', **kwargs): |
11063
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
264 |
parent_eid = parent_eid or '__cubicweb_internal_field__' |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
265 |
with self.admin_access.web_request() as req: |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
266 |
req.form = { |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
267 |
'eid': unicode(dir_eid), |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
268 |
'__maineid': unicode(dir_eid), |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
269 |
'__type:%s' % dir_eid: etype, |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
270 |
'parent-%s:%s' % (role, dir_eid): parent_eid, |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
271 |
} |
11064
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
272 |
req.form.update(kwargs) |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
273 |
req.form['_cw_entity_fields:%s' % dir_eid] = ','.join( |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
274 |
['parent-%s' % role] + |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
275 |
[key.split(':')[0] |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
276 |
for key in kwargs.keys() |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
277 |
if not key.startswith('_')]) |
11063
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
278 |
self.expect_redirect_handle_request(req) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
279 |
|
11066
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
280 |
def _edit_in_version(self, ticket_eid, version_eid, **kwargs): |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
281 |
version_eid = version_eid or '__cubicweb_internal_field__' |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
282 |
with self.admin_access.web_request() as req: |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
283 |
req.form = { |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
284 |
'eid': unicode(ticket_eid), |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
285 |
'__maineid': unicode(ticket_eid), |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
286 |
'__type:%s' % ticket_eid: 'Ticket', |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
287 |
'in_version-subject:%s' % ticket_eid: version_eid, |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
288 |
} |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
289 |
req.form.update(kwargs) |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
290 |
req.form['_cw_entity_fields:%s' % ticket_eid] = ','.join( |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
291 |
['in_version-subject'] + |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
292 |
[key.split(':')[0] |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
293 |
for key in kwargs.keys() |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
294 |
if not key.startswith('_')]) |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
295 |
self.expect_redirect_handle_request(req) |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
296 |
|
11064
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
297 |
def test_create_and_link_directories(self): |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
298 |
with self.admin_access.web_request() as req: |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
299 |
req.form = { |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
300 |
'eid': (u'A', u'B'), |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
301 |
'__maineid': u'A', |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
302 |
'__type:A': 'Directory', |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
303 |
'__type:B': 'Directory', |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
304 |
'parent-subject:B': u'A', |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
305 |
'name-subject:A': u'topd', |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
306 |
'name-subject:B': u'subd', |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
307 |
'_cw_entity_fields:A': 'name-subject', |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
308 |
'_cw_entity_fields:B': 'parent-subject,name-subject', |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
309 |
} |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
310 |
self.expect_redirect_handle_request(req) |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
311 |
|
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
312 |
with self.admin_access.repo_cnx() as cnx: |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
313 |
self.assertTrue(cnx.find('Directory', name=u'topd')) |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
314 |
self.assertTrue(cnx.find('Directory', name=u'subd')) |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
315 |
self.assertEqual(1, cnx.execute( |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
316 |
'Directory SUBD WHERE SUBD parent TOPD,' |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
317 |
' SUBD name "subd", TOPD name "topd"').rowcount) |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
318 |
|
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
319 |
def test_create_subentity(self): |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
320 |
with self.admin_access.repo_cnx() as cnx: |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
321 |
topd = cnx.create_entity('Directory', name=u'topd') |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
322 |
cnx.commit() |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
323 |
|
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
324 |
with self.admin_access.web_request() as req: |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
325 |
req.form = { |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
326 |
'eid': (unicode(topd.eid), u'B'), |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
327 |
'__maineid': unicode(topd.eid), |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
328 |
'__type:%s' % topd.eid: 'Directory', |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
329 |
'__type:B': 'Directory', |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
330 |
'parent-object:%s' % topd.eid: u'B', |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
331 |
'name-subject:B': u'subd', |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
332 |
'_cw_entity_fields:%s' % topd.eid: 'parent-object', |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
333 |
'_cw_entity_fields:B': 'name-subject', |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
334 |
} |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
335 |
self.expect_redirect_handle_request(req) |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
336 |
|
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
337 |
with self.admin_access.repo_cnx() as cnx: |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
338 |
self.assertTrue(cnx.find('Directory', name=u'topd')) |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
339 |
self.assertTrue(cnx.find('Directory', name=u'subd')) |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
340 |
self.assertEqual(1, cnx.execute( |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
341 |
'Directory SUBD WHERE SUBD parent TOPD,' |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
342 |
' SUBD name "subd", TOPD name "topd"').rowcount) |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
343 |
|
11063
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
344 |
def test_subject_subentity_removal(self): |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
345 |
"""Editcontroller: detaching a composite relation removes the subentity |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
346 |
(edit from the subject side) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
347 |
""" |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
348 |
with self.admin_access.repo_cnx() as cnx: |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
349 |
topd = cnx.create_entity('Directory', name=u'topd') |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
350 |
sub1 = cnx.create_entity('Directory', name=u'sub1', parent=topd) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
351 |
sub2 = cnx.create_entity('Directory', name=u'sub2', parent=topd) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
352 |
cnx.commit() |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
353 |
|
11064
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
354 |
attrs = {'name-subject:%s' % sub1.eid: ''} |
113e9da47afc
[edit controller] Cancel RQL queries to be performed on entities to be deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11063
diff
changeset
|
355 |
self._edit_parent(sub1.eid, parent_eid=None, **attrs) |
11063
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
356 |
|
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
357 |
with self.admin_access.repo_cnx() as cnx: |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
358 |
self.assertTrue(cnx.find('Directory', eid=topd.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
359 |
self.assertFalse(cnx.find('Directory', eid=sub1.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
360 |
self.assertTrue(cnx.find('Directory', eid=sub2.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
361 |
|
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
362 |
def test_object_subentity_removal(self): |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
363 |
"""Editcontroller: detaching a composite relation removes the subentity |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
364 |
(edit from the object side) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
365 |
""" |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
366 |
with self.admin_access.repo_cnx() as cnx: |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
367 |
topd = cnx.create_entity('Directory', name=u'topd') |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
368 |
sub1 = cnx.create_entity('Directory', name=u'sub1', parent=topd) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
369 |
sub2 = cnx.create_entity('Directory', name=u'sub2', parent=topd) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
370 |
cnx.commit() |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
371 |
|
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
372 |
self._edit_parent(topd.eid, parent_eid=sub1.eid, role='object') |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
373 |
|
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
374 |
with self.admin_access.repo_cnx() as cnx: |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
375 |
self.assertTrue(cnx.find('Directory', eid=topd.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
376 |
self.assertTrue(cnx.find('Directory', eid=sub1.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
377 |
self.assertFalse(cnx.find('Directory', eid=sub2.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
378 |
|
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
379 |
def test_reparent_subentity(self): |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
380 |
"Editcontroller: re-parenting a subentity does not remove it" |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
381 |
with self.admin_access.repo_cnx() as cnx: |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
382 |
top1 = cnx.create_entity('Directory', name=u'top1') |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
383 |
top2 = cnx.create_entity('Directory', name=u'top2') |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
384 |
subd = cnx.create_entity('Directory', name=u'subd', parent=top1) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
385 |
cnx.commit() |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
386 |
|
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
387 |
self._edit_parent(subd.eid, parent_eid=top2.eid) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
388 |
|
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
389 |
with self.admin_access.repo_cnx() as cnx: |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
390 |
self.assertTrue(cnx.find('Directory', eid=top1.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
391 |
self.assertTrue(cnx.find('Directory', eid=top2.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
392 |
self.assertTrue(cnx.find('Directory', eid=subd.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
393 |
self.assertEqual( |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
394 |
cnx.find('Directory', eid=subd.eid).one().parent[0], top2) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
395 |
|
11066
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
396 |
def test_reparent_subentity_inlined(self): |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
397 |
"""Editcontroller: re-parenting a subentity does not remove it |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
398 |
(inlined case)""" |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
399 |
with self.admin_access.repo_cnx() as cnx: |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
400 |
version1 = cnx.create_entity('Version', name=u'version1') |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
401 |
version2 = cnx.create_entity('Version', name=u'version2') |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
402 |
ticket = cnx.create_entity('Ticket', title=u'ticket', |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
403 |
in_version=version1) |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
404 |
cnx.commit() |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
405 |
|
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
406 |
self._edit_in_version(ticket.eid, version_eid=version2.eid) |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
407 |
|
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
408 |
with self.admin_access.repo_cnx() as cnx: |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
409 |
self.assertTrue(cnx.find('Version', eid=version1.eid)) |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
410 |
self.assertTrue(cnx.find('Version', eid=version2.eid)) |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
411 |
self.assertTrue(cnx.find('Ticket', eid=ticket.eid)) |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
412 |
self.assertEqual( |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
413 |
cnx.find('Ticket', eid=ticket.eid).one().in_version[0], version2) |
dcbb64d3a1d9
[edit controller] Fix composite entity reparenting when inlined
Florent Cayré <florent.cayre@logilab.fr>
parents:
11065
diff
changeset
|
414 |
|
11063
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
415 |
def test_subject_mixed_composite_subentity_removal_1(self): |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
416 |
"""Editcontroller: detaching several subentities respects each rdef's |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
417 |
compositeness - Remove non composite |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
418 |
""" |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
419 |
with self.admin_access.repo_cnx() as cnx: |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
420 |
topd = cnx.create_entity('Directory', name=u'topd') |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
421 |
fs = cnx.create_entity('Filesystem', name=u'/tmp') |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
422 |
subd = cnx.create_entity('Directory', name=u'subd', |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
423 |
parent=(topd, fs)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
424 |
cnx.commit() |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
425 |
|
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
426 |
self._edit_parent(subd.eid, parent_eid=topd.eid) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
427 |
|
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
428 |
with self.admin_access.repo_cnx() as cnx: |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
429 |
self.assertTrue(cnx.find('Directory', eid=topd.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
430 |
self.assertTrue(cnx.find('Directory', eid=subd.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
431 |
self.assertTrue(cnx.find('Filesystem', eid=fs.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
432 |
self.assertEqual(cnx.find('Directory', eid=subd.eid).one().parent, |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
433 |
[topd,]) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
434 |
|
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
435 |
def test_subject_mixed_composite_subentity_removal_2(self): |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
436 |
"""Editcontroller: detaching several subentities respects each rdef's |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
437 |
compositeness - Remove composite |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
438 |
""" |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
439 |
with self.admin_access.repo_cnx() as cnx: |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
440 |
topd = cnx.create_entity('Directory', name=u'topd') |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
441 |
fs = cnx.create_entity('Filesystem', name=u'/tmp') |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
442 |
subd = cnx.create_entity('Directory', name=u'subd', |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
443 |
parent=(topd, fs)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
444 |
cnx.commit() |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
445 |
|
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
446 |
self._edit_parent(subd.eid, parent_eid=fs.eid) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
447 |
|
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
448 |
with self.admin_access.repo_cnx() as cnx: |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
449 |
self.assertTrue(cnx.find('Directory', eid=topd.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
450 |
self.assertFalse(cnx.find('Directory', eid=subd.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
451 |
self.assertTrue(cnx.find('Filesystem', eid=fs.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
452 |
|
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
453 |
def test_object_mixed_composite_subentity_removal_1(self): |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
454 |
"""Editcontroller: detaching several subentities respects each rdef's |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
455 |
compositeness - Remove non composite |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
456 |
""" |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
457 |
with self.admin_access.repo_cnx() as cnx: |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
458 |
topd = cnx.create_entity('Directory', name=u'topd') |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
459 |
fs = cnx.create_entity('Filesystem', name=u'/tmp') |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
460 |
subd = cnx.create_entity('Directory', name=u'subd', |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
461 |
parent=(topd, fs)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
462 |
cnx.commit() |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
463 |
|
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
464 |
self._edit_parent(fs.eid, parent_eid=None, role='object', |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
465 |
etype='Filesystem') |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
466 |
|
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
467 |
with self.admin_access.repo_cnx() as cnx: |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
468 |
self.assertTrue(cnx.find('Directory', eid=topd.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
469 |
self.assertTrue(cnx.find('Directory', eid=subd.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
470 |
self.assertTrue(cnx.find('Filesystem', eid=fs.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
471 |
self.assertEqual(cnx.find('Directory', eid=subd.eid).one().parent, |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
472 |
[topd,]) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
473 |
|
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
474 |
def test_object_mixed_composite_subentity_removal_2(self): |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
475 |
"""Editcontroller: detaching several subentities respects each rdef's |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
476 |
compositeness - Remove composite |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
477 |
""" |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
478 |
with self.admin_access.repo_cnx() as cnx: |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
479 |
topd = cnx.create_entity('Directory', name=u'topd') |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
480 |
fs = cnx.create_entity('Filesystem', name=u'/tmp') |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
481 |
subd = cnx.create_entity('Directory', name=u'subd', |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
482 |
parent=(topd, fs)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
483 |
cnx.commit() |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
484 |
|
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
485 |
self._edit_parent(topd.eid, parent_eid=None, role='object') |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
486 |
|
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
487 |
with self.admin_access.repo_cnx() as cnx: |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
488 |
self.assertTrue(cnx.find('Directory', eid=topd.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
489 |
self.assertFalse(cnx.find('Directory', eid=subd.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
490 |
self.assertTrue(cnx.find('Filesystem', eid=fs.eid)) |
de20b0903d7d
[edit controller] fix handling of removal of subentities from an edit form
Florent Cayré <florent.cayre@logilab.fr>
parents:
11062
diff
changeset
|
491 |
|
11065
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
492 |
def test_delete_mandatory_composite(self): |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
493 |
with self.admin_access.repo_cnx() as cnx: |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
494 |
perm = cnx.create_entity('DirectoryPermission') |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
495 |
mydir = cnx.create_entity('Directory', name=u'dir', |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
496 |
has_permission=perm) |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
497 |
cnx.commit() |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
498 |
|
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
499 |
with self.admin_access.web_request() as req: |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
500 |
dir_eid = unicode(mydir.eid) |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
501 |
perm_eid = unicode(perm.eid) |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
502 |
req.form = { |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
503 |
'eid': [dir_eid, perm_eid], |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
504 |
'__maineid' : dir_eid, |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
505 |
'__type:%s' % dir_eid: 'Directory', |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
506 |
'__type:%s' % perm_eid: 'DirectoryPermission', |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
507 |
'_cw_entity_fields:%s' % dir_eid: '', |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
508 |
'_cw_entity_fields:%s' % perm_eid: 'has_permission-object', |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
509 |
'has_permission-object:%s' % perm_eid: '', |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
510 |
} |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
511 |
path, _params = self.expect_redirect_handle_request(req, 'edit') |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
512 |
self.assertTrue(req.find('Directory', eid=mydir.eid)) |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
513 |
self.assertFalse(req.find('DirectoryPermission', eid=perm.eid)) |
c7dbd10648e6
[forms] Do not raise errors on composite required relation being deleted
Florent Cayré <florent.cayre@logilab.fr>
parents:
11064
diff
changeset
|
514 |
|
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
|
515 |
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
|
516 |
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
|
517 |
__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
|
518 |
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
|
519 |
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
|
520 |
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
|
521 |
with real_error_handling(self.app) as app: |
9641
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
522 |
with self.admin_access.web_request(vid='test.ajax.error') as req: |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
523 |
req.ajax_request = True |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
524 |
page = app.handle_request(req, '') |
10604
d4bf85db41f2
[py3k] import HTTP client constants and exceptions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10356
diff
changeset
|
525 |
self.assertEqual(http_client.INTERNAL_SERVER_ERROR, |
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
|
526 |
req.status_out) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
527 |
|
0 | 528 |
def _test_cleaned(self, kwargs, injected, cleaned): |
9641
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
529 |
with self.admin_access.web_request(**kwargs) as req: |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
530 |
page = self.app_handle_request(req, 'view') |
10735
cb83ba66fa61
[py3k] CubicWebTC.app_handle_request returns bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10734
diff
changeset
|
531 |
self.assertNotIn(injected.encode('ascii'), page) |
cb83ba66fa61
[py3k] CubicWebTC.app_handle_request returns bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10734
diff
changeset
|
532 |
self.assertIn(cleaned.encode('ascii'), page) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
533 |
|
0 | 534 |
def test_nonregr_script_kiddies(self): |
535 |
"""test against current script injection""" |
|
536 |
injected = '<i>toto</i>' |
|
537 |
cleaned = 'toto' |
|
10080
bc7c3b0f439b
[web] stop accepting the magic __message form parameter
Julien Cristau <julien.cristau@logilab.fr>
parents:
9882
diff
changeset
|
538 |
for kwargs in ({'vid': injected}, |
0 | 539 |
{'vtitle': injected}, |
540 |
): |
|
541 |
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
|
542 |
|
0 | 543 |
def test_site_wide_eproperties_sync(self): |
544 |
# XXX work in all-in-one configuration but not in twisted for instance |
|
545 |
# in which case we need a kindof repo -> http server notification |
|
546 |
# protocol |
|
547 |
vreg = self.app.vreg |
|
548 |
# 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
|
549 |
self.assertEqual(vreg.property_value('ui.language'), 'en') |
9641
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
550 |
with self.admin_access.client_cnx() as cnx: |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
551 |
cnx.execute('INSERT CWProperty X: X value "fr", X pkey "ui.language"') |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
552 |
self.assertEqual(vreg.property_value('ui.language'), 'en') |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
553 |
cnx.commit() |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
554 |
self.assertEqual(vreg.property_value('ui.language'), 'fr') |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
555 |
cnx.execute('SET X value "de" WHERE X pkey "ui.language"') |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
556 |
self.assertEqual(vreg.property_value('ui.language'), 'fr') |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
557 |
cnx.commit() |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
558 |
self.assertEqual(vreg.property_value('ui.language'), 'de') |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
559 |
cnx.execute('DELETE CWProperty X WHERE X pkey "ui.language"') |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
560 |
self.assertEqual(vreg.property_value('ui.language'), 'de') |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
561 |
cnx.commit() |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
562 |
self.assertEqual(vreg.property_value('ui.language'), 'en') |
0 | 563 |
|
564 |
# authentication tests #################################################### |
|
565 |
||
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
566 |
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
|
567 |
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
|
568 |
self.assertAuthFailure(req) |
9017
aa709bc6b6c1
[application/connect] simplify connection logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8695
diff
changeset
|
569 |
self.app.handle_request(req, 'login') |
aa709bc6b6c1
[application/connect] simplify connection logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8695
diff
changeset
|
570 |
self.assertEqual(401, req.status_out) |
aa709bc6b6c1
[application/connect] simplify connection logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8695
diff
changeset
|
571 |
clear_cache(req, 'get_authorization') |
10779
6cef304aca4c
[web] base64 works on bytes not str (py3k)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10735
diff
changeset
|
572 |
authstr = base64.encodestring(('%s:%s' % (self.admlogin, self.admpassword)).encode('ascii')) |
6cef304aca4c
[web] base64 works on bytes not str (py3k)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10735
diff
changeset
|
573 |
req.set_request_header('Authorization', 'basic %s' % authstr.decode('ascii')) |
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
|
574 |
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
|
575 |
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
|
576 |
self.assertEqual(len(self.open_sessions), 0) |
0 | 577 |
|
578 |
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
|
579 |
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
|
580 |
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
|
581 |
try: |
9017
aa709bc6b6c1
[application/connect] simplify connection logic
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8695
diff
changeset
|
582 |
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
|
583 |
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
|
584 |
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
|
585 |
clear_cache(req, 'get_authorization') |
10780
a96ed0acc556
[web/test] CubicWebPublisher.handle_request returns bytes
Julien Cristau <julien.cristau@logilab.fr>
parents:
10779
diff
changeset
|
586 |
self.assertIn(b'__login', form) |
a96ed0acc556
[web/test] CubicWebPublisher.handle_request returns bytes
Julien Cristau <julien.cristau@logilab.fr>
parents:
10779
diff
changeset
|
587 |
self.assertIn(b'__password', form) |
9039
488255d1cf3b
[testlib] rework request building in init_authentication
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9019
diff
changeset
|
588 |
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
|
589 |
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
|
590 |
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
|
591 |
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
|
592 |
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
|
593 |
self.assertEqual(len(self.open_sessions), 0) |
0 | 594 |
|
1490
6b024694d493
add allow-email-login option
Florent <florent@secondweb.fr>
parents:
1489
diff
changeset
|
595 |
def test_login_by_email(self): |
9641
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
596 |
with self.admin_access.client_cnx() as cnx: |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
597 |
login = cnx.user.login |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
598 |
address = login + u'@localhost' |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
599 |
cnx.execute('INSERT EmailAddress X: X address %(address)s, U primary_email X ' |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
600 |
'WHERE U login %(login)s', {'address': address, 'login': login}) |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
601 |
cnx.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
|
602 |
# # 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
|
603 |
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
|
604 |
# 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
|
605 |
# 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
|
606 |
# self.assertAuthFailure(req) |
1490
6b024694d493
add allow-email-login option
Florent <florent@secondweb.fr>
parents:
1489
diff
changeset
|
607 |
# 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
|
608 |
#origsession.login = address |
1490
6b024694d493
add allow-email-login option
Florent <florent@secondweb.fr>
parents:
1489
diff
changeset
|
609 |
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
|
610 |
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
|
611 |
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
|
612 |
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
|
613 |
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
|
614 |
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
|
615 |
|
0 | 616 |
def _reset_cookie(self, req): |
617 |
# preparing the suite of the test |
|
618 |
# set session id in cookie |
|
10605
61521bee2b68
[py3k] import SimpleCookie using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10604
diff
changeset
|
619 |
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
|
620 |
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
|
621 |
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
|
622 |
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
|
623 |
raw=True) |
0 | 624 |
clear_cache(req, 'get_authorization') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
625 |
|
3657
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
626 |
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
|
627 |
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
|
628 |
# important otherwise _reset_cookie will not use the right session |
10356
a009a31fb1ea
[connection] eliminate ClientConnection leftovers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10331
diff
changeset
|
629 |
req.set_cnx(repoapi.Connection(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
|
630 |
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
|
631 |
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
|
632 |
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
|
633 |
self._reset_cookie(req) |
706d7bf0ae3d
factor out code reusable for authentication tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3524
diff
changeset
|
634 |
|
0 | 635 |
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
|
636 |
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
|
637 |
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
|
638 |
# important otherwise _reset_cookie will not use the right session |
10356
a009a31fb1ea
[connection] eliminate ClientConnection leftovers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10331
diff
changeset
|
639 |
req.set_cnx(repoapi.Connection(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
|
640 |
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
|
641 |
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
|
642 |
self.assertEqual(1, len(self.open_sessions)) |
0 | 643 |
self._reset_cookie(req) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
644 |
|
0 | 645 |
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
|
646 |
req, origsession = self.init_authentication('http', 'anon') |
0 | 647 |
self._test_auth_anon(req) |
10779
6cef304aca4c
[web] base64 works on bytes not str (py3k)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10735
diff
changeset
|
648 |
authstr = base64.encodestring(b'toto:pouet') |
6cef304aca4c
[web] base64 works on bytes not str (py3k)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10735
diff
changeset
|
649 |
req.set_request_header('Authorization', 'basic %s' % authstr.decode('ascii')) |
0 | 650 |
self._test_anon_auth_fail(req) |
10779
6cef304aca4c
[web] base64 works on bytes not str (py3k)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10735
diff
changeset
|
651 |
authstr = base64.encodestring(('%s:%s' % (self.admlogin, self.admpassword)).encode('ascii')) |
6cef304aca4c
[web] base64 works on bytes not str (py3k)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10735
diff
changeset
|
652 |
req.set_request_header('Authorization', 'basic %s' % authstr.decode('ascii')) |
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
|
653 |
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
|
654 |
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
|
655 |
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
|
656 |
|
0 | 657 |
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
|
658 |
req, origsession = self.init_authentication('cookie', 'anon') |
0 | 659 |
self._test_auth_anon(req) |
660 |
req.form['__login'] = 'toto' |
|
661 |
req.form['__password'] = 'pouet' |
|
662 |
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
|
663 |
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
|
664 |
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
|
665 |
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
|
666 |
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
|
667 |
self.assertEqual(0, len(self.open_sessions)) |
0 | 668 |
|
7876
df15d194a134
[views] implement json / jsonp export views (closes #1942658)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
669 |
def test_anonymized_request(self): |
9641
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
670 |
with self.admin_access.web_request() as req: |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
671 |
self.assertEqual(self.admlogin, req.session.user.login) |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
672 |
# admin should see anon + admin |
9642
9a42eaeea263
[web/test] avoid deprecation warnings from find_entities()
Julien Cristau <julien.cristau@logilab.fr>
parents:
9641
diff
changeset
|
673 |
self.assertEqual(2, len(list(req.find('CWUser')))) |
9641
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
674 |
with anonymized_request(req): |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
675 |
self.assertEqual('anon', req.session.login, 'anon') |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
676 |
# anon should only see anon user |
9642
9a42eaeea263
[web/test] avoid deprecation warnings from find_entities()
Julien Cristau <julien.cristau@logilab.fr>
parents:
9641
diff
changeset
|
677 |
self.assertEqual(1, len(list(req.find('CWUser')))) |
9641
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
678 |
self.assertEqual(self.admlogin, req.session.login) |
9642
9a42eaeea263
[web/test] avoid deprecation warnings from find_entities()
Julien Cristau <julien.cristau@logilab.fr>
parents:
9641
diff
changeset
|
679 |
self.assertEqual(2, len(list(req.find('CWUser')))) |
7876
df15d194a134
[views] implement json / jsonp export views (closes #1942658)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7791
diff
changeset
|
680 |
|
3523
16880e7ee3fa
don't accept None to avoid error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3265
diff
changeset
|
681 |
def test_non_regr_optional_first_var(self): |
9641
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
682 |
with self.admin_access.web_request() as req: |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
683 |
# expect a rset with None in [0][0] |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
684 |
req.form['rql'] = 'rql:Any OV1, X WHERE X custom_workflow OV1?' |
4147cc32371d
[web/test] port unittest_application to new 3.19 API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9478
diff
changeset
|
685 |
self.app_handle_request(req) |
0 | 686 |
|
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
|
687 |
|
0 | 688 |
if __name__ == '__main__': |
689 |
unittest_main() |