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 import copy |
18 from logilab.common.testlib import tag |
19 from logilab.common.testlib import tag |
19 from cubicweb.devtools.testlib import CubicWebTC |
20 from cubicweb.devtools.testlib import CubicWebTC |
20 from cubicweb.web import uicfg |
21 from cubicweb.web import uicfg, uihelper, formwidgets as fwdgs |
21 |
22 |
22 abaa = uicfg.actionbox_appearsin_addmenu |
23 abaa = uicfg.actionbox_appearsin_addmenu |
23 |
24 |
24 class UICFGTC(CubicWebTC): |
25 class UICFGTC(CubicWebTC): |
25 |
26 |
26 def test_default_actionbox_appearsin_addmenu_config(self): |
27 def test_default_actionbox_appearsin_addmenu_config(self): |
27 self.failIf(abaa.etype_get('TrInfo', 'wf_info_for', 'object', 'CWUser')) |
28 self.assertFalse(abaa.etype_get('TrInfo', 'wf_info_for', 'object', 'CWUser')) |
28 |
29 |
29 |
30 |
30 |
31 |
31 class DefinitionOrderTC(CubicWebTC): |
32 class DefinitionOrderTC(CubicWebTC): |
32 """This test check that when multiple definition could match a key, only |
33 """This test check that when multiple definition could match a key, only |
33 the more accurate apply""" |
34 the more accurate apply""" |
34 |
35 |
35 def setUp(self): |
36 def setUp(self): |
36 |
37 super(DefinitionOrderTC, self).setUp() |
|
38 for rtag in (uicfg.autoform_section, uicfg.autoform_field_kwargs): |
|
39 rtag._old_tagdefs = copy.deepcopy(rtag._tagdefs) |
37 new_def = ( |
40 new_def = ( |
38 (('*', 'login', '*'), |
41 (('*', 'login', '*'), |
39 {'formtype':'main', 'section':'hidden'}), |
42 {'formtype':'main', 'section':'hidden'}), |
40 (('*', 'login', '*'), |
43 (('*', 'login', '*'), |
41 {'formtype':'muledit', 'section':'hidden'}), |
44 {'formtype':'muledit', 'section':'hidden'}), |
46 (('CWUser', 'login', 'String'), |
49 (('CWUser', 'login', 'String'), |
47 {'formtype':'main', 'section':'inlined'}), |
50 {'formtype':'main', 'section':'inlined'}), |
48 (('CWUser', 'login', 'String'), |
51 (('CWUser', 'login', 'String'), |
49 {'formtype':'inlined', 'section':'attributes'}), |
52 {'formtype':'inlined', 'section':'attributes'}), |
50 ) |
53 ) |
51 self._old_def = [] |
|
52 |
|
53 for key, kwargs in new_def: |
54 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) |
55 uicfg.autoform_section.tag_subject_of(key, **kwargs) |
57 |
56 |
58 super(DefinitionOrderTC, self).setUp() |
57 def tearDown(self): |
59 |
58 super(DefinitionOrderTC, self).tearDown() |
|
59 for rtag in (uicfg.autoform_section, uicfg.autoform_field_kwargs): |
|
60 rtag._tagdefs = rtag._old_tagdefs |
60 |
61 |
61 @tag('uicfg') |
62 @tag('uicfg') |
62 def test_definition_order_hidden(self): |
63 def test_definition_order_hidden(self): |
63 result = uicfg.autoform_section.get('CWUser', 'login', 'String', 'subject') |
64 result = uicfg.autoform_section.get('CWUser', 'login', 'String', 'subject') |
64 expected = set(['main_inlined', 'muledit_attributes', 'inlined_attributes']) |
65 expected = set(['main_inlined', 'muledit_attributes', 'inlined_attributes']) |
65 self.assertSetEqual(result, expected) |
66 self.assertSetEqual(result, expected) |
66 |
67 |
67 def tearDown(self): |
68 @tag('uihelper', 'order', 'func') |
68 super(DefinitionOrderTC, self).tearDown() |
69 def test_uihelper_set_fields_order(self): |
69 for key, tags in self._old_def: |
70 afk_get = uicfg.autoform_field_kwargs.get |
70 if tags is None: |
71 self.assertEqual(afk_get('CWUser', 'firstname', 'String', 'subject'), {}) |
71 uicfg.autoform_section.del_rtag(*key) |
72 uihelper.set_fields_order('CWUser', ('login', 'firstname', 'surname')) |
72 else: |
73 self.assertEqual(afk_get('CWUser', 'firstname', 'String', 'subject'), {'order': 1}) |
73 for tag in tags: |
|
74 formtype, section = tag.split('_') |
|
75 uicfg.autoform_section.tag_subject_of(key[:3], formtype=formtype, section=section) |
|
76 |
74 |
77 uicfg.autoform_section.clear() |
75 @tag('uihelper', 'kwargs', 'func') |
78 uicfg.autoform_section.init(self.repo.vreg.schema) |
76 def test_uihelper_set_field_kwargs(self): |
|
77 afk_get = uicfg.autoform_field_kwargs.get |
|
78 self.assertEqual(afk_get('CWUser', 'firstname', 'String', 'subject'), {}) |
|
79 wdg = fwdgs.TextInput({'size': 30}) |
|
80 uihelper.set_field_kwargs('CWUser', 'firstname', widget=wdg) |
|
81 self.assertEqual(afk_get('CWUser', 'firstname', 'String', 'subject'), {'widget': wdg}) |
|
82 |
|
83 @tag('uihelper', 'hidden', 'func') |
|
84 def test_uihelper_hide_fields(self): |
|
85 # original conf : in_group is edited in 'attributes' section everywhere |
|
86 section_conf = uicfg.autoform_section.get('CWUser', 'in_group', '*', 'subject') |
|
87 self.assertItemsEqual(section_conf, ['main_attributes', 'muledit_attributes']) |
|
88 # hide field in main form |
|
89 uihelper.hide_fields('CWUser', ('login', 'in_group')) |
|
90 section_conf = uicfg.autoform_section.get('CWUser', 'in_group', '*', 'subject') |
|
91 self.assertItemsEqual(section_conf, ['main_hidden', 'muledit_attributes']) |
|
92 # hide field in muledit form |
|
93 uihelper.hide_fields('CWUser', ('login', 'in_group'), formtype='muledit') |
|
94 section_conf = uicfg.autoform_section.get('CWUser', 'in_group', '*', 'subject') |
|
95 self.assertItemsEqual(section_conf, ['main_hidden', 'muledit_hidden']) |
|
96 |
|
97 @tag('uihelper', 'hidden', 'formconfig') |
|
98 def test_uihelper_formconfig(self): |
|
99 afk_get = uicfg.autoform_field_kwargs.get |
|
100 class CWUserFormConfig(uihelper.FormConfig): |
|
101 etype = 'CWUser' |
|
102 hidden = ('in_group',) |
|
103 fields_order = ('login', 'firstname') |
|
104 section_conf = uicfg.autoform_section.get('CWUser', 'in_group', '*', 'subject') |
|
105 self.assertItemsEqual(section_conf, ['main_hidden', 'muledit_attributes']) |
|
106 self.assertEqual(afk_get('CWUser', 'firstname', 'String', 'subject'), {'order': 1}) |
|
107 |
|
108 |
79 |
109 |
80 if __name__ == '__main__': |
110 if __name__ == '__main__': |
81 from logilab.common.testlib import unittest_main |
111 from logilab.common.testlib import unittest_main |
82 unittest_main() |
112 unittest_main() |