cubicweb/web/test/unittest_views_editforms.py
author Laurent Peuch <cortex@worlddomination.be>
Thu, 21 Feb 2019 18:56:42 +0100
changeset 12399 c0ad7aa36e4a
parent 12091 3c9e296f0a6a
child 12677 9f03df82f8de
permissions -rw-r--r--
[doc] misc, put every reference to something in the code between backquotes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
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: 4758
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: 4758
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: 4758
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: 4758
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: 4758
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: 4758
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: 4758
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: 4758
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: 4758
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: 4758
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: 4758
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: 4758
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: 4758
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: 4758
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: 4758
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
11100
5758ba784ebd [autoform] when building inlined-form view for a relation, consider related entities intead of other views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10907
diff changeset
    18
3930
c0ae3148b893 fix test: required to fake parent form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3771
diff changeset
    19
from logilab.common.testlib import unittest_main, mock_object
11100
5758ba784ebd [autoform] when building inlined-form view for a relation, consider related entities intead of other views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10907
diff changeset
    20
from logilab.common import tempattr
3722
c414f402cbff 2.4 compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589
diff changeset
    21
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    22
from cubicweb.devtools.testlib import CubicWebTC
11964
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
    23
from cubicweb.predicates import is_instance
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    24
from cubicweb.web.views import uicfg
11964
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
    25
from cubicweb.web.views.editforms import DeleteConfFormView
1359
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    26
from cubicweb.web.formwidgets import AutoCompletionWidget
10637
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
    27
from cubicweb.schema import RRQLExpression
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
    28
3722
c414f402cbff 2.4 compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589
diff changeset
    29
4080
f88331eb374c test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3998
diff changeset
    30
AFFK = uicfg.autoform_field_kwargs
f88331eb374c test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3998
diff changeset
    31
AFS = uicfg.autoform_section
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    32
11170
d034791621ad pep8 unittest_application and unittest_formfields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11151
diff changeset
    33
4080
f88331eb374c test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3998
diff changeset
    34
def rbc(entity, formtype, section):
4570
ede247bbbf62 follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    35
    if section in ('attributes', 'metadata', 'hidden'):
ede247bbbf62 follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    36
        permission = 'update'
ede247bbbf62 follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    37
    else:
