diff -r 13c9cd75f097 -r 5758ba784ebd web/test/unittest_views_editforms.py --- a/web/test/unittest_views_editforms.py Fri Feb 05 12:26:28 2016 +0100 +++ b/web/test/unittest_views_editforms.py Thu Feb 04 12:00:23 2016 +0100 @@ -15,7 +15,9 @@ # # You should have received a copy of the GNU Lesser General Public License along # with CubicWeb. If not, see . + from logilab.common.testlib import unittest_main, mock_object +from logilab.common import tempattr from cubicweb.devtools.testlib import CubicWebTC from cubicweb.web.views import uicfg @@ -181,6 +183,22 @@ autoform = self.vreg['forms'].select('edition', req, entity=req.user) self.assertEqual(list(autoform.inlined_form_views()), []) + def test_inlined_form_views(self): + # when some relation has + cardinality, and some already linked entities which are not + # updatable, a link to optionally add a new sub-entity should be displayed, not a sub-form + # forcing creation of a sub-entity + from cubicweb.web.views import autoform + with self.admin_access.web_request() as req: + req.create_entity('EmailAddress', address=u'admin@cubicweb.org', + reverse_use_email=req.user.eid) + use_email_schema = self.vreg.schema['CWUser'].rdef('use_email') + with tempattr(use_email_schema, 'cardinality', '+1'): + with self.temporary_permissions(EmailAddress={'update': ()}): + form = self.vreg['forms'].select('edition', req, entity=req.user) + formviews = list(form.inlined_form_views()) + self.assertEqual(len(formviews), 1, formviews) + self.assertIsInstance(formviews[0], autoform.InlineAddNewLinkView) + def test_check_inlined_rdef_permissions(self): # try to check permissions when creating an entity ('user' below is a # fresh entity without an eid)