cubicweb/web/test/unittest_uicfg.py
author Laura Médioni <laura.medioni@logilab.fr>, Denis Laxalde <denis.laxalde@logilab.fr>
Thu, 03 Nov 2016 15:00:01 +0100
changeset 11794 d8830e2bd2e0
parent 11057 0b59724cb3f2
child 11876 b35e21fc1f9b
permissions -rw-r--r--
[req,web] Make it possible to handle page language from URL prefix Adding a short language prefix to URL (like "/en" or "/fr") changes the language the pages are displayed in. This prefix is kept during navigation. This way it is not necessary to do language negotiation, nor to use user preferences to determine which language to apply. This behavior is controlled through a new configuration option "language-mode", which replaces "language-negociation" option and which values may be "http-negotiation", "url-prefix" or "" (to disable language setting and force using "ui.language" property). Migration from previous option is not handled because I could not manage to have it working (users will get prompted with the configuration file diff anyways). Add some tests checking various scenarios. Closes #15743487
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4997
diff changeset
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4997
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: 4997
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: 4997
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: 4997
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: 4997
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: 4997
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: 4997
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: 4997
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: 4997
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: 4997
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: 4997
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: 4997
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: 4997
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: 4997
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: 4997
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    18
import copy
5842
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    19
from logilab.common.testlib import tag
3464
99bd1ea0394a [tests] make unittest_uicfg pass again by using the correct test class
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3125
diff changeset
    20
from cubicweb.devtools.testlib import CubicWebTC
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8030
diff changeset
    21
from cubicweb.web import uihelper, formwidgets as fwdgs
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8030
diff changeset
    22
from cubicweb.web.views import uicfg
3125
52b6b8c2ccc5 [uicfg, autoform] when a relation is inlined, put it in the generated section by default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
4997
aed7bdb9da54 [web test] a basic test, to be completed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    24
abaa = uicfg.actionbox_appearsin_addmenu
aed7bdb9da54 [web test] a basic test, to be completed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    25
3464
99bd1ea0394a [tests] make unittest_uicfg pass again by using the correct test class
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3125
diff changeset
    26
class UICFGTC(CubicWebTC):
3125
52b6b8c2ccc5 [uicfg, autoform] when a relation is inlined, put it in the generated section by default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
4997
aed7bdb9da54 [web test] a basic test, to be completed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    28
    def test_default_actionbox_appearsin_addmenu_config(self):
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    29
        self.assertFalse(abaa.etype_get('TrInfo', 'wf_info_for', 'object', 'CWUser'))
3125
52b6b8c2ccc5 [uicfg, autoform] when a relation is inlined, put it in the generated section by default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    30
5842
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    31
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    32
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    33
class DefinitionOrderTC(CubicWebTC):
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    34
    """This test check that when multiple definition could match a key, only
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    35
    the more accurate apply"""
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    36
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    37
    def setUp(self):
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    38
        super(DefinitionOrderTC, self).setUp()
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    39
        for rtag in (uicfg.autoform_section, uicfg.autoform_field_kwargs):
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    40
            rtag._old_tagdefs = copy.deepcopy(rtag._tagdefs)
5842
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    41
        new_def = (
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    42
                    (('*', 'login', '*'),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    43
                         {'formtype':'main', 'section':'hidden'}),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    44
                    (('*', 'login', '*'),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    45
                         {'formtype':'muledit', 'section':'hidden'}),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    46
                    (('CWUser', 'login', '*'),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    47
                         {'formtype':'main', 'section':'attributes'}),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    48
                    (('CWUser', 'login', '*'),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    49
                         {'formtype':'muledit', 'section':'attributes'}),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    50
                    (('CWUser', 'login', 'String'),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    51
                         {'formtype':'main', 'section':'inlined'}),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    52
                    (('CWUser', 'login', 'String'),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    53
                         {'formtype':'inlined', 'section':'attributes'}),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    54
                    )
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    55
        for key, kwargs in new_def:
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    56
            uicfg.autoform_section.tag_subject_of(key, **kwargs)
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    57
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    58
    def tearDown(self):
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    59
        super(DefinitionOrderTC, self).tearDown()
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    60
        for rtag in (uicfg.autoform_section, uicfg.autoform_field_kwargs):
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    61
            rtag._tagdefs = rtag._old_tagdefs
5842
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    62
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    63
    @tag('uicfg')
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    64
    def test_definition_order_hidden(self):
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    65
        result = uicfg.autoform_section.get('CWUser', 'login', 'String', 'subject')
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    66
        expected = set(['main_inlined', 'muledit_attributes', 'inlined_attributes'])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5842
diff changeset
    67
        self.assertSetEqual(result, expected)
