web/test/unittest_form.py
author sylvain.thenault@logilab.fr
Tue, 12 May 2009 11:56:12 +0200
branchtls-sprint
changeset 1739 78b0819162a8
parent 1654 57b9fd2462b8
child 1793 fdac26e003e7
permissions -rw-r--r--
final rtag api
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
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1654
diff changeset
     4
from cubicweb.web.form import EntityFieldsForm, FieldsForm
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1654
diff changeset
     5
from cubicweb.web.formrenderers import FormRenderer
1111
bcb81e7c41bc fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
sylvain.thenault@logilab.fr
parents: 1074
diff changeset
     6
from cubicweb.web.formfields import (IntField, StringField, RichTextField,
bcb81e7c41bc fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
sylvain.thenault@logilab.fr
parents: 1074
diff changeset
     7
                                     DateTimeField, DateTimePicker,
bcb81e7c41bc fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
sylvain.thenault@logilab.fr
parents: 1074
diff changeset
     8
                                     FileField, EditableFileField)
bcb81e7c41bc fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
sylvain.thenault@logilab.fr
parents: 1074
diff changeset
     9
from cubicweb.web.formwidgets import PasswordInput
bcb81e7c41bc fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
sylvain.thenault@logilab.fr
parents: 1074
diff changeset
    10
from cubicweb.web.views.workflow import ChangeStateForm
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    11
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 868
diff changeset
    12
1359
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    13
class FieldsFormTC(WebTest):
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    14
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    15
    def test_form_field_format(self):
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    16
        form = FieldsForm(self.request(), None)
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    17
        self.assertEquals(form.form_field_format(None), 'text/html')
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1393
diff changeset
    18
        self.execute('INSERT CWProperty X: X pkey "ui.default-text-format", X value "text/rest", X for_user U WHERE U login "admin"')
1359
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    19
        self.commit()
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    20
        self.assertEquals(form.form_field_format(None), 'text/rest')
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    21
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    22
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 868
diff changeset
    23
class EntityFieldsFormTC(WebTest):
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    24
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
    25
    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
    26
        super(EntityFieldsFormTC, self).setUp()
868
5d993a0c794c update test, use a DateTimePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 866
diff changeset
    27
        self.req = self.request()
5d993a0c794c update test, use a DateTimePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 866
diff changeset
    28
        self.entity = self.user(self.req)
1057
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
    29
        self.renderer = FormRenderer()
1570
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    30
1345
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    31
    def test_form_field_vocabulary_unrelated(self):
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    32
        b = self.add_entity('BlogEntry', title=u'di mascii code', content=u'a best-seller')
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    33
        t = self.add_entity('Tag', name=u'x')
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    34
        form1 = EntityFieldsForm(self.request(), None, entity=t)
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    35
        unrelated = [reid for rview, reid in form1.subject_relation_vocabulary('tags')]
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    36
        self.failUnless(b.eid in unrelated, unrelated)
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    37
        form2 = EntityFieldsForm(self.request(), None, entity=b)
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    38
        unrelated = [reid for rview, reid in form2.object_relation_vocabulary('tags')]
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    39
        self.failUnless(t.eid in unrelated, unrelated)
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    40
        self.execute('SET X tags Y WHERE X is Tag, Y is BlogEntry')
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    41
        unrelated = [reid for rview, reid in form1.subject_relation_vocabulary('tags')]
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    42
        self.failIf(b.eid in unrelated, unrelated)
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    43
        unrelated = [reid for rview, reid in form2.object_relation_vocabulary('tags')]
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    44
        self.failIf(t.eid in unrelated, unrelated)
