web/test/unittest_form.py
author Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
Thu, 19 Feb 2009 21:38:04 +0100
branchtls-sprint
changeset 866 6fdb029663ca
parent 848 f5aca5c5f6ca
child 868 5d993a0c794c
permissions -rw-r--r--
use EnvBasedTC since we need to access the schema
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
866
6fdb029663ca use EnvBasedTC since we need to access the schema
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 848
diff changeset
     1
from logilab.common.testlib import unittest_main, mock_object
6fdb029663ca use EnvBasedTC since we need to access the schema
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 848
diff changeset
     2
from cubicweb.devtools.apptest import EnvBasedTC
847
27c4ebe90d03 prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents: 845
diff changeset
     3
from cubicweb.web.form import *
27c4ebe90d03 prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents: 845
diff changeset
     4
from cubicweb.web.views.baseforms import ChangeStateForm
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
     5
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
     6
class CustomChangeStateForm(ChangeStateForm):
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
     7
    hello = IntField(name='youlou')
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
     8
866
6fdb029663ca use EnvBasedTC since we need to access the schema
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 848
diff changeset
     9
class EntityFieldsFormTC(EnvBasedTC):
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    10
847
27c4ebe90d03 prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents: 845
diff changeset
    11
    def setUp(self):
866
6fdb029663ca use EnvBasedTC since we need to access the schema
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 848
diff changeset
    12
        super(EntityFieldsFormTC, self).setUp()
6fdb029663ca use EnvBasedTC since we need to access the schema
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 848
diff changeset
    13
##         def next_tabindex(self):
6fdb029663ca use EnvBasedTC since we need to access the schema
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 848
diff changeset
    14
##             self.count += 1
6fdb029663ca use EnvBasedTC since we need to access the schema
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 848
diff changeset
    15
##             return self.count
6fdb029663ca use EnvBasedTC since we need to access the schema
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 848
diff changeset
    16
##         self.req = mock_object(build_url=lambda *args,**kwargs: 'myurl.com/pouet',
6fdb029663ca use EnvBasedTC since we need to access the schema
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 848
diff changeset
    17
##                                url=lambda *args,**kwargs: 'myurl.com/form',
6fdb029663ca use EnvBasedTC since we need to access the schema
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 848
diff changeset
    18
##                                _=lambda s,x: x, form={}, data={},
6fdb029663ca use EnvBasedTC since we need to access the schema
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 848
diff changeset
    19
##                                next_tabindex=next_tabindex, count=0)
6fdb029663ca use EnvBasedTC since we need to access the schema
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 848
diff changeset
    20
##         self.entity = mock_object(eid=1, has_eid=lambda x: False, id='Entity')
847
27c4ebe90d03 prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents: 845
diff changeset
    21
        
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    22
    def test(self):
866
6fdb029663ca use EnvBasedTC since we need to access the schema
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 848
diff changeset
    23
        req = self.request()
6fdb029663ca use EnvBasedTC since we need to access the schema
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 848
diff changeset
    24
        form = ChangeStateForm(req, redirect_path='perdu.com')
6fdb029663ca use EnvBasedTC since we need to access the schema
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 848
diff changeset
    25
        self.assertEquals(form.form_render(self.user(req), state=123),
6fdb029663ca use EnvBasedTC since we need to access the schema
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 848
diff changeset
    26
                          ''' ''')
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    27
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    28
    def test_form_inheritance(self):
847
27c4ebe90d03 prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents: 845
diff changeset
    29
        form = CustomChangeStateForm(self.req, redirect_path='perdu.com')
27c4ebe90d03 prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents: 845
diff changeset
    30
        self.assertEquals(form.form_render(self.entity, state=123),
866
6fdb029663ca use EnvBasedTC since we need to access the schema
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 848
diff changeset
    31
                          ''' ''')
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    32
        
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    33
        
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    34
if __name__ == '__main__':
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    35
    unittest_main()