web/test/unittest_formwidgets.py
branchstable
changeset 6682 bdf9424b499c
child 6781 5062d86d6ffe
equal deleted inserted replaced
6681:674461009c7c 6682:bdf9424b499c
       
     1 # copyright 2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     3 #
       
     4 # This file is part of CubicWeb.
       
     5 #
       
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
       
     7 # terms of the GNU Lesser General Public License as published by the Free
       
     8 # Software Foundation, either version 2.1 of the License, or (at your option)
       
     9 # any later version.
       
    10 #
       
    11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
       
    14 # details.
       
    15 #
       
    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/>.
       
    18 """unittests for cw.web.formwidgets"""
       
    19 
       
    20 from logilab.common.testlib import TestCase, unittest_main, mock_object as mock
       
    21 
       
    22 from cubicweb.devtools import TestServerConfiguration, fake
       
    23 from cubicweb.web import uicfg, formwidgets, formfields
       
    24 
       
    25 from cubes.file.entities import File
       
    26 
       
    27 def setup_module(*args):
       
    28     global schema
       
    29     config = TestServerConfiguration('data', apphome=WidgetsTC.datadir)
       
    30     config.bootstrap_cubes()
       
    31     schema = config.load_schema()
       
    32 
       
    33 class WidgetsTC(TestCase):
       
    34 
       
    35     def test_state_fields(self):
       
    36         field = formfields.guess_field(schema['Bookmark'], schema['path'])
       
    37         widget = formwidgets.EditableURLWidget()
       
    38         req = fake.FakeRequest(form={'path-subjectfqs:A': 'param=value&vid=view'})
       
    39         form = mock(_cw=req, formvalues={}, edited_entity=mock(eid='A'))
       
    40         self.assertEqual(widget.process_field_data(form, field),
       
    41                          '?param=value%26vid%3Dview')
       
    42 
       
    43 if __name__ == '__main__':
       
    44     unittest_main()