web/test/unittest_uicfg.py
author Alexandre Fayolle <alexandre.fayolle@logilab.fr>
Fri, 15 Apr 2011 16:05:20 +0200
changeset 7236 b91205ada414
parent 6340 470d8e828fda
child 7791 31bb51ea5485
permissions -rw-r--r--
added test case to monitor speed improvements in the repository code. To use it, add a test in a patch, then hack CW to speed it up in another patch, updating the test if needed. By running the test with and without the second patch applied you can easily see the speed improvements
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4997
diff changeset
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4997
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4997
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4997
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4997
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4997
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4997
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4997
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4997
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4997
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4997
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4997
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4997
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4997
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4997
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4997
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
5842
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    18
from logilab.common.testlib import tag
3464
99bd1ea0394a [tests] make unittest_uicfg pass again by using the correct test class
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3125
diff changeset
    19
from cubicweb.devtools.testlib import CubicWebTC
3125
52b6b8c2ccc5 [uicfg, autoform] when a relation is inlined, put it in the generated section by default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
from cubicweb.web import uicfg
52b6b8c2ccc5 [uicfg, autoform] when a relation is inlined, put it in the generated section by default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
4997
aed7bdb9da54 [web test] a basic test, to be completed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    22
abaa = uicfg.actionbox_appearsin_addmenu
aed7bdb9da54 [web test] a basic test, to be completed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    23
3464
99bd1ea0394a [tests] make unittest_uicfg pass again by using the correct test class
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3125
diff changeset
    24
class UICFGTC(CubicWebTC):
3125
52b6b8c2ccc5 [uicfg, autoform] when a relation is inlined, put it in the generated section by default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
4997
aed7bdb9da54 [web test] a basic test, to be completed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    26
    def test_default_actionbox_appearsin_addmenu_config(self):
aed7bdb9da54 [web test] a basic test, to be completed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4083
diff changeset
    27
        self.failIf(abaa.etype_get('TrInfo', 'wf_info_for', 'object', 'CWUser'))
3125
52b6b8c2ccc5 [uicfg, autoform] when a relation is inlined, put it in the generated section by default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
5842
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    29
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    30
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    31
class DefinitionOrderTC(CubicWebTC):
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    32
    """This test check that when multiple definition could match a key, only
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    33
    the more accurate apply"""
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    34
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    35
    def setUp(self):
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    36
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    37
        new_def = (
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    38
                    (('*', 'login', '*'),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    39
                         {'formtype':'main', 'section':'hidden'}),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    40
                    (('*', 'login', '*'),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    41
                         {'formtype':'muledit', 'section':'hidden'}),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    42
                    (('CWUser', 'login', '*'),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    43
                         {'formtype':'main', 'section':'attributes'}),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    44
                    (('CWUser', 'login', '*'),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    45
                         {'formtype':'muledit', 'section':'attributes'}),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    46
                    (('CWUser', 'login', 'String'),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    47
                         {'formtype':'main', 'section':'inlined'}),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    48
                    (('CWUser', 'login', 'String'),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    49
                         {'formtype':'inlined', 'section':'attributes'}),
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    50
                    )
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    51
        self._old_def = []
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    52
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    53
        for key, kwargs in new_def:
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    54
            nkey = key[0], key[1], key[2], 'subject'
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    55
            self._old_def.append((nkey, uicfg.autoform_section._tagdefs.get(nkey)))
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    56
            uicfg.autoform_section.tag_subject_of(key, **kwargs)
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    57
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    58
        super(DefinitionOrderTC, self).setUp()
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    59
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    60
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    61
    @tag('uicfg')
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    62
    def test_definition_order_hidden(self):
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    63
        result = uicfg.autoform_section.get('CWUser', 'login', 'String', 'subject')
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    64
        expected = set(['main_inlined', 'muledit_attributes', 'inlined_attributes'])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5842
diff changeset
    65
        self.assertSetEqual(result, expected)
5842
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    66
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    67
    def tearDown(self):
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    68
        super(DefinitionOrderTC, self).tearDown()
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    69
        for key, tags in self._old_def:
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    70
                if tags is None:
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    71
                    uicfg.autoform_section.del_rtag(*key)
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    72
                else:
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    73
                    for tag in tags:
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    74
                        formtype, section = tag.split('_')
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    75
                        uicfg.autoform_section.tag_subject_of(key[:3], formtype=formtype, section=section)
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    76
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    77
        uicfg.autoform_section.clear()
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    78
        uicfg.autoform_section.init(self.repo.vreg.schema)
10efd227648e [fix] fix a uicfg bug in autoform_section
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    79
3125
52b6b8c2ccc5 [uicfg, autoform] when a relation is inlined, put it in the generated section by default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    80
if __name__ == '__main__':
52b6b8c2ccc5 [uicfg, autoform] when a relation is inlined, put it in the generated section by default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    81
    from logilab.common.testlib import unittest_main
52b6b8c2ccc5 [uicfg, autoform] when a relation is inlined, put it in the generated section by default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    82
    unittest_main()