web/test/unittest_form.py
author sylvain.thenault@logilab.fr
Fri, 20 Feb 2009 17:20:53 +0100
branchtls-sprint
changeset 907 192800415f59
parent 894 e1f848785e3d
child 1052 4f746935e6b1
permissions -rw-r--r--
FileField backport
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)
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    34
        self.assertEquals(form.form_render(state=123),
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 868
diff changeset
    35
                          ''' ''')
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)
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    40
        self.assertEquals(form.form_render(state=123),
866
6fdb029663ca use EnvBasedTC since we need to access the schema
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 848
diff changeset
    41
                          ''' ''')
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    42
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 868
diff changeset
    43
    def test_delete_conf_form_multi(self):
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 868
diff changeset
    44
        rset = self.execute('EGroup X')
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 868
diff changeset
    45
        self.assertEquals(self.view('deleteconf', rset).source,
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 868
diff changeset
    46
                          '')
894
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    47
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    48
    def test_richtextfield(self):
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    49
        card = self.add_entity('Card', title=u"tls sprint fev 2009",
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    50
                               content=u'new widgets system')
907
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    51
        form = RTFForm(self.req, redirect_path='perdu.com',
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    52
                       entity=card)
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    53
        self.assertEquals(form.form_render(),
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    54
                          '''''')
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    55
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    56
    def test_filefield(self):
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    57
        file = self.add_entity('File', name=u"pouet.txt",
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    58
                               data=Binary('new widgets system'))
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    59
        form = FFForm(self.req, redirect_path='perdu.com',
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    60
                      entity=file)
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    61
        self.assertEquals(form.form_render(),
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    62
                          '''''')
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    63
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    64
    def test_passwordfield(self):
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    65
        form = PFForm(self.req, redirect_path='perdu.com',
192800415f59 FileField backport
sylvain.thenault@logilab.fr
parents: 894
diff changeset
    66
                      entity=self.entity)
894
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    67
        self.assertEquals(form.form_render(),
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    68
                          '''''')
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    69
        
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    70
if __name__ == '__main__':
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    71
    unittest_main()