web/test/unittest_form.py
author sylvain.thenault@logilab.fr
Wed, 11 Mar 2009 11:18:57 +0100
branchtls-sprint
changeset 1052 4f746935e6b1
parent 907 192800415f59
child 1057 6636c75c4aa9
permissions -rw-r--r--
use assertTextEquals
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
907
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
     2
from cubicweb import Binary
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 868
diff changeset
     3
from cubicweb.devtools.testlib import WebTest
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
     4
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
     5
from cubicweb.web.views.baseforms import ChangeStateForm
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
     6
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 868
diff changeset
     7
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
     8
class CustomChangeStateForm(ChangeStateForm):
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
     9
    hello = IntField(name='youlou')
868
5d993a0c794c update test, use a DateTimePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 866
diff changeset
    10
    creation_date = DateTimeField(widget=DateTimePicker)
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 868
diff changeset
    11
894
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    12
907
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    13
class RTFForm(EntityFieldsForm):
894
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    14
    content = RichTextField()
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    15
907
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    16
class FFForm(EntityFieldsForm):
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    17
    data = FileField(format_field=StringField(name='data_format'),
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    18
                     encoding_field=StringField(name='data_encoding'))
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    19
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    20
class PFForm(EntityFieldsForm):
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    21
    upassword = StringField(widget=PasswordInput)
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    22
868
5d993a0c794c update test, use a DateTimePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 866
diff changeset
    23
    
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 868
diff changeset
    24
class EntityFieldsFormTC(WebTest):
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    25
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
    26
    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
    27
        super(EntityFieldsFormTC, self).setUp()
868
5d993a0c794c update test, use a DateTimePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 866
diff changeset
    28
        self.req = self.request()
5d993a0c794c update test, use a DateTimePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 866
diff changeset
    29
        self.entity = self.user(self.req)
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
    30
        
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 868
diff changeset
    31
    def test_form_inheritance(self):
894
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    32
        form = CustomChangeStateForm(self.req, redirect_path='perdu.com',
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    33
                                     entity=self.entity)
1052
4f746935e6b1 use assertTextEquals
sylvain.thenault@logilab.fr
parents: 907
diff changeset
    34
        self.assertTextEquals(form.form_render(state=123),
4f746935e6b1 use assertTextEquals
sylvain.thenault@logilab.fr
parents: 907
diff changeset
    35
                              ''' ''')
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 868
diff changeset
    36
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 868
diff changeset
    37
    def test_change_state_form(self):
894
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    38
        form = ChangeStateForm(self.req, redirect_path='perdu.com',
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    39
                               entity=self.entity)
1052
4f746935e6b1 use assertTextEquals
sylvain.thenault@logilab.fr
parents: 907
diff changeset
    40
        self.assertTextEquals(form.form_render(state=123, trcomment=u''),
4f746935e6b1 use assertTextEquals
sylvain.thenault@logilab.fr
parents: 907
diff changeset
    41
                              ''' ''')
894
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    42
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    43
    def test_richtextfield(self):
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    44
        card = self.add_entity('Card', title=u"tls sprint fev 2009",
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    45
                               content=u'new widgets system')
907
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    46
        form = RTFForm(self.req, redirect_path='perdu.com',
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    47
                       entity=card)
1052
4f746935e6b1 use assertTextEquals
sylvain.thenault@logilab.fr
parents: 907
diff changeset
    48
        self.assertTextEquals(form.form_render(),
4f746935e6b1 use assertTextEquals
sylvain.thenault@logilab.fr
parents: 907
diff changeset
    49
                              '''''')
907
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    50
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    51
    def test_filefield(self):
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    52
        file = self.add_entity('File', name=u"pouet.txt",
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    53
                               data=Binary('new widgets system'))
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    54
        form = FFForm(self.req, redirect_path='perdu.com',
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    55
                      entity=file)
1052
4f746935e6b1 use assertTextEquals
sylvain.thenault@logilab.fr
parents: 907
diff changeset
    56
        self.assertTextEquals(form.form_render(),
4f746935e6b1 use assertTextEquals
sylvain.thenault@logilab.fr
parents: 907
diff changeset
    57
                              '''''')
907
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    58
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    59
    def test_passwordfield(self):
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    60
        form = PFForm(self.req, redirect_path='perdu.com',
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    61
                      entity=self.entity)
1052
4f746935e6b1 use assertTextEquals
sylvain.thenault@logilab.fr
parents: 907
diff changeset
    62
        self.assertTextEquals(form.form_render(),
4f746935e6b1 use assertTextEquals
sylvain.thenault@logilab.fr
parents: 907
diff changeset
    63
                              '''''')
4f746935e6b1 use assertTextEquals
sylvain.thenault@logilab.fr
parents: 907
diff changeset
    64
        
4f746935e6b1 use assertTextEquals
sylvain.thenault@logilab.fr
parents: 907
diff changeset
    65
    def test_delete_conf_form_multi(self):
4f746935e6b1 use assertTextEquals
sylvain.thenault@logilab.fr
parents: 907
diff changeset
    66
        rset = self.execute('EGroup X')
4f746935e6b1 use assertTextEquals
sylvain.thenault@logilab.fr
parents: 907
diff changeset
    67
        self.assertTextEquals(self.view('deleteconf', rset, template=None).source,
4f746935e6b1 use assertTextEquals
sylvain.thenault@logilab.fr
parents: 907
diff changeset
    68
                              '')
4f746935e6b1 use assertTextEquals
sylvain.thenault@logilab.fr
parents: 907
diff changeset
    69
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    70
        
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    71
if __name__ == '__main__':
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    72
    unittest_main()