ede247bbbf62 follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    38
        permission = 'add'
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    39
    return [(rschema.type, x)
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    40
            for rschema, tschemas, x in AFS.relations_by_section(entity,
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    41
                                                                 formtype,
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    42
                                                                 section,
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    43
                                                                 permission)]
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    44
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    45
class AutomaticEntityFormTC(CubicWebTC):
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    46
1359
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    47
    def test_custom_widget(self):
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    48
        with self.admin_access.web_request() as req:
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    49
            AFFK.tag_subject_of(('CWUser', 'login', '*'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    50
                                {'widget': AutoCompletionWidget(autocomplete_initfunc='get_logins')})
10241
9d2f53777430 [web/test] fix 3.19 deprecation warning
Julien Cristau <julien.cristau@logilab.fr>
parents: 9990
diff changeset
    51
            form = self.vreg['forms'].select('edition', req, entity=req.user)
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    52
            field = form.field_by_name('login', 'subject')
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    53
            self.assertIsInstance(field.widget, AutoCompletionWidget)
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    54
            AFFK.del_rtag('CWUser', 'login', '*', 'subject')
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    55
1359
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    56
2637
07103211e511 R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2058
diff changeset
    57
    def test_cwuser_relations_by_category(self):
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    58
        with self.admin_access.web_request() as req:
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    59
            e = self.vreg['etypes'].etype_class('CWUser')(req)
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    60
            # see custom configuration in views.cwuser
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    61
            self.assertEqual(rbc(e, 'main', 'attributes'),
10243
60789eabc3b7 [web/test] don't depend on dict iteration ordering
Julien Cristau <julien.cristau@logilab.fr>
parents: 10242
diff changeset
    62
                             [('login', 'subject'),
60789eabc3b7 [web/test] don't depend on dict iteration ordering
Julien Cristau <julien.cristau@logilab.fr>
parents: 10242
diff changeset
    63
                              ('upassword', 'subject'),
60789eabc3b7 [web/test] don't depend on dict iteration ordering
Julien Cristau <julien.cristau@logilab.fr>
parents: 10242
diff changeset
    64
                              ('firstname', 'subject'),
60789eabc3b7 [web/test] don't depend on dict iteration ordering
Julien Cristau <julien.cristau@logilab.fr>
parents: 10242
diff changeset
    65
                              ('surname', 'subject'),
60789eabc3b7 [web/test] don't depend on dict iteration ordering
Julien Cristau <julien.cristau@logilab.fr>
parents: 10242
diff changeset
    66
                              ('in_group', 'subject'),
60789eabc3b7 [web/test] don't depend on dict iteration ordering
Julien Cristau <julien.cristau@logilab.fr>
parents: 10242
diff changeset
    67
                              ])
60789eabc3b7 [web/test] don't depend on dict iteration ordering
Julien Cristau <julien.cristau@logilab.fr>
parents: 10242
diff changeset
    68
            self.assertEqual(rbc(e, 'muledit', 'attributes'),
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    69
                                  [('login', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    70
                                   ('upassword', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    71
                                   ('in_group', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    72
                                   ])
10243
60789eabc3b7 [web/test] don't depend on dict iteration ordering
Julien Cristau <julien.cristau@logilab.fr>
parents: 10242
diff changeset
    73
            self.assertCountEqual(rbc(e, 'main', 'metadata'),
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    74
                                  [('last_login_time', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    75
                                   ('cw_source', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    76
                                   ('creation_date', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    77
                                   ('modification_date', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    78
                                   ('created_by', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    79
                                   ('owned_by', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    80
                                   ('bookmarked_by', 'object'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    81
                                   ])
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    82
            # XXX skip 'tags' relation here and in the hidden category because
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    83
            # of some test interdependancy when pytest is launched on whole cw
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    84
            # (appears here while expected in hidden
10243
60789eabc3b7 [web/test] don't depend on dict iteration ordering
Julien Cristau <julien.cristau@logilab.fr>
parents: 10242
diff changeset
    85
            self.assertCountEqual([x for x in rbc(e, 'main', 'relations')
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    86
                                   if x != ('tags', 'object')],
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    87
                                  [('connait', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    88
                                   ('custom_workflow', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    89
                                   ('primary_email', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    90
                                   ('checked_by', 'object'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    91
                                   ])
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    92
            self.assertListEqual(rbc(e, 'main', 'inlined'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    93
                                  [('use_email', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    94
                                   ])
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    95
            # owned_by is defined both as subject and object relations on CWUser
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    96
            self.assertListEqual(sorted(x for x in rbc(e, 'main', 'hidden')
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    97
                                         if x != ('tags', 'object')),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    98
                                  sorted([('for_user', 'object'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    99
                                          ('created_by', 'object'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   100
                                          ('wf_info_for', 'object'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   101
                                          ('owned_by', 'object'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   102
                                          ]))
1298
ca02a2b5e9be test inlined rtags
sylvain.thenault@logilab.fr
parents: 1287
diff changeset
   103
ca02a2b5e9be test inlined rtags
sylvain.thenault@logilab.fr
parents: 1287
diff changeset
   104
    def test_inlined_view(self):
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   105
        self.assertIn('main_inlined',
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   106
                      AFS.etype_get('CWUser', 'use_email', 'subject', 'EmailAddress'))
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   107
        self.assertNotIn('main_inlined',
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   108
                         AFS.etype_get('CWUser', 'primary_email', 'subject', 'EmailAddress'))
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   109
        self.assertIn('main_relations',
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   110
                      AFS.etype_get('CWUser', 'primary_email', 'subject', 'EmailAddress'))
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   111
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
   112
    def test_personne_relations_by_category(self):
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   113
        with self.admin_access.web_request() as req:
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   114
            e = self.vreg['etypes'].etype_class('Personne')(req)
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   115
            self.assertListEqual(rbc(e, 'main', 'attributes'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   116
                                  [('nom', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   117
                                   ('prenom', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   118
                                   ('sexe', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   119
                                   ('promo', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   120
                                   ('titre', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   121
                                   ('ass', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   122
                                   ('web', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   123
                                   ('tel', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   124
                                   ('fax', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   125
                                   ('datenaiss', 'subject'),
11240
1694e6e9ff94 [forms] Fix edition of TZDatetime attributes
Florent Cayré <florent.cayre@logilab.fr>
parents: 11170
diff changeset
   126
                                   ('tzdatenaiss', 'subject'),
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   127
                                   ('test', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   128
                                   ('description', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   129
                                   ('salary', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   130
                                   ])
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   131
            self.assertListEqual(rbc(e, 'muledit', 'attributes'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   132
                                  [('nom', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   133
                                   ])
10243
60789eabc3b7 [web/test] don't depend on dict iteration ordering
Julien Cristau <julien.cristau@logilab.fr>
parents: 10242
diff changeset
   134
            self.assertCountEqual(rbc(e, 'main', 'metadata'),
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   135
                                  [('cw_source', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   136
                                   ('creation_date', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   137
                                   ('modification_date', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   138
                                   ('created_by', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   139
                                   ('owned_by', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   140
                                   ])
10243
60789eabc3b7 [web/test] don't depend on dict iteration ordering
Julien Cristau <julien.cristau@logilab.fr>
parents: 10242
diff changeset
   141
            self.assertCountEqual(rbc(e, 'main', 'relations'),
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   142
                                  [('travaille', 'subject'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   143
                                   ('manager', 'object'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   144
                                   ('connait', 'object'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   145
                                   ])
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   146
            self.assertListEqual(rbc(e, 'main', 'hidden'),
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   147
                                  [])
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   148
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   149
    def test_edition_form(self):
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   150
        with self.admin_access.web_request() as req:
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   151
            rset = req.execute('CWUser X LIMIT 1')
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   152
            form = self.vreg['forms'].select('edition', req, rset=rset, row=0, col=0)
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   153
            # should be also selectable by specifying entity
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   154
            self.vreg['forms'].select('edition', req, entity=rset.get_entity(0, 0))
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   155
            self.assertFalse(any(f for f in form.fields if f is None))
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   156
10223
fbb370195199 [web/views] Honor 'action' attribute on AutomaticEntityForm, closes #4943392
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9984
diff changeset
   157
    def test_edition_form_with_action(self):
fbb370195199 [web/views] Honor 'action' attribute on AutomaticEntityForm, closes #4943392
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9984
diff changeset
   158
        with self.admin_access.web_request() as req:
fbb370195199 [web/views] Honor 'action' attribute on AutomaticEntityForm, closes #4943392
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9984
diff changeset
   159
            rset = req.execute('CWUser X LIMIT 1')
fbb370195199 [web/views] Honor 'action' attribute on AutomaticEntityForm, closes #4943392
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9984
diff changeset
   160
            form = self.vreg['forms'].select('edition', req, rset=rset, row=0,
fbb370195199 [web/views] Honor 'action' attribute on AutomaticEntityForm, closes #4943392
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9984
diff changeset
   161
                                             col=0, action='my_custom_action')
fbb370195199 [web/views] Honor 'action' attribute on AutomaticEntityForm, closes #4943392
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9984
diff changeset
   162
            self.assertEqual(form.form_action(), 'my_custom_action')
fbb370195199 [web/views] Honor 'action' attribute on AutomaticEntityForm, closes #4943392
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9984
diff changeset
   163
9976
457efde98629 [views] Display attributes in entity creation form based on "add" permission
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9842
diff changeset
   164
    def test_attribute_add_permissions(self):
457efde98629 [views] Display attributes in entity creation form based on "add" permission
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9842
diff changeset
   165
        # https://www.cubicweb.org/ticket/4342844
457efde98629 [views] Display attributes in entity creation form based on "add" permission
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9842
diff changeset
   166
        with self.admin_access.repo_cnx() as cnx:
10242
3efd572a137a [web/test] pass login as unicode string
Julien Cristau <julien.cristau@logilab.fr>
parents: 10241
diff changeset
   167
            self.create_user(cnx, u'toto')
9976
457efde98629 [views] Display attributes in entity creation form based on "add" permission
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9842
diff changeset
   168
            cnx.commit()
10242
3efd572a137a [web/test] pass login as unicode string
Julien Cristau <julien.cristau@logilab.fr>
parents: 10241
diff changeset
   169
        with self.new_access(u'toto').web_request() as req:
9976
457efde98629 [views] Display attributes in entity creation form based on "add" permission
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9842
diff changeset
   170
            e = self.vreg['etypes'].etype_class('Personne')(req)
457efde98629 [views] Display attributes in entity creation form based on "add" permission
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9842
diff changeset
   171
            cform = self.vreg['forms'].select('edition', req, entity=e)
457efde98629 [views] Display attributes in entity creation form based on "add" permission
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9842
diff changeset
   172
            self.assertIn('sexe',
457efde98629 [views] Display attributes in entity creation form based on "add" permission
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9842
diff changeset
   173
                          [rschema.type
457efde98629 [views] Display attributes in entity creation form based on "add" permission
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9842
diff changeset
   174
                           for rschema, _ in cform.editable_attributes()])
10242
3efd572a137a [web/test] pass login as unicode string
Julien Cristau <julien.cristau@logilab.fr>
parents: 10241
diff changeset
   175
            with self.new_access(u'toto').repo_cnx() as cnx:
9976
457efde98629 [views] Display attributes in entity creation form based on "add" permission
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9842
diff changeset
   176
                person_eid = cnx.create_entity('Personne', nom=u'Robert').eid
457efde98629 [views] Display attributes in entity creation form based on "add" permission
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9842
diff changeset
   177
                cnx.commit()
457efde98629 [views] Display attributes in entity creation form based on "add" permission
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9842
diff changeset
   178
            person = req.entity_from_eid(person_eid)
457efde98629 [views] Display attributes in entity creation form based on "add" permission
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9842
diff changeset
   179
            mform = self.vreg['forms'].select('edition', req, entity=person)
457efde98629 [views] Display attributes in entity creation form based on "add" permission
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9842
diff changeset
   180
            self.assertNotIn('sexe',
457efde98629 [views] Display attributes in entity creation form based on "add" permission
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9842
diff changeset
   181
                             [rschema.type
457efde98629 [views] Display attributes in entity creation form based on "add" permission
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9842
diff changeset
   182
                              for rschema, _ in mform.editable_attributes()])
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   183
10634
06a43f727601 [web/views] avoid propagation of NoSelectableObject in some case of inlined relations / permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10386
diff changeset
   184
    def test_inlined_relations(self):
06a43f727601 [web/views] avoid propagation of NoSelectableObject in some case of inlined relations / permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10386
diff changeset
   185
        with self.admin_access.web_request() as req:
06a43f727601 [web/views] avoid propagation of NoSelectableObject in some case of inlined relations / permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10386
diff changeset
   186
            with self.temporary_permissions(EmailAddress={'add': ()}):
06a43f727601 [web/views] avoid propagation of NoSelectableObject in some case of inlined relations / permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10386
diff changeset
   187
                autoform = self.vreg['forms'].select('edition', req, entity=req.user)
06a43f727601 [web/views] avoid propagation of NoSelectableObject in some case of inlined relations / permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10386
diff changeset
   188
                self.assertEqual(list(autoform.inlined_form_views()), [])
06a43f727601 [web/views] avoid propagation of NoSelectableObject in some case of inlined relations / permissions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10386
diff changeset
   189
11100
5758ba784ebd [autoform] when building inlined-form view for a relation, consider related entities intead of other views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10907
diff changeset
   190
    def test_inlined_form_views(self):
5758ba784ebd [autoform] when building inlined-form view for a relation, consider related entities intead of other views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10907
diff changeset
   191
        # when some relation has + cardinality, and some already linked entities which are not
5758ba784ebd [autoform] when building inlined-form view for a relation, consider related entities intead of other views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10907
diff changeset
   192
        # updatable, a link to optionally add a new sub-entity should be displayed, not a sub-form
5758ba784ebd [autoform] when building inlined-form view for a relation, consider related entities intead of other views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10907
diff changeset
   193
        # forcing creation of a sub-entity
5758ba784ebd [autoform] when building inlined-form view for a relation, consider related entities intead of other views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10907
diff changeset
   194
        from cubicweb.web.views import autoform
5758ba784ebd [autoform] when building inlined-form view for a relation, consider related entities intead of other views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10907
diff changeset
   195
        with self.admin_access.web_request() as req:
5758ba784ebd [autoform] when building inlined-form view for a relation, consider related entities intead of other views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10907
diff changeset
   196
            req.create_entity('EmailAddress', address=u'admin@cubicweb.org',
5758ba784ebd [autoform] when building inlined-form view for a relation, consider related entities intead of other views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10907
diff changeset
   197
                              reverse_use_email=req.user.eid)
5758ba784ebd [autoform] when building inlined-form view for a relation, consider related entities intead of other views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10907
diff changeset
   198
            use_email_schema = self.vreg.schema['CWUser'].rdef('use_email')
5758ba784ebd [autoform] when building inlined-form view for a relation, consider related entities intead of other views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10907
diff changeset
   199
            with tempattr(use_email_schema, 'cardinality', '+1'):
5758ba784ebd [autoform] when building inlined-form view for a relation, consider related entities intead of other views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10907
diff changeset
   200
                with self.temporary_permissions(EmailAddress={'update': ()}):
5758ba784ebd [autoform] when building inlined-form view for a relation, consider related entities intead of other views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10907
diff changeset
   201
                    form = self.vreg['forms'].select('edition', req, entity=req.user)
5758ba784ebd [autoform] when building inlined-form view for a relation, consider related entities intead of other views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10907
diff changeset
   202
                    formviews = list(form.inlined_form_views())
5758ba784ebd [autoform] when building inlined-form view for a relation, consider related entities intead of other views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10907
diff changeset
   203
                    self.assertEqual(len(formviews), 1, formviews)
5758ba784ebd [autoform] when building inlined-form view for a relation, consider related entities intead of other views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10907
diff changeset
   204
                    self.assertIsInstance(formviews[0], autoform.InlineAddNewLinkView)
11145
d3edefdeddb4 [web/autoform] fix regression introduced by #5758ba784ebd
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11100
diff changeset
   205
            # though do not introduce regression on entity creation with 1 cardinality relation
d3edefdeddb4 [web/autoform] fix regression introduced by #5758ba784ebd
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11100
diff changeset
   206
            with tempattr(use_email_schema, 'cardinality', '11'):
d3edefdeddb4 [web/autoform] fix regression introduced by #5758ba784ebd
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11100
diff changeset
   207
                user = self.vreg['etypes'].etype_class('CWUser')(req)
d3edefdeddb4 [web/autoform] fix regression introduced by #5758ba784ebd
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11100
diff changeset
   208
                form = self.vreg['forms'].select('edition', req, entity=user)
d3edefdeddb4 [web/autoform] fix regression introduced by #5758ba784ebd
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11100
diff changeset
   209
                formviews = list(form.inlined_form_views())
d3edefdeddb4 [web/autoform] fix regression introduced by #5758ba784ebd
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11100
diff changeset
   210
                self.assertEqual(len(formviews), 1, formviews)
d3edefdeddb4 [web/autoform] fix regression introduced by #5758ba784ebd
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11100
diff changeset
   211
                self.assertIsInstance(formviews[0], autoform.InlineEntityCreationFormView)
11100
5758ba784ebd [autoform] when building inlined-form view for a relation, consider related entities intead of other views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10907
diff changeset
   212
10637
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   213
    def test_check_inlined_rdef_permissions(self):
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   214
        # try to check permissions when creating an entity ('user' below is a
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   215
        # fresh entity without an eid)
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   216
        with self.admin_access.web_request() as req:
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   217
            ttype = 'EmailAddress'
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   218
            rschema = self.schema['use_email']
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   219
            rdef =  rschema.rdefs[('CWUser', ttype)]
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   220
            tschema = self.schema[ttype]
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   221
            role = 'subject'
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   222
            with self.temporary_permissions((rdef, {'add': ()})):
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   223
                user = self.vreg['etypes'].etype_class('CWUser')(req)
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   224
                autoform = self.vreg['forms'].select('edition', req, entity=user)
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   225
                self.assertFalse(autoform.check_inlined_rdef_permissions(rschema, role,
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   226
                                                                         tschema, ttype))
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   227
            # we actually don't care about the actual expression,
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   228
            # may_have_permission only checks the presence of such expressions
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   229
            expr = RRQLExpression('S use_email O')
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   230
            with self.temporary_permissions((rdef, {'add': (expr,)})):
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   231
                user = self.vreg['etypes'].etype_class('CWUser')(req)
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   232
                autoform = self.vreg['forms'].select('edition', req, entity=user)
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   233
                self.assertTrue(autoform.check_inlined_rdef_permissions(rschema, role,
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   234
                                                                        tschema, ttype))
a8b33789b982 [autoform] fix appearance of link to add inlined creation form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10634
diff changeset
   235
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   236
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   237
class FormViewsTC(CubicWebTC):
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   238
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   239
    def test_delete_conf_formview(self):
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   240
        with self.admin_access.web_request() as req:
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   241
            rset = req.execute('CWGroup X')
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   242
            self.view('deleteconf', rset, template=None, req=req).source
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   243
11964
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   244
    def test_delete_conf_formview_composite(self):
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   245
        with self.admin_access.cnx() as cnx:
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   246
            d1 = cnx.create_entity('Directory', name=u'dtest1')
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   247
            d2 = cnx.create_entity('Directory', name=u'dtest2', parent=d1)
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   248
            d3 = cnx.create_entity('Directory', name=u'dtest3', parent=d2)
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   249
            d4 = cnx.create_entity('Directory', name=u'dtest4', parent=d1)
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   250
            for i in range(3):
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   251
                cnx.create_entity('Directory', name=u'child%s' % (i,),
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   252
                                  parent=d3)
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   253
            cnx.commit()
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   254
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   255
        class DirectoryDeleteView(DeleteConfFormView):
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   256
            __select__ = (DeleteConfFormView.__select__ &
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   257
                          is_instance('Directory'))
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   258
            show_composite = True
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   259
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   260
        self.vreg['propertyvalues']['navigation.page-size'] = 3
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   261
        with self.admin_access.web_request() as req, \
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   262
                self.temporary_appobjects(DirectoryDeleteView):
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   263
            rset = req.execute('Directory X WHERE X name "dtest1"')
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   264
            source = self.view('deleteconf', rset,
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   265
                               template=None, req=req).source.decode('utf-8')
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   266
            # Show composite object at depth 1
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   267
            # Don't display "And more composite entities" since their are equal
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   268
            # to page size
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   269
            expected = (
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   270
                '<li>'
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   271
                '<a href="http://testing.fr/cubicweb/directory/%s">dtest1</a>'
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   272
                '<ul class="treeview"><li>'
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   273
                '<a href="http://testing.fr/cubicweb/directory/%s">dtest4</a>'
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   274
                '</li><li class="last">'
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   275
                '<a href="http://testing.fr/cubicweb/directory/%s">dtest2</a>'
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   276
                '</li></ul></li>') % (d1.eid, d4.eid, d2.eid)
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   277
            self.assertIn(expected, source)
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   278
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   279
            # Page size is reached, show "And more composite entities"
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   280
            rset = req.execute('Directory X WHERE X name "dtest3"')
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   281
            source = self.view('deleteconf', rset,
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   282
                               template=None, req=req).source.decode('utf-8')
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   283
            expected = (
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   284
                '<li>'
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   285
                '<a href="http://testing.fr/cubicweb/directory/%s">dtest3</a>'
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   286
                '<ul class="treeview"><li>'
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   287
                '<a href="http://testing.fr/cubicweb/directory/%s">child2</a>'
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   288
                '</li><li>'
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   289
                '<a href="http://testing.fr/cubicweb/directory/%s">child1</a>'
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   290
                '</li><li class="last">And more composite entities</li>'
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   291
                '</ul></li>') % (
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   292
                    d3.eid,
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   293
                    req.find('Directory', name='child2').one().eid,
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   294
                    req.find('Directory', name='child1').one().eid)
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   295
            self.assertIn(expected, source)
01eeea97e549 [web/views] show composite entities in delete view
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11240
diff changeset
   296
12091
3c9e296f0a6a [web/views] fix bad html in deleteconf with show_composite=True
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11964
diff changeset
   297
            # No composite entities
3c9e296f0a6a [web/views] fix bad html in deleteconf with show_composite=True
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11964
diff changeset
   298
            rset = req.execute('Directory X WHERE X name "dtest4"')
3c9e296f0a6a [web/views] fix bad html in deleteconf with show_composite=True
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11964
diff changeset
   299
            source = self.view('deleteconf', rset,
3c9e296f0a6a [web/views] fix bad html in deleteconf with show_composite=True
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11964
diff changeset
   300
                               template=None, req=req).source.decode('utf-8')
3c9e296f0a6a [web/views] fix bad html in deleteconf with show_composite=True
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11964
diff changeset
   301
            expected = ('<li><a href="http://testing.fr/cubicweb/directory/%s">'
3c9e296f0a6a [web/views] fix bad html in deleteconf with show_composite=True
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11964
diff changeset
   302
                        'dtest4</a></li>') % (d4.eid,)
3c9e296f0a6a [web/views] fix bad html in deleteconf with show_composite=True
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11964
diff changeset
   303
            self.assertIn(expected, source)
3c9e296f0a6a [web/views] fix bad html in deleteconf with show_composite=True
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11964
diff changeset
   304
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   305
    def test_automatic_edition_formview(self):
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   306
        with self.admin_access.web_request() as req:
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   307
            rset = req.execute('CWUser X')
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   308
            self.view('edition', rset, row=0, template=None, req=req).source
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   309
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   310
    def test_automatic_edition_copyformview(self):
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   311
        with self.admin_access.web_request() as req:
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   312
            rset = req.execute('CWUser X')
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   313
            self.view('copy', rset, row=0, template=None, req=req).source
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   314
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   315
    def test_automatic_creation_formview(self):
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   316
        with self.admin_access.web_request() as req:
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   317
            self.view('creation', None, etype='CWUser', template=None, req=req).source
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   318
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   319
    def test_automatic_muledit_formview(self):
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   320
        with self.admin_access.web_request() as req:
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   321
            rset = req.execute('CWUser X')
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   322
            self.view('muledit', rset, template=None, req=req).source
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   323
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   324
    def test_automatic_reledit_formview(self):
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   325
        with self.admin_access.web_request() as req:
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   326
            rset = req.execute('CWUser X')
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   327
            self.view('reledit', rset, row=0, rtype='login', template=None, req=req).source
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   328
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   329
    def test_automatic_inline_edit_formview(self):
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   330
        with self.admin_access.web_request() as req:
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   331
            geid = req.execute('CWGroup X LIMIT 1')[0][0]
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   332
            rset = req.execute('CWUser X LIMIT 1')
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   333
            self.view('inline-edition', rset, row=0, col=0, rtype='in_group',
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   334
                      peid=geid, role='object', i18nctx='', pform=MOCKPFORM,
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   335
                      template=None, req=req).source
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   336
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   337
    def test_automatic_inline_creation_formview(self):
9842
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   338
        with self.admin_access.web_request() as req:
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   339
            geid = req.execute('CWGroup X LIMIT 1')[0][0]
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   340
            self.view('inline-creation', None, etype='CWUser', rtype='in_group',
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   341
                      peid=geid, petype='CWGroup', i18nctx='', role='object', pform=MOCKPFORM,
78d1beebdebc [webtests/views_editforms] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   342
                      template=None, req=req)
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   343
3930
c0ae3148b893 fix test: required to fake parent form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3771
diff changeset
   344
MOCKPFORM = mock_object(form_previous_values={}, form_valerror=None)
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   345
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
   346
if __name__ == '__main__':
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
   347
    unittest_main()