web/test/unittest_form.py
branchtls-sprint
changeset 1654 57b9fd2462b8
parent 1570 5c40d9fb4e8d
child 1739 78b0819162a8
equal deleted inserted replaced
1653:8b82227719f0 1654:57b9fd2462b8
   106                               expected % {'eid': state.eid})
   106                               expected % {'eid': state.eid})
   107 
   107 
   108 
   108 
   109     def test_richtextfield_1(self):
   109     def test_richtextfield_1(self):
   110         self.req.use_fckeditor = lambda: False
   110         self.req.use_fckeditor = lambda: False
   111         self._test_richtextfield('''<select name="description_format:%(eid)s" size="1" id="description_format:%(eid)s" tabindex="0">
   111         self._test_richtextfield('''<select id="description_format:%(eid)s" name="description_format:%(eid)s" size="1" tabindex="0">
   112 <option value="text/cubicweb-page-template">text/cubicweb-page-template</option>
   112 <option value="text/cubicweb-page-template">text/cubicweb-page-template</option>
   113 <option value="text/html">text/html</option>
   113 <option value="text/html">text/html</option>
   114 <option value="text/plain">text/plain</option>
   114 <option value="text/plain">text/plain</option>
   115 <option selected="selected" value="text/rest">text/rest</option>
   115 <option selected="selected" value="text/rest">text/rest</option>
   116 </select><textarea rows="5" name="description:564" onkeypress="autogrow(this)" cols="60" id="description:564" tabindex="1"/>''')
   116 </select><textarea cols="60" id="description:%(eid)s" name="description:%(eid)s" onkeypress="autogrow(this)" rows="5" tabindex="1"/>''')
   117 
   117 
   118 
   118 
   119     def test_richtextfield_2(self):
   119     def test_richtextfield_2(self):
   120         self.req.use_fckeditor = lambda: True
   120         self.req.use_fckeditor = lambda: True
   121         self._test_richtextfield('<input type="hidden" name="description_format:%(eid)s" value="text/rest"/><textarea rows="20" name="description:564" onkeypress="autogrow(this)" cols="80" cubicweb:type="wysiwyg" id="description:564" tabindex="0"/>')
   121         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"/>')
   122 
   122 
   123 
   123 
   124     def test_filefield(self):
   124     def test_filefield(self):
   125         class FFForm(EntityFieldsForm):
   125         class FFForm(EntityFieldsForm):
   126             data = FileField(format_field=StringField(name='data_format'),
   126             data = FileField(format_field=StringField(name='data_format'),
   127                              encoding_field=StringField(name='data_encoding'))
   127                              encoding_field=StringField(name='data_encoding'))
   128         file = self.add_entity('File', name=u"pouet.txt",
   128         file = self.add_entity('File', name=u"pouet.txt", data_encoding=u'UTF-8',
   129                                data=Binary('new widgets system'))
   129                                data=Binary('new widgets system'))
   130         form = FFForm(self.req, redirect_path='perdu.com', entity=file)
   130         form = FFForm(self.req, redirect_path='perdu.com', entity=file)
   131         self.assertTextEquals(self._render_entity_field('data', form),
   131         self.assertTextEquals(self._render_entity_field('data', form),
   132                               '''<input id="data:%(eid)s" type="file" name="data:%(eid)s" value="" tabindex="0"/>
   132                               '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="0" type="file" value=""/>
   133 <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>
   133 <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>
   134 <div id="data:%(eid)s-advanced" class="hidden">
   134 <div id="data:%(eid)s-advanced" class="hidden">
   135 <label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" type="text" name="data_format:%(eid)s" value="text/plain" tabindex="1"/><br/><br/>
   135 <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/>
   136 <label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" type="text" name="data_encoding:%(eid)s" value="UTF-8" tabindex="2"/><br/><br/>
   136 <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/>
   137 </div>
   137 </div>
   138 <br/>
   138 <br/>
   139 <input type="checkbox" name="data:%(eid)s__detach"/>
   139 <input name="data:%(eid)s__detach" type="checkbox"/>
   140 detach attached file
   140 detach attached file
   141 ''' % {'eid': file.eid})
   141 ''' % {'eid': file.eid})
   142 
   142 
   143 
   143 
   144     def test_editablefilefield(self):
   144     def test_editablefilefield(self):
   147                                      encoding_field=StringField(name='data_encoding'))
   147                                      encoding_field=StringField(name='data_encoding'))
   148             def form_field_encoding(self, field):
   148             def form_field_encoding(self, field):
   149                 return 'ascii'
   149                 return 'ascii'
   150             def form_field_format(self, field):
   150             def form_field_format(self, field):
   151                 return 'text/plain'
   151                 return 'text/plain'
   152         file = self.add_entity('File', name=u"pouet.txt",
   152         file = self.add_entity('File', name=u"pouet.txt", data_encoding=u'UTF-8', 
   153                                data=Binary('new widgets system'))
   153                                data=Binary('new widgets system'))
   154         form = EFFForm(self.req, redirect_path='perdu.com', entity=file)
   154         form = EFFForm(self.req, redirect_path='perdu.com', entity=file)
   155         self.assertTextEquals(self._render_entity_field('data', form),
   155         self.assertTextEquals(self._render_entity_field('data', form),
   156                               '''<input id="data:%(eid)s" type="file" name="data:%(eid)s" value="" tabindex="0"/>
   156                               '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="0" type="file" value=""/>
   157 <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>
   157 <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>
   158 <div id="data:%(eid)s-advanced" class="hidden">
   158 <div id="data:%(eid)s-advanced" class="hidden">
   159 <label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" type="text" name="data_format:%(eid)s" value="text/plain" tabindex="1"/><br/><br/>
   159 <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/>
   160 <label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" type="text" name="data_encoding:%(eid)s" value="UTF-8" tabindex="2"/><br/><br/>
   160 <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/>
   161 </div>
   161 </div>
   162 <br/>
   162 <br/>
   163 <input type="checkbox" name="data:%(eid)s__detach"/>
   163 <input name="data:%(eid)s__detach" type="checkbox"/>
   164 detach attached file
   164 detach attached file
   165 <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>
   165 <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>
   166 <textarea tabindex="3" rows="20" cols="80" name="data:%(eid)s" onkeypress="autogrow(this)">new widgets system</textarea>''' % {'eid': file.eid})
   166 <textarea cols="80" name="data:%(eid)s" onkeypress="autogrow(this)" rows="20" tabindex="3">new widgets system</textarea>''' % {'eid': file.eid})
   167 
   167 
   168 
   168 
   169     def test_passwordfield(self):
   169     def test_passwordfield(self):
   170         class PFForm(EntityFieldsForm):
   170         class PFForm(EntityFieldsForm):
   171             upassword = StringField(widget=PasswordInput)
   171             upassword = StringField(widget=PasswordInput)
   172         form = PFForm(self.req, redirect_path='perdu.com', entity=self.entity)
   172         form = PFForm(self.req, redirect_path='perdu.com', entity=self.entity)
   173         self.assertTextEquals(self._render_entity_field('upassword', form),
   173         self.assertTextEquals(self._render_entity_field('upassword', form),
   174                               '''<input id="upassword:%(eid)s" type="password" name="upassword:%(eid)s" value="__cubicweb_internal_field__" tabindex="0"/>
   174                               '''<input id="upassword:%(eid)s" name="upassword:%(eid)s" tabindex="0" type="password" value="__cubicweb_internal_field__"/>
   175 <br/>
   175 <br/>
   176 <input type="password" name="upassword-confirm:%(eid)s" value="__cubicweb_internal_field__" tabindex="0"/>
   176 <input name="upassword-confirm:%(eid)s" tabindex="0" type="password" value="__cubicweb_internal_field__"/>
   177 &nbsp;
   177 &nbsp;
   178 <span class="emphasis">confirm password</span>''' % {'eid': self.entity.eid})
   178 <span class="emphasis">confirm password</span>''' % {'eid': self.entity.eid})
   179 
   179 
   180 
   180 
   181 if __name__ == '__main__':
   181 if __name__ == '__main__':