cubicweb/web/test/unittest_uicfg.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 06 Oct 2017 14:24:35 +0200
branch3.25
changeset 12210 3fa6c9ef2f51
parent 11876 b35e21fc1f9b
child 12211 1a5911825ef5
permissions -rw-r--r--
[cleanup] Fix some flake8 errors and drop upper bound of copyright along the way. autoform module is not added to flake8-ok-files since there are some remaining errors to be handled, but that's still a start.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12210
3fa6c9ef2f51 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11876
diff changeset
     1
# copyright 2003 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: 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/>.
12210
3fa6c9ef2f51 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11876
diff changeset
    18
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    19
import copy
11876
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
    20
import warnings
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
    21
5842
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    22
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
    23
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
    24
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
    25
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
    26
4997
aed7bdb9da54 [web test] a basic test, to be completed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    27
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
    28
12210
3fa6c9ef2f51 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11876
diff changeset
    29
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
    30
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
    31
4997
aed7bdb9da54 [web test] a basic test, to be completed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    32
    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
    33
        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
    34
5842
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    35
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    36
class DefinitionOrderTC(CubicWebTC):
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    37
    """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
    38
    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
    39
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    40
    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
    41
        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
    42
        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
    43
            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
    44
        new_def = (
12210
3fa6c9ef2f51 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11876
diff changeset
    45
            (('*', 'login', '*'),
3fa6c9ef2f51 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11876
diff changeset
    46
             {'formtype': 'main', 'section': 'hidden'}),
3fa6c9ef2f51 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11876
diff changeset
    47
            (('*', 'login', '*'),
3fa6c9ef2f51 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11876
diff changeset
    48
             {'formtype': 'muledit', 'section': 'hidden'}),
3fa6c9ef2f51 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11876
diff changeset
    49
            (('CWUser', 'login', '*'),
3fa6c9ef2f51 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11876
diff changeset
    50
             {'formtype': 'main', 'section': 'attributes'}),
3fa6c9ef2f51 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11876
diff changeset
    51
            (('CWUser', 'login', '*'),
3fa6c9ef2f51 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11876
diff changeset
    52
             {'formtype': 'muledit', 'section': 'attributes'}),
3fa6c9ef2f51 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11876
diff changeset
    53
            (('CWUser', 'login', 'String'),
3fa6c9ef2f51 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11876
diff changeset
    54
             {'formtype': 'main', 'section': 'inlined'}),
3fa6c9ef2f51 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11876
diff changeset
    55
            (('CWUser', 'login', 'String'),
3fa6c9ef2f51 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11876
diff changeset
    56
             {'formtype': 'inlined', 'section': 'attributes'}),
3fa6c9ef2f51 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11876
diff changeset
    57
        )
5842
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    58
        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
    59
            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
    60
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    61
    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
    62
        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
    63
        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
    64
            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
    65
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    66
    @tag('uicfg')
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    67
    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
    68
        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
    69
        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
    70
        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
    71
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    72
    @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
    73
    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
    74
        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
    75
        self.assertEqual(afk_get('CWUser', 'firstname', 'String', 'subject'), {})
11876
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
    76
        with warnings.catch_warnings(record=True) as w:
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
    77
            uihelper.set_fields_order('CWUser', ('login', 'firstname', 'surname'))
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
    78
            self.assertEqual(len(w), 1)
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
    79
            self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    80
        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
    81
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
    82
    @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
    83
    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
    84
        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
    85
        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
    86
        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
    87
        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
    88
        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
    89
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    90
    @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
    91
    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
    92
        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
    93
        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
    94
        wdg = fwdgs.TextInput({'size': 30})
11876
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
    95
        with warnings.catch_warnings(record=True) as w:
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
    96
            uihelper.set_field_kwargs('CWUser', 'firstname', widget=wdg)
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
    97
            self.assertEqual(len(w), 1)
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
    98
            self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    99
        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
   100
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   101
    @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
   102
    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
   103
        # 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
   104
        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
   105
        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
   106
        # hide field in main form
11876
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
   107
        with warnings.catch_warnings(record=True) as w:
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
   108
            uihelper.hide_fields('CWUser', ('login', 'in_group'))
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
   109
            self.assertEqual(len(w), 1)
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
   110
            self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   111
        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
   112
        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
   113
        # hide field in muledit form
11876
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
   114
        with warnings.catch_warnings(record=True) as w:
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
   115
            uihelper.hide_fields('CWUser', ('login', 'in_group'), formtype='muledit')
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
   116
            self.assertEqual(len(w), 1)
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
   117
            self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   118
        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
   119
        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
   120
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   121
    @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
   122
    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
   123
        afk_get = uicfg.autoform_field_kwargs.get
12210
3fa6c9ef2f51 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11876
diff changeset
   124
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   125
        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
   126
            etype = 'CWUser'
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   127
            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
   128
            fields_order = ('login', 'firstname')
12210
3fa6c9ef2f51 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11876
diff changeset
   129
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   130
        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
   131
        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
   132
        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
   133
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   134
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   135
class UicfgRegistryTC(CubicWebTC):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   136
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   137
    def test_default_uicfg_object(self):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   138
        '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
   139
        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
   140
        for oname in onames:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   141
            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
   142
            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
   143
                            % oname)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   144
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   145
    def test_custom_uicfg(self):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   146
        ASRT = uicfg.AutoformSectionRelationTags
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   147
        custom_afs = ASRT()
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   148
        custom_afs.__select__ = ASRT.__select__ & ASRT.__select__
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   149
        self.vreg['uicfg'].register(custom_afs)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   150
        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
   151
        self.assertTrue(obj is custom_afs)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   152
5842
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
   153
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
   154
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
   155
    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
   156
    unittest_main()