1570
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    45
1345
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    46
    def test_form_field_vocabulary_new_entity(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1393
diff changeset
    47
        e = self.etype_instance('CWUser')
1345
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    48
        form = EntityFieldsForm(self.request(), None, entity=e)
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    49
        unrelated = [rview for rview, reid in form.subject_relation_vocabulary('in_group')]
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    50
        # should be default groups but owners, i.e. managers, users, guests
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    51
        self.assertEquals(unrelated, [u'guests', u'managers', u'users'])
9f086baa2537 backport tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    52
1359
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    53
    def test_subject_in_state_vocabulary(self):
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    54
        # on a new entity
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1393
diff changeset
    55
        e = self.etype_instance('CWUser')
1359
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    56
        form = EntityFieldsForm(self.request(), None, entity=e)
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    57
        states = list(form.subject_in_state_vocabulary('in_state'))
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    58
        self.assertEquals(len(states), 1)
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    59
        self.assertEquals(states[0][0], u'activated') # list of (combobox view, state eid)
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    60
        # on an existant entity
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    61
        e = self.user()
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    62
        form = EntityFieldsForm(self.request(), None, entity=e)
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    63
        states = list(form.subject_in_state_vocabulary('in_state'))
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    64
        self.assertEquals(len(states), 1)
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    65
        self.assertEquals(states[0][0], u'deactivated') # list of (combobox view, state eid)
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    66
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1345
diff changeset
    67
1570
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    68
1181
620ec8e6ae19 cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
    69
    # form view tests #########################################################
1570
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    70
1181
620ec8e6ae19 cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
    71
    def test_massmailing_formview(self):
620ec8e6ae19 cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
    72
        self.execute('INSERT EmailAddress X: X address L + "@cubicweb.org", '
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1393
diff changeset
    73
                     'U use_email X WHERE U is CWUser, U login L')
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1393
diff changeset
    74
        rset = self.execute('CWUser X')
1181
620ec8e6ae19 cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
    75
        self.view('massmailing', rset, template=None)
1570
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    76
1181
620ec8e6ae19 cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents: 1147
diff changeset
    77
1057
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
    78
    # form tests ##############################################################
1570
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    79
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 868
diff changeset
    80
    def test_form_inheritance(self):
1057
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
    81
        class CustomChangeStateForm(ChangeStateForm):
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
    82
            hello = IntField(name='youlou')
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
    83
            creation_date = DateTimeField(widget=DateTimePicker)
894
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    84
        form = CustomChangeStateForm(self.req, redirect_path='perdu.com',
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    85
                                     entity=self.entity)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1111
diff changeset
    86
        form.form_render(state=123, trcomment=u'')
869
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 868
diff changeset
    87
168ad6d424d1 form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents: 868
diff changeset
    88
    def test_change_state_form(self):
894
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    89
        form = ChangeStateForm(self.req, redirect_path='perdu.com',
e1f848785e3d test and fixes
sylvain.thenault@logilab.fr
parents: 869
diff changeset
    90
                               entity=self.entity)
1147
402e8a8b1d6a more form works
sylvain.thenault@logilab.fr
parents: 1111
diff changeset
    91
        form.form_render(state=123, trcomment=u'')
1570
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    92
1057
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
    93
    # fields tests ############################################################
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
    94
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
    95
    def _render_entity_field(self, name, form):
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
    96
        form.form_build_context({})
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
    97
        return form.field_by_name(name).render(form, self.renderer)
1570
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    98
1057
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
    99
    def _test_richtextfield(self, expected):
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   100
        class RTFForm(EntityFieldsForm):
1570
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   101
            description = RichTextField()
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   102
        state = self.execute('State X WHERE X name "activated", X state_of ET, ET name "CWUser"').get_entity(0, 0)
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   103
        form = RTFForm(self.req, redirect_path='perdu.com', entity=state)
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   104
        # make it think it can use fck editor anyway
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   105
        form.form_field_format = lambda x: 'text/html'
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   106
        self.assertTextEquals(self._render_entity_field('description', form),
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   107
                              expected % {'eid': state.eid})
1111
bcb81e7c41bc fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
sylvain.thenault@logilab.fr
parents: 1074
diff changeset
   108
1570
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   109
1057
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   110
    def test_richtextfield_1(self):
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   111
        self.req.use_fckeditor = lambda: False
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1570
diff changeset
   112
        self._test_richtextfield('''<select id="description_format:%(eid)s" name="description_format:%(eid)s" size="1" tabindex="0">
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1181
diff changeset
   113
<option value="text/cubicweb-page-template">text/cubicweb-page-template</option>
1570
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   114
<option value="text/html">text/html</option>
1057
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   115
<option value="text/plain">text/plain</option>
1570
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   116
<option selected="selected" value="text/rest">text/rest</option>
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1570
diff changeset
   117
</select><textarea cols="60" id="description:%(eid)s" name="description:%(eid)s" onkeypress="autogrow(this)" rows="5" tabindex="1"/>''')
1111
bcb81e7c41bc fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
sylvain.thenault@logilab.fr
parents: 1074
diff changeset
   118
1570
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   119
1057
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   120
    def test_richtextfield_2(self):
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   121
        self.req.use_fckeditor = lambda: True
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1570
diff changeset
   122
        self._test_richtextfield('<input name="description_format:%(eid)s" type="hidden" value="text/rest"/><textarea cols="80" cubicweb:type="wysiwyg" id="description:%(eid)s" name="description:%(eid)s" onkeypress="autogrow(this)" rows="20" tabindex="0"/>')
1057
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   123
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   124
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   125
    def test_filefield(self):
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   126
        class FFForm(EntityFieldsForm):
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   127
            data = FileField(format_field=StringField(name='data_format'),
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   128
                             encoding_field=StringField(name='data_encoding'))
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1570
diff changeset
   129
        file = self.add_entity('File', name=u"pouet.txt", data_encoding=u'UTF-8',
1057
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   130
                               data=Binary('new widgets system'))
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   131
        form = FFForm(self.req, redirect_path='perdu.com', entity=file)
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   132
        self.assertTextEquals(self._render_entity_field('data', form),
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1570
diff changeset
   133
                              '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="0" type="file" value=""/>
1111
bcb81e7c41bc fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
sylvain.thenault@logilab.fr
parents: 1074
diff changeset
   134
<a href="javascript: toggleVisibility(&#39;data:%(eid)s-advanced&#39;)" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a>
bcb81e7c41bc fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
sylvain.thenault@logilab.fr
parents: 1074
diff changeset
   135
<div id="data:%(eid)s-advanced" class="hidden">
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1570
diff changeset
   136
<label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" name="data_format:%(eid)s" tabindex="1" type="text" value="text/plain"/><br/><br/>
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1570
diff changeset
   137
<label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" name="data_encoding:%(eid)s" tabindex="2" type="text" value="UTF-8"/><br/><br/>
1111
bcb81e7c41bc fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
sylvain.thenault@logilab.fr
parents: 1074
diff changeset
   138
</div>
bcb81e7c41bc fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
sylvain.thenault@logilab.fr
parents: 1074
diff changeset
   139
<br/>
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1570
diff changeset
   140
<input name="data:%(eid)s__detach" type="checkbox"/>
1111
bcb81e7c41bc fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
sylvain.thenault@logilab.fr
parents: 1074
diff changeset
   141
detach attached file
bcb81e7c41bc fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
sylvain.thenault@logilab.fr
parents: 1074
diff changeset
   142
''' % {'eid': file.eid})
1057
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   143
1570
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   144
1057
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   145
    def test_editablefilefield(self):
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   146
        class EFFForm(EntityFieldsForm):
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   147
            data = EditableFileField(format_field=StringField(name='data_format'),
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   148
                                     encoding_field=StringField(name='data_encoding'))
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   149
            def form_field_encoding(self, field):
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   150
                return 'ascii'
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   151
            def form_field_format(self, field):
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   152
                return 'text/plain'
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1570
diff changeset
   153
        file = self.add_entity('File', name=u"pouet.txt", data_encoding=u'UTF-8', 
1057
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   154
                               data=Binary('new widgets system'))
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   155
        form = EFFForm(self.req, redirect_path='perdu.com', entity=file)
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   156
        self.assertTextEquals(self._render_entity_field('data', form),
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1570
diff changeset
   157
                              '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="0" type="file" value=""/>
1111
bcb81e7c41bc fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
sylvain.thenault@logilab.fr
parents: 1074
diff changeset
   158
<a href="javascript: toggleVisibility(&#39;data:%(eid)s-advanced&#39;)" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a>
bcb81e7c41bc fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
sylvain.thenault@logilab.fr
parents: 1074
diff changeset
   159
<div id="data:%(eid)s-advanced" class="hidden">
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1570
diff changeset
   160
<label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" name="data_format:%(eid)s" tabindex="1" type="text" value="text/plain"/><br/><br/>
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1570
diff changeset
   161
<label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" name="data_encoding:%(eid)s" tabindex="2" type="text" value="UTF-8"/><br/><br/>
1057
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   162
</div>
1111
bcb81e7c41bc fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
sylvain.thenault@logilab.fr
parents: 1074
diff changeset
   163
<br/>
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1570
diff changeset
   164
<input name="data:%(eid)s__detach" type="checkbox"/>
1111
bcb81e7c41bc fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
sylvain.thenault@logilab.fr
parents: 1074
diff changeset
   165
detach attached file
1057
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   166
<p><b>You can either submit a new file using the browse button above, or choose to remove already uploaded file by checking the "detach attached file" check-box, or edit file content online with the widget below.</b></p>
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1570
diff changeset
   167
<textarea cols="80" name="data:%(eid)s" onkeypress="autogrow(this)" rows="20" tabindex="3">new widgets system</textarea>''' % {'eid': file.eid})
1111
bcb81e7c41bc fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
sylvain.thenault@logilab.fr
parents: 1074
diff changeset
   168
1057
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   169
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   170
    def test_passwordfield(self):
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   171
        class PFForm(EntityFieldsForm):
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   172
            upassword = StringField(widget=PasswordInput)
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   173
        form = PFForm(self.req, redirect_path='perdu.com', entity=self.entity)
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   174
        self.assertTextEquals(self._render_entity_field('upassword', form),
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1570
diff changeset
   175
                              '''<input id="upassword:%(eid)s" name="upassword:%(eid)s" tabindex="0" type="password" value="__cubicweb_internal_field__"/>
1057
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   176
<br/>
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1570
diff changeset
   177
<input name="upassword-confirm:%(eid)s" tabindex="0" type="password" value="__cubicweb_internal_field__"/>
1057
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   178
&nbsp;
1111
bcb81e7c41bc fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
sylvain.thenault@logilab.fr
parents: 1074
diff changeset
   179
<span class="emphasis">confirm password</span>''' % {'eid': self.entity.eid})
1057
6636c75c4aa9 actual fields test, though it's still to early for form tests
sylvain.thenault@logilab.fr
parents: 1052
diff changeset
   180
1570
5c40d9fb4e8d stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   181
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
   182
if __name__ == '__main__':
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
   183
    unittest_main()