web/test/unittest_form.py
branchstable
changeset 2174 7f576dc9502e
parent 2172 cf8f9180e63e
parent 2147 476a75ede2cc
child 2181 94ca417b9b07
child 2198 ac45d4dbaf76
equal deleted inserted replaced
2173:7fae9300b9f9 2174:7f576dc9502e
     4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     7 """
     7 """
     8 
     8 
       
     9 from xml.etree.ElementTree import fromstring
       
    10 
     9 from logilab.common.testlib import unittest_main, mock_object
    11 from logilab.common.testlib import unittest_main, mock_object
    10 
    12 
    11 from cubicweb import Binary
    13 from cubicweb import Binary
    12 from cubicweb.devtools.testlib import WebTest
    14 from cubicweb.devtools.testlib import WebTest
    13 from cubicweb.web.formfields import (IntField, StringField, RichTextField,
    15 from cubicweb.web.formfields import (IntField, StringField, RichTextField,
    14                                      DateTimeField, DateTimePicker,
    16                                      DateTimeField, DateTimePicker,
    15                                      FileField, EditableFileField)
    17                                      FileField, EditableFileField)
    16 from cubicweb.web.formwidgets import PasswordInput
    18 from cubicweb.web.formwidgets import PasswordInput, Input
    17 from cubicweb.web.views.forms import EntityFieldsForm, FieldsForm
    19 from cubicweb.web.views.forms import EntityFieldsForm, FieldsForm
    18 from cubicweb.web.views.workflow import ChangeStateForm
    20 from cubicweb.web.views.workflow import ChangeStateForm
    19 from cubicweb.web.views.formrenderers import FormRenderer
    21 from cubicweb.web.views.formrenderers import FormRenderer
    20 
    22 
    21 
    23 
   143         self._test_richtextfield('''<select id="description_format:%(eid)s" name="description_format:%(eid)s" size="1" style="display: block" tabindex="0">
   145         self._test_richtextfield('''<select id="description_format:%(eid)s" name="description_format:%(eid)s" size="1" style="display: block" tabindex="0">
   144 <option value="text/cubicweb-page-template">text/cubicweb-page-template</option>
   146 <option value="text/cubicweb-page-template">text/cubicweb-page-template</option>
   145 <option value="text/html">text/html</option>
   147 <option value="text/html">text/html</option>
   146 <option value="text/plain">text/plain</option>
   148 <option value="text/plain">text/plain</option>
   147 <option selected="selected" value="text/rest">text/rest</option>
   149 <option selected="selected" value="text/rest">text/rest</option>
   148 </select><textarea cols="60" id="description:%(eid)s" name="description:%(eid)s" onkeypress="autogrow(this)" rows="5" tabindex="1"/>''')
   150 </select><textarea cols="60" id="description:%(eid)s" name="description:%(eid)s" onkeyup="autogrow(this)" rows="5" tabindex="1"/>''')
   149 
   151 
   150 
   152 
   151     def test_richtextfield_2(self):
   153     def test_richtextfield_2(self):
   152         self.req.use_fckeditor = lambda: True
   154         self.req.use_fckeditor = lambda: True
   153         self._test_richtextfield('<input name="description_format:%(eid)s" style="display: block" 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"/>')
   155         self._test_richtextfield('<input name="description_format:%(eid)s" style="display: block" type="hidden" value="text/rest"/><textarea cols="80" cubicweb:type="wysiwyg" id="description:%(eid)s" name="description:%(eid)s" onkeyup="autogrow(this)" rows="20" tabindex="0"/>')
   154 
   156 
   155 
   157 
   156     def test_filefield(self):
   158     def test_filefield(self):
   157         class FFForm(EntityFieldsForm):
   159         class FFForm(EntityFieldsForm):
   158             data = FileField(format_field=StringField(name='data_format', max_length=50),
   160             data = FileField(format_field=StringField(name='data_format', max_length=50),
   193 </div>
   195 </div>
   194 <br/>
   196 <br/>
   195 <input name="data:%(eid)s__detach" type="checkbox"/>
   197 <input name="data:%(eid)s__detach" type="checkbox"/>
   196 detach attached file
   198 detach attached file
   197 <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>
   199 <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>
   198 <textarea cols="80" name="data:%(eid)s" onkeypress="autogrow(this)" rows="20" tabindex="3">new widgets system</textarea>''' % {'eid': file.eid})
   200 <textarea cols="80" name="data:%(eid)s" onkeyup="autogrow(this)" rows="20" tabindex="3">new widgets system</textarea>''' % {'eid': file.eid})
   199 
   201 
   200 
   202 
   201     def test_passwordfield(self):
   203     def test_passwordfield(self):
   202         class PFForm(EntityFieldsForm):
   204         class PFForm(EntityFieldsForm):
   203             upassword = StringField(widget=PasswordInput)
   205             upassword = StringField(widget=PasswordInput)
   208 <input name="upassword-confirm:%(eid)s" tabindex="0" type="password" value="__cubicweb_internal_field__"/>
   210 <input name="upassword-confirm:%(eid)s" tabindex="0" type="password" value="__cubicweb_internal_field__"/>
   209 &nbsp;
   211 &nbsp;
   210 <span class="emphasis">confirm password</span>''' % {'eid': self.entity.eid})
   212 <span class="emphasis">confirm password</span>''' % {'eid': self.entity.eid})
   211 
   213 
   212 
   214 
       
   215     def test_datefield(self):
       
   216         class DFForm(EntityFieldsForm):
       
   217             creation_date = DateTimeField(widget=Input)
       
   218         form = DFForm(self.req, entity=self.entity)
       
   219         init, cur = (fromstring(self._render_entity_field(attr, form)).get('value')
       
   220                      for attr in ('edits-creation_date', 'creation_date'))
       
   221         self.assertEquals(init, cur)
       
   222 
   213 if __name__ == '__main__':
   223 if __name__ == '__main__':
   214     unittest_main()
   224     unittest_main()