# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr## This file is part of CubicWeb.## CubicWeb is free software: you can redistribute it and/or modify it under the# terms of the GNU Lesser General Public License as published by the Free# Software Foundation, either version 2.1 of the License, or (at your option)# any later version.## CubicWeb is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more# details.## You should have received a copy of the GNU Lesser General Public License along# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.importcopyfromlogilab.common.testlibimporttagfromcubicweb.devtools.testlibimportCubicWebTCfromcubicweb.webimportuihelper,formwidgetsasfwdgsfromcubicweb.web.viewsimportuicfgabaa=uicfg.actionbox_appearsin_addmenuclassUICFGTC(CubicWebTC):deftest_default_actionbox_appearsin_addmenu_config(self):self.assertFalse(abaa.etype_get('TrInfo','wf_info_for','object','CWUser'))classDefinitionOrderTC(CubicWebTC):"""This test check that when multiple definition could match a key, only the more accurate apply"""defsetUp(self):super(DefinitionOrderTC,self).setUp()forrtagin(uicfg.autoform_section,uicfg.autoform_field_kwargs):rtag._old_tagdefs=copy.deepcopy(rtag._tagdefs)new_def=((('*','login','*'),{'formtype':'main','section':'hidden'}),(('*','login','*'),{'formtype':'muledit','section':'hidden'}),(('CWUser','login','*'),{'formtype':'main','section':'attributes'}),(('CWUser','login','*'),{'formtype':'muledit','section':'attributes'}),(('CWUser','login','String'),{'formtype':'main','section':'inlined'}),(('CWUser','login','String'),{'formtype':'inlined','section':'attributes'}),)forkey,kwargsinnew_def:uicfg.autoform_section.tag_subject_of(key,**kwargs)deftearDown(self):super(DefinitionOrderTC,self).tearDown()forrtagin(uicfg.autoform_section,uicfg.autoform_field_kwargs):rtag._tagdefs=rtag._old_tagdefs@tag('uicfg')deftest_definition_order_hidden(self):result=uicfg.autoform_section.get('CWUser','login','String','subject')expected=set(['main_inlined','muledit_attributes','inlined_attributes'])self.assertSetEqual(result,expected)@tag('uihelper','order','func')deftest_uihelper_set_fields_order(self):afk_get=uicfg.autoform_field_kwargs.getself.assertEqual(afk_get('CWUser','firstname','String','subject'),{})uihelper.set_fields_order('CWUser',('login','firstname','surname'))self.assertEqual(afk_get('CWUser','firstname','String','subject'),{'order':1})@tag('uicfg','order','func')deftest_uicfg_primaryview_set_fields_order(self):pvdc=uicfg.primaryview_display_ctrlpvdc.set_fields_order('CWUser',('login','firstname','surname'))self.assertEqual(pvdc.get('CWUser','login','String','subject'),{'order':0})self.assertEqual(pvdc.get('CWUser','firstname','String','subject'),{'order':1})self.assertEqual(pvdc.get('CWUser','surname','String','subject'),{'order':2})@tag('uihelper','kwargs','func')deftest_uihelper_set_field_kwargs(self):afk_get=uicfg.autoform_field_kwargs.getself.assertEqual(afk_get('CWUser','firstname','String','subject'),{})wdg=fwdgs.TextInput({'size':30})uihelper.set_field_kwargs('CWUser','firstname',widget=wdg)self.assertEqual(afk_get('CWUser','firstname','String','subject'),{'widget':wdg})@tag('uihelper','hidden','func')deftest_uihelper_hide_fields(self):# original conf : in_group is edited in 'attributes' section everywheresection_conf=uicfg.autoform_section.get('CWUser','in_group','*','subject')self.assertCountEqual(section_conf,['main_attributes','muledit_attributes'])# hide field in main formuihelper.hide_fields('CWUser',('login','in_group'))section_conf=uicfg.autoform_section.get('CWUser','in_group','*','subject')self.assertCountEqual(section_conf,['main_hidden','muledit_attributes'])# hide field in muledit formuihelper.hide_fields('CWUser',('login','in_group'),formtype='muledit')section_conf=uicfg.autoform_section.get('CWUser','in_group','*','subject')self.assertCountEqual(section_conf,['main_hidden','muledit_hidden'])@tag('uihelper','hidden','formconfig')deftest_uihelper_formconfig(self):afk_get=uicfg.autoform_field_kwargs.getclassCWUserFormConfig(uihelper.FormConfig):etype='CWUser'hidden=('in_group',)fields_order=('login','firstname')section_conf=uicfg.autoform_section.get('CWUser','in_group','*','subject')self.assertCountEqual(section_conf,['main_hidden','muledit_attributes'])self.assertEqual(afk_get('CWUser','firstname','String','subject'),{'order':1})classUicfgRegistryTC(CubicWebTC):deftest_default_uicfg_object(self):'CW default ui config objects must be registered in uicfg registry'onames=('autoform_field','autoform_section','autoform_field_kwargs')foronameinonames:obj=self.vreg['uicfg'].select_or_none(oname)self.assertTrue(objisnotNone,'%s not found in uicfg registry'%oname)deftest_custom_uicfg(self):ASRT=uicfg.AutoformSectionRelationTagscustom_afs=ASRT()custom_afs.__select__=ASRT.__select__&ASRT.__select__self.vreg['uicfg'].register(custom_afs)obj=self.vreg['uicfg'].select_or_none('autoform_section')self.assertTrue(objiscustom_afs)if__name__=='__main__':fromlogilab.common.testlibimportunittest_mainunittest_main()