author | Julien Cristau <julien.cristau@logilab.fr> |
Mon, 09 Nov 2015 15:29:07 +0100 | |
changeset 10871 | 1d4a94d04ec6 |
parent 10519 | 0019b7888dd7 |
permissions | -rw-r--r-- |
9873
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
1 |
# copyright 2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
3 |
# |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
4 |
# This file is part of CubicWeb. |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
5 |
# |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
9 |
# any later version. |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
10 |
# |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
14 |
# details. |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
15 |
# |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
18 |
|
10519
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
19 |
from logilab.common import tempattr, attrdict |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
20 |
|
9873
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
21 |
from cubicweb.devtools.testlib import CubicWebTC |
10519
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
22 |
from cubicweb.web.views.autoform import InlinedFormField |
9873
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
23 |
|
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
24 |
class InlinedFormTC(CubicWebTC): |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
25 |
|
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
26 |
def test_linked_to(self): |
10088
ac63f7ec5af0
[test/view forms] use the official, undeprecated API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9873
diff
changeset
|
27 |
with self.admin_access.web_request() as req: |
ac63f7ec5af0
[test/view forms] use the official, undeprecated API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9873
diff
changeset
|
28 |
formview = req.vreg['views'].select( |
ac63f7ec5af0
[test/view forms] use the official, undeprecated API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9873
diff
changeset
|
29 |
'inline-creation', req, |
ac63f7ec5af0
[test/view forms] use the official, undeprecated API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9873
diff
changeset
|
30 |
etype='File', rtype='described_by_test', role='subject', |
ac63f7ec5af0
[test/view forms] use the official, undeprecated API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9873
diff
changeset
|
31 |
peid=123, |
ac63f7ec5af0
[test/view forms] use the official, undeprecated API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9873
diff
changeset
|
32 |
petype='Salesterm') |
ac63f7ec5af0
[test/view forms] use the official, undeprecated API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9873
diff
changeset
|
33 |
self.assertEqual({('described_by_test', 'object'): [123]}, |
ac63f7ec5af0
[test/view forms] use the official, undeprecated API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9873
diff
changeset
|
34 |
formview.form.linked_to) |
9873
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
35 |
|
10142
f4a4556f23da
[views/forms] Fix EntityFieldsForm.link_to when parent entity is being created
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10088
diff
changeset
|
36 |
def test_linked_to_parent_being_created(self): |
f4a4556f23da
[views/forms] Fix EntityFieldsForm.link_to when parent entity is being created
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10088
diff
changeset
|
37 |
with self.admin_access.web_request() as req: |
f4a4556f23da
[views/forms] Fix EntityFieldsForm.link_to when parent entity is being created
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10088
diff
changeset
|
38 |
formview = req.vreg['views'].select( |
f4a4556f23da
[views/forms] Fix EntityFieldsForm.link_to when parent entity is being created
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10088
diff
changeset
|
39 |
'inline-creation', req, |
f4a4556f23da
[views/forms] Fix EntityFieldsForm.link_to when parent entity is being created
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10088
diff
changeset
|
40 |
etype='File', rtype='described_by_test', role='subject', |
f4a4556f23da
[views/forms] Fix EntityFieldsForm.link_to when parent entity is being created
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10088
diff
changeset
|
41 |
peid='A', |
f4a4556f23da
[views/forms] Fix EntityFieldsForm.link_to when parent entity is being created
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10088
diff
changeset
|
42 |
petype='Salesterm') |
f4a4556f23da
[views/forms] Fix EntityFieldsForm.link_to when parent entity is being created
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10088
diff
changeset
|
43 |
self.assertEqual(formview.form.linked_to, {}) |
f4a4556f23da
[views/forms] Fix EntityFieldsForm.link_to when parent entity is being created
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10088
diff
changeset
|
44 |
|
10519
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
45 |
def test_remove_js_depending_on_cardinality(self): |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
46 |
with self.admin_access.web_request() as req: |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
47 |
formview = req.vreg['views'].select( |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
48 |
'inline-creation', req, |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
49 |
etype='File', rtype='described_by_test', role='subject', |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
50 |
peid='A', |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
51 |
petype='Salesterm') |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
52 |
# cardinality is 1, can't remove |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
53 |
self.assertIsNone(formview._get_removejs()) |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
54 |
rdef = self.schema['Salesterm'].rdef('described_by_test') |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
55 |
with tempattr(rdef, 'cardinality', '?*'): |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
56 |
self.assertTrue(formview._get_removejs()) |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
57 |
with tempattr(rdef, 'cardinality', '+*'): |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
58 |
# formview has no parent info (pform). This is what happens |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
59 |
# when an inline form is requested through AJAX. |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
60 |
self.assertTrue(formview._get_removejs()) |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
61 |
fakeview = attrdict(dict(rtype='described_by_test', role='subject')) |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
62 |
# formview is first, can't be removed |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
63 |
formview.pform = attrdict(fields=[InlinedFormField(view=formview), |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
64 |
InlinedFormField(view=fakeview)]) |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
65 |
self.assertIsNone(formview._get_removejs()) |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
66 |
# formview isn't first, can be removed |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
67 |
formview.pform = attrdict(fields=[InlinedFormField(view=fakeview), |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
68 |
InlinedFormField(view=formview)]) |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
69 |
self.assertTrue(formview._get_removejs()) |
0019b7888dd7
[forms] don't display 'remove' link of inlined form for the first entity related using a '+' cardinality to its parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10142
diff
changeset
|
70 |
|
10142
f4a4556f23da
[views/forms] Fix EntityFieldsForm.link_to when parent entity is being created
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10088
diff
changeset
|
71 |
|
9873
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
72 |
if __name__ == '__main__': |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
73 |
from logilab.common.testlib import unittest_main |
1257e909d25e
[forms] consider inline creation form information as linkto info. Closes #3161121
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
74 |
unittest_main() |