[fix] fix a uicfg bug in autoform_section stable
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Tue, 22 Jun 2010 13:47:13 +0200
branchstable
changeset 5842 10efd227648e
parent 5841 4cbcfed90905
child 5843 85c4d5334f2c
[fix] fix a uicfg bug in autoform_section When several rtags matches the same relation (for example "* login *" and "CWUser login *") inconsistent rtag could be merged.
web/test/unittest_uicfg.py
web/uicfg.py
--- a/web/test/unittest_uicfg.py	Wed Jun 30 15:50:06 2010 +0200
+++ b/web/test/unittest_uicfg.py	Tue Jun 22 13:47:13 2010 +0200
@@ -15,6 +15,7 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
+from logilab.common.testlib import tag
 from cubicweb.devtools.testlib import CubicWebTC
 from cubicweb.web import uicfg
 
@@ -25,6 +26,57 @@
     def test_default_actionbox_appearsin_addmenu_config(self):
         self.failIf(abaa.etype_get('TrInfo', 'wf_info_for', 'object', 'CWUser'))
 
+
+
+class DefinitionOrderTC(CubicWebTC):
+    """This test check that when multiple definition could match a key, only
+    the more accurate apply"""
+
+    def setUp(self):
+
+        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'}),
+                    )
+        self._old_def = []
+
+        for key, kwargs in new_def:
+            nkey = key[0], key[1], key[2], 'subject'
+            self._old_def.append((nkey, uicfg.autoform_section._tagdefs.get(nkey)))
+            uicfg.autoform_section.tag_subject_of(key, **kwargs)
+
+        super(DefinitionOrderTC, self).setUp()
+
+
+    @tag('uicfg')
+    def test_definition_order_hidden(self):
+        result = uicfg.autoform_section.get('CWUser', 'login', 'String', 'subject')
+        expected = set(['main_inlined', 'muledit_attributes', 'inlined_attributes'])
+        self.assertSetEquals(result, expected)
+
+    def tearDown(self):
+        super(DefinitionOrderTC, self).tearDown()
+        for key, tags in self._old_def:
+                if tags is None:
+                    uicfg.autoform_section.del_rtag(*key)
+                else:
+                    for tag in tags:
+                        formtype, section = tag.split('_')
+                        uicfg.autoform_section.tag_subject_of(key[:3], formtype=formtype, section=section)
+
+        uicfg.autoform_section.clear()
+        uicfg.autoform_section.init(self.repo.vreg.schema)
+
 if __name__ == '__main__':
     from logilab.common.testlib import unittest_main
     unittest_main()
--- a/web/uicfg.py	Wed Jun 30 15:50:06 2010 +0200
+++ b/web/uicfg.py	Tue Jun 22 13:47:13 2010 +0200
@@ -278,8 +278,19 @@
         rtags.add('%s_%s' % (formtype, section))
         return rtags
 
-    def init_get(self, *key):
-        return super(AutoformSectionRelationTags, self).get(*key)
+    def init_get(self, stype, rtype, otype, tagged):
+        key = (stype, rtype, otype, tagged)
+        rtags = {}
+        for key in self._get_keys(stype, rtype, otype, tagged):
+            tags = self._tagdefs.get(key, ())
+            for tag in tags:
+                assert '_' in tag, (tag, tags)
+                section, value = tag.split('_', 1)
+                rtags[section] = value
+        cls = self.tag_container_cls
+        rtags = cls('_'.join([section,value]) for section,value in rtags.iteritems())
+        return rtags
+
 
     def get(self, *key):
         # overriden to avoid recomputing done in parent classes