web/test/unittest_form.py
branchtls-sprint
changeset 847 27c4ebe90d03
parent 845 6103d0f55a0b
child 848 f5aca5c5f6ca
equal deleted inserted replaced
846:e449f1da7d09 847:27c4ebe90d03
     1 from logilab.common.testlib import TestCase, unittest_main, mock_object
     1 from logilab.common.testlib import TestCase, unittest_main, mock_object
       
     2 
     2 from cubicweb.web.form import *
     3 from cubicweb.web.form import *
     3 
     4 from cubicweb.web.views.baseforms import ChangeStateForm
     4 class ChangeStateForm(EntityFieldsForm):
       
     5     state = TextField(widget=HiddenInput, eidparam=False)
       
     6     __method = TextField(widget=HiddenInput, initial='set_state', eidparam=False)
       
     7     trcomment = RichTextField()
       
     8 
       
     9     def buttons(self):
       
    10         return []
       
    11 
     5 
    12 class CustomChangeStateForm(ChangeStateForm):
     6 class CustomChangeStateForm(ChangeStateForm):
    13     hello = IntField(name='youlou')
     7     hello = IntField(name='youlou')
    14 
     8 
    15 class EntityFieldsFormTC(TestCase):
     9 class EntityFieldsFormTC(TestCase):
    16 
    10 
       
    11     def setUp(self):
       
    12         def next_tabindex(self):
       
    13             self.count += 1
       
    14             return self.count
       
    15         self.req = mock_object(build_url=lambda *args,**kwargs: 'myurl.com',
       
    16                                _=lambda s,x: x,
       
    17                                next_tabindex=next_tabindex, count=0)
       
    18         self.entity = mock_object(eid=1)
       
    19         
    17     def test(self):
    20     def test(self):
    18         req = mock_object(build_url=lambda *args,**kwargs: 'myurl.com')
    21         form = ChangeStateForm(self.req, redirect_path='perdu.com')
    19         form = ChangeStateForm(req, redirect_path='perdu.com')
    22         self.assertEquals(form.form_render(self.entity, state=123),
    20         entity = mock_object(eid=1)
       
    21         self.assertEquals(form.render(entity, state=123),
       
    22                           '''''')
    23                           '''''')
    23 
    24 
    24     def test_form_inheritance(self):
    25     def test_form_inheritance(self):
    25         req = mock_object(build_url=lambda *args,**kwargs: 'myurl.com')
    26         form = CustomChangeStateForm(self.req, redirect_path='perdu.com')
    26         form = CustomChangeStateForm(req, redirect_path='perdu.com')
    27         self.assertEquals(form.form_render(self.entity, state=123),
    27         entity = mock_object(eid=1)
       
    28         self.assertEquals(form.render(entity, state=123),
       
    29                           '''''')
    28                           '''''')
    30         
    29         
    31         
    30         
    32 if __name__ == '__main__':
    31 if __name__ == '__main__':
    33     unittest_main()
    32     unittest_main()