cubicweb/web/test/unittest_uicfg.py
branch3.25
changeset 12210 3fa6c9ef2f51
parent 11876 b35e21fc1f9b
child 12211 1a5911825ef5
equal deleted inserted replaced
12207:2fc04786dd36 12210:3fa6c9ef2f51
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    14 # details.
    14 # details.
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
       
    18 
    18 import copy
    19 import copy
    19 import warnings
    20 import warnings
    20 
    21 
    21 from logilab.common.testlib import tag
    22 from logilab.common.testlib import tag
    22 from cubicweb.devtools.testlib import CubicWebTC
    23 from cubicweb.devtools.testlib import CubicWebTC
    23 from cubicweb.web import uihelper, formwidgets as fwdgs
    24 from cubicweb.web import uihelper, formwidgets as fwdgs
    24 from cubicweb.web.views import uicfg
    25 from cubicweb.web.views import uicfg
    25 
    26 
    26 abaa = uicfg.actionbox_appearsin_addmenu
    27 abaa = uicfg.actionbox_appearsin_addmenu
    27 
    28 
       
    29 
    28 class UICFGTC(CubicWebTC):
    30 class UICFGTC(CubicWebTC):
    29 
    31 
    30     def test_default_actionbox_appearsin_addmenu_config(self):
    32     def test_default_actionbox_appearsin_addmenu_config(self):
    31         self.assertFalse(abaa.etype_get('TrInfo', 'wf_info_for', 'object', 'CWUser'))
    33         self.assertFalse(abaa.etype_get('TrInfo', 'wf_info_for', 'object', 'CWUser'))
    32 
       
    33 
    34 
    34 
    35 
    35 class DefinitionOrderTC(CubicWebTC):
    36 class DefinitionOrderTC(CubicWebTC):
    36     """This test check that when multiple definition could match a key, only
    37     """This test check that when multiple definition could match a key, only
    37     the more accurate apply"""
    38     the more accurate apply"""
    39     def setUp(self):
    40     def setUp(self):
    40         super(DefinitionOrderTC, self).setUp()
    41         super(DefinitionOrderTC, self).setUp()
    41         for rtag in (uicfg.autoform_section, uicfg.autoform_field_kwargs):
    42         for rtag in (uicfg.autoform_section, uicfg.autoform_field_kwargs):
    42             rtag._old_tagdefs = copy.deepcopy(rtag._tagdefs)
    43             rtag._old_tagdefs = copy.deepcopy(rtag._tagdefs)
    43         new_def = (
    44         new_def = (
    44                     (('*', 'login', '*'),
    45             (('*', 'login', '*'),
    45                          {'formtype':'main', 'section':'hidden'}),
    46              {'formtype': 'main', 'section': 'hidden'}),
    46                     (('*', 'login', '*'),
    47             (('*', 'login', '*'),
    47                          {'formtype':'muledit', 'section':'hidden'}),
    48              {'formtype': 'muledit', 'section': 'hidden'}),
    48                     (('CWUser', 'login', '*'),
    49             (('CWUser', 'login', '*'),
    49                          {'formtype':'main', 'section':'attributes'}),
    50              {'formtype': 'main', 'section': 'attributes'}),
    50                     (('CWUser', 'login', '*'),
    51             (('CWUser', 'login', '*'),
    51                          {'formtype':'muledit', 'section':'attributes'}),
    52              {'formtype': 'muledit', 'section': 'attributes'}),
    52                     (('CWUser', 'login', 'String'),
    53             (('CWUser', 'login', 'String'),
    53                          {'formtype':'main', 'section':'inlined'}),
    54              {'formtype': 'main', 'section': 'inlined'}),
    54                     (('CWUser', 'login', 'String'),
    55             (('CWUser', 'login', 'String'),
    55                          {'formtype':'inlined', 'section':'attributes'}),
    56              {'formtype': 'inlined', 'section': 'attributes'}),
    56                     )
    57         )
    57         for key, kwargs in new_def:
    58         for key, kwargs in new_def:
    58             uicfg.autoform_section.tag_subject_of(key, **kwargs)
    59             uicfg.autoform_section.tag_subject_of(key, **kwargs)
    59 
    60 
    60     def tearDown(self):
    61     def tearDown(self):
    61         super(DefinitionOrderTC, self).tearDown()
    62         super(DefinitionOrderTC, self).tearDown()
   118         self.assertCountEqual(section_conf, ['main_hidden', 'muledit_hidden'])
   119         self.assertCountEqual(section_conf, ['main_hidden', 'muledit_hidden'])
   119 
   120 
   120     @tag('uihelper', 'hidden', 'formconfig')
   121     @tag('uihelper', 'hidden', 'formconfig')
   121     def test_uihelper_formconfig(self):
   122     def test_uihelper_formconfig(self):
   122         afk_get = uicfg.autoform_field_kwargs.get
   123         afk_get = uicfg.autoform_field_kwargs.get
       
   124 
   123         class CWUserFormConfig(uihelper.FormConfig):
   125         class CWUserFormConfig(uihelper.FormConfig):
   124             etype = 'CWUser'
   126             etype = 'CWUser'
   125             hidden = ('in_group',)
   127             hidden = ('in_group',)
   126             fields_order = ('login', 'firstname')
   128             fields_order = ('login', 'firstname')
       
   129 
   127         section_conf = uicfg.autoform_section.get('CWUser', 'in_group', '*', 'subject')
   130         section_conf = uicfg.autoform_section.get('CWUser', 'in_group', '*', 'subject')
   128         self.assertCountEqual(section_conf, ['main_hidden', 'muledit_attributes'])
   131         self.assertCountEqual(section_conf, ['main_hidden', 'muledit_attributes'])
   129         self.assertEqual(afk_get('CWUser', 'firstname', 'String', 'subject'), {'order': 1})
   132         self.assertEqual(afk_get('CWUser', 'firstname', 'String', 'subject'), {'order': 1})
   130 
   133 
   131 
   134