13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
14 # details. |
14 # details. |
15 # |
15 # |
16 # You should have received a copy of the GNU Lesser General Public License along |
16 # You should have received a copy of the GNU Lesser General Public License along |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
|
18 |
18 from logilab.common.testlib import unittest_main, mock_object |
19 from logilab.common.testlib import unittest_main, mock_object |
|
20 from logilab.common import tempattr |
19 |
21 |
20 from cubicweb.devtools.testlib import CubicWebTC |
22 from cubicweb.devtools.testlib import CubicWebTC |
21 from cubicweb.web.views import uicfg |
23 from cubicweb.web.views import uicfg |
22 from cubicweb.web.formwidgets import AutoCompletionWidget |
24 from cubicweb.web.formwidgets import AutoCompletionWidget |
23 from cubicweb.schema import RRQLExpression |
25 from cubicweb.schema import RRQLExpression |
179 with self.admin_access.web_request() as req: |
181 with self.admin_access.web_request() as req: |
180 with self.temporary_permissions(EmailAddress={'add': ()}): |
182 with self.temporary_permissions(EmailAddress={'add': ()}): |
181 autoform = self.vreg['forms'].select('edition', req, entity=req.user) |
183 autoform = self.vreg['forms'].select('edition', req, entity=req.user) |
182 self.assertEqual(list(autoform.inlined_form_views()), []) |
184 self.assertEqual(list(autoform.inlined_form_views()), []) |
183 |
185 |
|
186 def test_inlined_form_views(self): |
|
187 # when some relation has + cardinality, and some already linked entities which are not |
|
188 # updatable, a link to optionally add a new sub-entity should be displayed, not a sub-form |
|
189 # forcing creation of a sub-entity |
|
190 from cubicweb.web.views import autoform |
|
191 with self.admin_access.web_request() as req: |
|
192 req.create_entity('EmailAddress', address=u'admin@cubicweb.org', |
|
193 reverse_use_email=req.user.eid) |
|
194 use_email_schema = self.vreg.schema['CWUser'].rdef('use_email') |
|
195 with tempattr(use_email_schema, 'cardinality', '+1'): |
|
196 with self.temporary_permissions(EmailAddress={'update': ()}): |
|
197 form = self.vreg['forms'].select('edition', req, entity=req.user) |
|
198 formviews = list(form.inlined_form_views()) |
|
199 self.assertEqual(len(formviews), 1, formviews) |
|
200 self.assertIsInstance(formviews[0], autoform.InlineAddNewLinkView) |
|
201 |
184 def test_check_inlined_rdef_permissions(self): |
202 def test_check_inlined_rdef_permissions(self): |
185 # try to check permissions when creating an entity ('user' below is a |
203 # try to check permissions when creating an entity ('user' below is a |
186 # fresh entity without an eid) |
204 # fresh entity without an eid) |
187 with self.admin_access.web_request() as req: |
205 with self.admin_access.web_request() as req: |
188 ttype = 'EmailAddress' |
206 ttype = 'EmailAddress' |