cubicweb/web/test/unittest_uicfg.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 24 Nov 2016 15:36:26 +0100
changeset 11892 08cf02efc7ce
parent 11876 b35e21fc1f9b
child 12210 3fa6c9ef2f51
permissions -rw-r--r--
Simplify and fix _cw.drop_entity_cache * it's never called with an eid as argument, beside in a useless case in test (removed) * the only place where it's called from outside the tests is in full-text reindexation in server.checkintegrity: we could removed the request implementation and move it in unittest_rset, byt I decided to keep it for consistency with all other entity cache handling methods * get back a fix from Julien Cristau for the connection's implementation, quoting is commit message: When removing an entity from the transaction's cache, clear the entity's own cache May avoid issues where an entity object is still accessible somewhere else (e.g. an operation) after dropping it from the transaction's cache, with a stale attribute or relation cache.
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
11876
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
    19
import warnings
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
    20
5842
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    21
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
    22
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
    23
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
    24
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
    25
4997
aed7bdb9da54 [web test] a basic test, to be completed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    26
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
    27
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
    28
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
    29
4997
aed7bdb9da54 [web test] a basic test, to be completed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    30
    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
    31
        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
    32
5842
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    33
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    34
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    35
class DefinitionOrderTC(CubicWebTC):
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    36
    """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
    37
    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
    38
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    39
    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
    40
        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
    41
        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
    42
            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
    43
        new_def = (
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':'main', 'section':'hidden'}),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    46
                    (('*', 'login', '*'),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    47
                         {'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
    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':'main', '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', '*'),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    51
                         {'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
    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':'main', 'section':'inlined'}),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    54
                    (('CWUser', 'login', 'String'),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    55
                         {'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
    56
                    )
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    57
        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
    58
            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
    59
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    60
    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
    61
        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
    62
        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
    63
            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
    64
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    65
    @tag('uicfg')
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    66
    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
    67
        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
    68
        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
    69
        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
    70
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    71
    @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
    72
    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
    73
        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
    74
        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
    75
        with warnings.catch_warnings(record=True) as w:
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
    76
            uihelper.set_fields_order('CWUser', ('login', 'firstname', 'surname'))
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
    77
            self.assertEqual(len(w), 1)
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
    78
            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
    79
        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
    80
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
    81
    @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
    82
    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
    83
        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
    84
        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
    85
        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
    86
        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
    87
        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
    88
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
    89
    @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
    90
    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
    91
        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
    92
        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
    93
        wdg = fwdgs.TextInput({'size': 30})
11876
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
    94
        with warnings.catch_warnings(record=True) as w:
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
    95
            uihelper.set_field_kwargs('CWUser', 'firstname', widget=wdg)
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
    96
            self.assertEqual(len(w), 1)
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
    97
            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
    98
        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
    99
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   100
    @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
   101
    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
   102
        # 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
   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_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
   105
        # hide field in main form
11876
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
   106
        with warnings.catch_warnings(record=True) as w:
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
   107
            uihelper.hide_fields('CWUser', ('login', 'in_group'))
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
   108
            self.assertEqual(len(w), 1)
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
   109
            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
   110
        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
   111
        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
   112
        # hide field in muledit form
11876
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
   113
        with warnings.catch_warnings(record=True) as w:
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
   114
            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
   115
            self.assertEqual(len(w), 1)
b35e21fc1f9b [web/tests] Hide DeprecationWarnings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11057
diff changeset
   116
            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
   117
        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
   118
        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
   119
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   120
    @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
   121
    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
   122
        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
   123
        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
   124
            etype = 'CWUser'
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   125
            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
   126
            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
   127
        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
   128
        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
   129
        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
   130
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7791
diff changeset
   131
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   132
class UicfgRegistryTC(CubicWebTC):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   133
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   134
    def test_default_uicfg_object(self):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   135
        '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
   136
        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
   137
        for oname in onames:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   138
            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
   139
            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
   140
                            % oname)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   141
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   142
    def test_custom_uicfg(self):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   143
        ASRT = uicfg.AutoformSectionRelationTags
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   144
        custom_afs = ASRT()
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   145
        custom_afs.__select__ = ASRT.__select__ & ASRT.__select__
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   146
        self.vreg['uicfg'].register(custom_afs)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   147
        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
   148
        self.assertTrue(obj is custom_afs)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   149
5842
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
   150
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
   151
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
   152
    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
   153
    unittest_main()