web/test/unittest_form.py
changeset 4390 0285c1fa1459
parent 4252 6c4f109c2b03
child 4536 02d0803a60b8
equal deleted inserted replaced
4389:14a993bc8d1e 4390:0285c1fa1459
    13 from logilab.common.compat import any
    13 from logilab.common.compat import any
    14 
    14 
    15 from cubicweb import Binary
    15 from cubicweb import Binary
    16 from cubicweb.devtools.testlib import CubicWebTC
    16 from cubicweb.devtools.testlib import CubicWebTC
    17 from cubicweb.web.formfields import (IntField, StringField, RichTextField,
    17 from cubicweb.web.formfields import (IntField, StringField, RichTextField,
    18                                      PasswordField, DateTimeField, DateTimePicker,
    18                                      PasswordField, DateTimeField,
    19                                      FileField, EditableFileField)
    19                                      FileField, EditableFileField)
    20 from cubicweb.web.formwidgets import PasswordInput, Input
    20 from cubicweb.web.formwidgets import PasswordInput, Input, DateTimePicker
    21 from cubicweb.web.views.forms import EntityFieldsForm, FieldsForm
    21 from cubicweb.web.views.forms import EntityFieldsForm, FieldsForm
    22 from cubicweb.web.views.workflow import ChangeStateForm
    22 from cubicweb.web.views.workflow import ChangeStateForm
    23 from cubicweb.web.views.formrenderers import FormRenderer
    23 from cubicweb.web.views.formrenderers import FormRenderer
    24 
    24 
    25 
    25 
    65 
    65 
    66     def test_consider_req_form_params(self):
    66     def test_consider_req_form_params(self):
    67         e = self.vreg['etypes'].etype_class('CWUser')(self.request())
    67         e = self.vreg['etypes'].etype_class('CWUser')(self.request())
    68         e.eid = 'A'
    68         e.eid = 'A'
    69         form = EntityFieldsForm(self.request(login=u'toto'), None, entity=e)
    69         form = EntityFieldsForm(self.request(login=u'toto'), None, entity=e)
    70         field = StringField(name='login', eidparam=True)
    70         field = StringField(name='login', role='subject', eidparam=True)
    71         form.append_field(field)
    71         form.append_field(field)
    72         form.build_context({})
    72         form.build_context({})
    73         self.assertEquals(field.display_value(form), 'toto')
    73         self.assertEquals(field.widget.values(form, field), (u'toto',))
    74 
    74 
    75 
    75 
    76     def test_linkto_field_duplication(self):
    76     def test_linkto_field_duplication(self):
    77         e = self.vreg['etypes'].etype_class('CWUser')(self.request())
    77         e = self.vreg['etypes'].etype_class('CWUser')(self.request())
    78         e.eid = 'A'
    78         e.eid = 'A'
   128         return form.field_by_name(name, 'subject').render(form, renderer)
   128         return form.field_by_name(name, 'subject').render(form, renderer)
   129 
   129 
   130     def _test_richtextfield(self, expected):
   130     def _test_richtextfield(self, expected):
   131         class RTFForm(EntityFieldsForm):
   131         class RTFForm(EntityFieldsForm):
   132             description = RichTextField(eidparam=True, role='subject')
   132             description = RichTextField(eidparam=True, role='subject')
   133         state = self.execute('State X WHERE X name "activated", X state_of WF, WF workflow_of ET, ET name "CWUser"').get_entity(0, 0)
   133         state = self.vreg['etypes'].etype_class('State')(self.req)
       
   134         state.eid = 'S'
   134         form = RTFForm(self.req, redirect_path='perdu.com', entity=state)
   135         form = RTFForm(self.req, redirect_path='perdu.com', entity=state)
   135         # make it think it can use fck editor anyway
   136         # make it think it can use fck editor anyway
   136         form.field_by_name('description', 'subject').format = lambda x: 'text/html'
   137         form.field_by_name('description', 'subject').format = lambda x: 'text/html'
   137         self.assertTextEquals(self._render_entity_field('description', form),
   138         self.assertTextEquals(self._render_entity_field('description', form),
   138                               expected % {'eid': state.eid})
   139                               expected % {'eid': state.eid})