web/test/unittest_uicfg.py
branchstable
changeset 5842 10efd227648e
parent 5424 8ecbcbff9777
child 6340 470d8e828fda
equal deleted inserted replaced
5841:4cbcfed90905 5842:10efd227648e
    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 from logilab.common.testlib import tag
    18 from cubicweb.devtools.testlib import CubicWebTC
    19 from cubicweb.devtools.testlib import CubicWebTC
    19 from cubicweb.web import uicfg
    20 from cubicweb.web import uicfg
    20 
    21 
    21 abaa = uicfg.actionbox_appearsin_addmenu
    22 abaa = uicfg.actionbox_appearsin_addmenu
    22 
    23 
    23 class UICFGTC(CubicWebTC):
    24 class UICFGTC(CubicWebTC):
    24 
    25 
    25     def test_default_actionbox_appearsin_addmenu_config(self):
    26     def test_default_actionbox_appearsin_addmenu_config(self):
    26         self.failIf(abaa.etype_get('TrInfo', 'wf_info_for', 'object', 'CWUser'))
    27         self.failIf(abaa.etype_get('TrInfo', 'wf_info_for', 'object', 'CWUser'))
    27 
    28 
       
    29 
       
    30 
       
    31 class DefinitionOrderTC(CubicWebTC):
       
    32     """This test check that when multiple definition could match a key, only
       
    33     the more accurate apply"""
       
    34 
       
    35     def setUp(self):
       
    36 
       
    37         new_def = (
       
    38                     (('*', 'login', '*'),
       
    39                          {'formtype':'main', 'section':'hidden'}),
       
    40                     (('*', 'login', '*'),
       
    41                          {'formtype':'muledit', 'section':'hidden'}),
       
    42                     (('CWUser', 'login', '*'),
       
    43                          {'formtype':'main', 'section':'attributes'}),
       
    44                     (('CWUser', 'login', '*'),
       
    45                          {'formtype':'muledit', 'section':'attributes'}),
       
    46                     (('CWUser', 'login', 'String'),
       
    47                          {'formtype':'main', 'section':'inlined'}),
       
    48                     (('CWUser', 'login', 'String'),
       
    49                          {'formtype':'inlined', 'section':'attributes'}),
       
    50                     )
       
    51         self._old_def = []
       
    52 
       
    53         for key, kwargs in new_def:
       
    54             nkey = key[0], key[1], key[2], 'subject'
       
    55             self._old_def.append((nkey, uicfg.autoform_section._tagdefs.get(nkey)))
       
    56             uicfg.autoform_section.tag_subject_of(key, **kwargs)
       
    57 
       
    58         super(DefinitionOrderTC, self).setUp()
       
    59 
       
    60 
       
    61     @tag('uicfg')
       
    62     def test_definition_order_hidden(self):
       
    63         result = uicfg.autoform_section.get('CWUser', 'login', 'String', 'subject')
       
    64         expected = set(['main_inlined', 'muledit_attributes', 'inlined_attributes'])
       
    65         self.assertSetEquals(result, expected)
       
    66 
       
    67     def tearDown(self):
       
    68         super(DefinitionOrderTC, self).tearDown()
       
    69         for key, tags in self._old_def:
       
    70                 if tags is None:
       
    71                     uicfg.autoform_section.del_rtag(*key)
       
    72                 else:
       
    73                     for tag in tags:
       
    74                         formtype, section = tag.split('_')
       
    75                         uicfg.autoform_section.tag_subject_of(key[:3], formtype=formtype, section=section)
       
    76 
       
    77         uicfg.autoform_section.clear()
       
    78         uicfg.autoform_section.init(self.repo.vreg.schema)
       
    79 
    28 if __name__ == '__main__':
    80 if __name__ == '__main__':
    29     from logilab.common.testlib import unittest_main
    81     from logilab.common.testlib import unittest_main
    30     unittest_main()
    82     unittest_main()