5842
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    68
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    69
    @tag('uihelper', 'order', 'func')
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    70
    def test_uihelper_set_fields_order(self):
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    71
        afk_get = uicfg.autoform_field_kwargs.get
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    72
        self.assertEqual(afk_get('CWUser', 'firstname', 'String', 'subject'), {})
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    73
        uihelper.set_fields_order('CWUser', ('login', 'firstname', 'surname'))
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    74
        self.assertEqual(afk_get('CWUser', 'firstname', 'String', 'subject'), {'order': 1})
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    75
9341
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9273
diff changeset
    76
    @tag('uicfg', 'order', 'func')
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9273
diff changeset
    77
    def test_uicfg_primaryview_set_fields_order(self):
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9273
diff changeset
    78
        pvdc = uicfg.primaryview_display_ctrl
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9273
diff changeset
    79
        pvdc.set_fields_order('CWUser', ('login', 'firstname', 'surname'))
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9273
diff changeset
    80
        self.assertEqual(pvdc.get('CWUser', 'login', 'String', 'subject'), {'order': 0})
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9273
diff changeset
    81
        self.assertEqual(pvdc.get('CWUser', 'firstname', 'String', 'subject'), {'order': 1})
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9273
diff changeset
    82
        self.assertEqual(pvdc.get('CWUser', 'surname', 'String', 'subject'), {'order': 2})
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9273
diff changeset
    83
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    84
    @tag('uihelper', 'kwargs', 'func')
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    85
    def test_uihelper_set_field_kwargs(self):
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    86
        afk_get = uicfg.autoform_field_kwargs.get
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    87
        self.assertEqual(afk_get('CWUser', 'firstname', 'String', 'subject'), {})
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    88
        wdg = fwdgs.TextInput({'size': 30})
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    89
        uihelper.set_field_kwargs('CWUser', 'firstname', widget=wdg)
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    90
        self.assertEqual(afk_get('CWUser', 'firstname', 'String', 'subject'), {'widget': wdg})
5842
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    91
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    92
    @tag('uihelper', 'hidden', 'func')
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    93
    def test_uihelper_hide_fields(self):
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    94
        # original conf : in_group is edited in 'attributes' section everywhere
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    95
        section_conf = uicfg.autoform_section.get('CWUser', 'in_group', '*', 'subject')
9273
f3795da61959 [test] use assertCountEqual instead of assertItemsEqual
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8666
diff changeset
    96
        self.assertCountEqual(section_conf, ['main_attributes', 'muledit_attributes'])
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    97
        # hide field in main form
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    98
        uihelper.hide_fields('CWUser', ('login', 'in_group'))
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    99
        section_conf = uicfg.autoform_section.get('CWUser', 'in_group', '*', 'subject')
9273
f3795da61959 [test] use assertCountEqual instead of assertItemsEqual
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8666
diff changeset
   100
        self.assertCountEqual(section_conf, ['main_hidden', 'muledit_attributes'])
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   101
        # hide field in muledit form
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   102
        uihelper.hide_fields('CWUser', ('login', 'in_group'), formtype='muledit')
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   103
        section_conf = uicfg.autoform_section.get('CWUser', 'in_group', '*', 'subject')
9273
f3795da61959 [test] use assertCountEqual instead of assertItemsEqual
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8666
diff changeset
   104
        self.assertCountEqual(section_conf, ['main_hidden', 'muledit_hidden'])
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   105
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   106
    @tag('uihelper', 'hidden', 'formconfig')
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   107
    def test_uihelper_formconfig(self):
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   108
        afk_get = uicfg.autoform_field_kwargs.get
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   109
        class CWUserFormConfig(uihelper.FormConfig):
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   110
            etype = 'CWUser'
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   111
            hidden = ('in_group',)
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   112
            fields_order = ('login', 'firstname')
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   113
        section_conf = uicfg.autoform_section.get('CWUser', 'in_group', '*', 'subject')
9273
f3795da61959 [test] use assertCountEqual instead of assertItemsEqual
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8666
diff changeset
   114
        self.assertCountEqual(section_conf, ['main_hidden', 'muledit_attributes'])
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   115
        self.assertEqual(afk_get('CWUser', 'firstname', 'String', 'subject'), {'order': 1})
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   116
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   117
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   118
class UicfgRegistryTC(CubicWebTC):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   119
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   120
    def test_default_uicfg_object(self):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   121
        'CW default ui config objects must be registered in uicfg registry'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   122
        onames = ('autoform_field', 'autoform_section', 'autoform_field_kwargs')
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   123
        for oname in onames:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   124
            obj = self.vreg['uicfg'].select_or_none(oname)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   125
            self.assertTrue(obj is not None, '%s not found in uicfg registry'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   126
                            % oname)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   127
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   128
    def test_custom_uicfg(self):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   129
        ASRT = uicfg.AutoformSectionRelationTags
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   130
        custom_afs = ASRT()
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   131
        custom_afs.__select__ = ASRT.__select__ & ASRT.__select__
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   132
        self.vreg['uicfg'].register(custom_afs)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   133
        obj = self.vreg['uicfg'].select_or_none('autoform_section')
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   134
        self.assertTrue(obj is custom_afs)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   135
5842
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
   136
3125
52b6b8c2ccc5 [uicfg, autoform] when a relation is inlined, put it in the generated section by default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   137
if __name__ == '__main__':
52b6b8c2ccc5 [uicfg, autoform] when a relation is inlined, put it in the generated section by default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   138
    from logilab.common.testlib import unittest_main
52b6b8c2ccc5 [uicfg, autoform] when a relation is inlined, put it in the generated section by default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   139
    unittest_main()