web/test/unittest_form.py
changeset 2181 94ca417b9b07
parent 2144 51c84d585456
parent 2174 7f576dc9502e
child 2234 1fbcf202882d
equal deleted inserted replaced
2144:51c84d585456 2181:94ca417b9b07
     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 
   179                                      encoding_field=StringField(name='data_encoding', max_length=20))
   181                                      encoding_field=StringField(name='data_encoding', max_length=20))
   180             def form_field_encoding(self, field):
   182             def form_field_encoding(self, field):
   181                 return 'ascii'
   183                 return 'ascii'
   182             def form_field_format(self, field):
   184             def form_field_format(self, field):
   183                 return 'text/plain'
   185                 return 'text/plain'
   184         file = self.add_entity('File', name=u"pouet.txt", data_encoding=u'UTF-8', 
   186         file = self.add_entity('File', name=u"pouet.txt", data_encoding=u'UTF-8',
   185                                data=Binary('new widgets system'))
   187                                data=Binary('new widgets system'))
   186         form = EFFForm(self.req, redirect_path='perdu.com', entity=file)
   188         form = EFFForm(self.req, redirect_path='perdu.com', entity=file)
   187         self.assertTextEquals(self._render_entity_field('data', form),
   189         self.assertTextEquals(self._render_entity_field('data', form),
   188                               '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="0" type="file" value=""/>
   190                               '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="0" type="file" value=""/>
   189 <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>
   191 <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>
   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()