web/test/unittest_formwidgets.py
author Rémi Cardona <remi.cardona@logilab.fr>
Fri, 18 Sep 2015 11:58:29 +0200
changeset 10707 3f4f190f8e35
parent 10596 3a7ce5c9fe35
child 10901 ddeac3ecdd88
permissions -rw-r--r--
[py3k] unicode → six.text_type
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6682
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     1
# copyright 2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
#
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     4
# This file is part of CubicWeb.
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     5
#
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     9
# any later version.
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    10
#
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    14
# details.
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    15
#
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    18
"""unittests for cw.web.formwidgets"""
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    19
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
from logilab.common.testlib import TestCase, unittest_main, mock_object as mock
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
from cubicweb.devtools import TestServerConfiguration, fake
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8029
diff changeset
    23
from cubicweb.web import formwidgets, formfields
6682
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
from cubes.file.entities import File
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
class WidgetsTC(TestCase):
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    29
10596
3a7ce5c9fe35 [web/test] Use TestCase.setUpClass instead of setUpModule
Julien Cristau <julien.cristau@logilab.fr>
parents: 8665
diff changeset
    30
    @classmethod
3a7ce5c9fe35 [web/test] Use TestCase.setUpClass instead of setUpModule
Julien Cristau <julien.cristau@logilab.fr>
parents: 8665
diff changeset
    31
    def setUpClass(cls):
3a7ce5c9fe35 [web/test] Use TestCase.setUpClass instead of setUpModule
Julien Cristau <julien.cristau@logilab.fr>
parents: 8665
diff changeset
    32
        super(WidgetsTC, cls).setUpClass()
3a7ce5c9fe35 [web/test] Use TestCase.setUpClass instead of setUpModule
Julien Cristau <julien.cristau@logilab.fr>
parents: 8665
diff changeset
    33
        config = TestServerConfiguration('data', apphome=cls.datadir)
3a7ce5c9fe35 [web/test] Use TestCase.setUpClass instead of setUpModule
Julien Cristau <julien.cristau@logilab.fr>
parents: 8665
diff changeset
    34
        config.bootstrap_cubes()
3a7ce5c9fe35 [web/test] Use TestCase.setUpClass instead of setUpModule
Julien Cristau <julien.cristau@logilab.fr>
parents: 8665
diff changeset
    35
        cls.schema = config.load_schema()
3a7ce5c9fe35 [web/test] Use TestCase.setUpClass instead of setUpModule
Julien Cristau <julien.cristau@logilab.fr>
parents: 8665
diff changeset
    36
3a7ce5c9fe35 [web/test] Use TestCase.setUpClass instead of setUpModule
Julien Cristau <julien.cristau@logilab.fr>
parents: 8665
diff changeset
    37
    @classmethod
3a7ce5c9fe35 [web/test] Use TestCase.setUpClass instead of setUpModule
Julien Cristau <julien.cristau@logilab.fr>
parents: 8665
diff changeset
    38
    def tearDownClass(cls):
3a7ce5c9fe35 [web/test] Use TestCase.setUpClass instead of setUpModule
Julien Cristau <julien.cristau@logilab.fr>
parents: 8665
diff changeset
    39
        del cls.schema
3a7ce5c9fe35 [web/test] Use TestCase.setUpClass instead of setUpModule
Julien Cristau <julien.cristau@logilab.fr>
parents: 8665
diff changeset
    40
        super(WidgetsTC, cls).tearDownClass()
3a7ce5c9fe35 [web/test] Use TestCase.setUpClass instead of setUpModule
Julien Cristau <julien.cristau@logilab.fr>
parents: 8665
diff changeset
    41
8029
805d4e121b65 [ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    42
    def test_editableurl_widget(self):
10596
3a7ce5c9fe35 [web/test] Use TestCase.setUpClass instead of setUpModule
Julien Cristau <julien.cristau@logilab.fr>
parents: 8665
diff changeset
    43
        field = formfields.guess_field(self.schema['Bookmark'], self.schema['path'])
6682
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    44
        widget = formwidgets.EditableURLWidget()
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    45
        req = fake.FakeRequest(form={'path-subjectfqs:A': 'param=value&vid=view'})
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    46
        form = mock(_cw=req, formvalues={}, edited_entity=mock(eid='A'))
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    47
        self.assertEqual(widget.process_field_data(form, field),
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    48
                         '?param=value%26vid%3Dview')
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    49
8029
805d4e121b65 [ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    50
    def test_bitselect_widget(self):
10596
3a7ce5c9fe35 [web/test] Use TestCase.setUpClass instead of setUpModule
Julien Cristau <julien.cristau@logilab.fr>
parents: 8665
diff changeset
    51
        field = formfields.guess_field(self.schema['CWAttribute'], self.schema['ordernum'])
8029
805d4e121b65 [ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    52
        field.choices = [('un', '1',), ('deux', '2',)]
805d4e121b65 [ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    53
        widget = formwidgets.BitSelect(settabindex=False)
805d4e121b65 [ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    54
        req = fake.FakeRequest(form={'ordernum-subject:A': ['1', '2']})
805d4e121b65 [ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    55
        form = mock(_cw=req, formvalues={}, edited_entity=mock(eid='A'),
805d4e121b65 [ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    56
                    form_previous_values=())
805d4e121b65 [ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    57
        self.assertMultiLineEqual(widget._render(form, field, None),
805d4e121b65 [ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    58
                             '''\
805d4e121b65 [ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    59
<select id="ordernum-subject:A" multiple="multiple" name="ordernum-subject:A" size="2">
805d4e121b65 [ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    60
<option selected="selected" value="2">deux</option>
805d4e121b65 [ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    61
<option selected="selected" value="1">un</option>
805d4e121b65 [ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    62
</select>''')
805d4e121b65 [ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    63
        self.assertEqual(widget.process_field_data(form, field),
805d4e121b65 [ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    64
                         3)
805d4e121b65 [ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    65
6682
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    66
if __name__ == '__main__':
bdf9424b499c test and fix #1232202: [bookmarks] broken link for startupviews
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    67
    unittest_main()