cubicweb/web/test/unittest_views_editforms.py
changeset 11129 97095348b3ee
parent 11100 5758ba784ebd
parent 11057 0b59724cb3f2
child 11151 4259c55df3e7
--- a/cubicweb/web/test/unittest_views_editforms.py	Thu Feb 11 21:59:49 2016 +0100
+++ b/cubicweb/web/test/unittest_views_editforms.py	Wed Feb 17 13:45:34 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 <http://www.gnu.org/licenses/>.
+
 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)