web/test/unittest_form.py
author sylvain.thenault@logilab.fr
Thu, 19 Feb 2009 18:22:55 +0100
branchtls-sprint
changeset 845 6103d0f55a0b
child 847 27c4ebe90d03
permissions -rw-r--r--
simple tags
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
     1
from logilab.common.testlib import TestCase, unittest_main, mock_object
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
     2
from cubicweb.web.form import *
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
     3
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
     4
class ChangeStateForm(EntityFieldsForm):
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
     5
    state = TextField(widget=HiddenInput, eidparam=False)
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
     6
    __method = TextField(widget=HiddenInput, initial='set_state', eidparam=False)
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
     7
    trcomment = RichTextField()
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
     8
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
     9
    def buttons(self):
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    10
        return []
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    11
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    12
class CustomChangeStateForm(ChangeStateForm):
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    13
    hello = IntField(name='youlou')
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    14
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    15
class EntityFieldsFormTC(TestCase):
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    16
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    17
    def test(self):
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    18
        req = mock_object(build_url=lambda *args,**kwargs: 'myurl.com')
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    19
        form = ChangeStateForm(req, redirect_path='perdu.com')
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    20
        entity = mock_object(eid=1)
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    21
        self.assertEquals(form.render(entity, state=123),
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    22
                          '''''')
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    23
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    24
    def test_form_inheritance(self):
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    25
        req = mock_object(build_url=lambda *args,**kwargs: 'myurl.com')
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    26
        form = CustomChangeStateForm(req, redirect_path='perdu.com')
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    27
        entity = mock_object(eid=1)
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    28
        self.assertEquals(form.render(entity, state=123),
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    29
                          '''''')
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    30
        
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    31
        
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    32
if __name__ == '__main__':
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    33
    unittest_main()