fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs... tls-sprint
authorsylvain.thenault@logilab.fr
Thu, 12 Mar 2009 20:46:30 +0100
branchtls-sprint
changeset 1111 bcb81e7c41bc
parent 1110 c71997f514ba
child 1129 c0603e04727d
fix test: form_add_entity_hiddens *must* be called before build context, resulting in slightly different outputs...
web/test/unittest_form.py
--- a/web/test/unittest_form.py	Thu Mar 12 20:45:39 2009 +0100
+++ b/web/test/unittest_form.py	Thu Mar 12 20:46:30 2009 +0100
@@ -1,8 +1,12 @@
 from logilab.common.testlib import unittest_main, mock_object
 from cubicweb import Binary
 from cubicweb.devtools.testlib import WebTest
-from cubicweb.web.form import *
-from cubicweb.web.views.baseforms import ChangeStateForm
+from cubicweb.web.form import EntityFieldsForm, FormRenderer
+from cubicweb.web.formfields import (IntField, StringField, RichTextField,
+                                     DateTimeField, DateTimePicker,
+                                     FileField, EditableFileField)
+from cubicweb.web.formwidgets import PasswordInput
+from cubicweb.web.views.workflow import ChangeStateForm
 
 
 class EntityFieldsFormTC(WebTest):
@@ -45,8 +49,8 @@
     # fields tests ############################################################
 
     def _render_entity_field(self, name, form):
+        form.form_add_entity_hiddens(form.entity.e_schema)
         form.form_build_context({})
-        form.form_add_entity_hiddens(form.entity.e_schema)
         return form.field_by_name(name).render(form, self.renderer)
     
     def _test_richtextfield(self, expected):
@@ -56,20 +60,22 @@
                                content=u'<h1>new widgets system</h1>',
                                content_format=u'text/html')
         form = RTFForm(self.req, redirect_path='perdu.com', entity=card)
-        self.assertTextEquals(self._render_entity_field('content', form), expected)
+        self.assertTextEquals(self._render_entity_field('content', form), expected % {'eid': card.eid})
+
         
     def test_richtextfield_1(self):
         self.req.use_fckeditor = lambda: False
-        self._test_richtextfield('''<select name="content_format" id="content_format" tabindex="0">
+        self._test_richtextfield('''<select name="content_format:%(eid)s" id="content_format:%(eid)s" tabindex="0">
 <option value="text/rest">text/rest</option>
 <option selected="selected" value="text/html">text/html</option>
 <option value="text/plain">text/plain</option>
 <option value="text/cubicweb-page-template">text/cubicweb-page-template</option>
-</select><textarea tabindex="1" id="content" name="content" onkeypress="autogrow(this)"/>''')
+</select><textarea tabindex="1" id="content:%(eid)s" name="content:%(eid)s" onkeypress="autogrow(this)">&lt;h1&gt;new widgets system&lt;/h1&gt;</textarea>''')
+
     
     def test_richtextfield_2(self):
         self.req.use_fckeditor = lambda: True
-        self._test_richtextfield('''<input type="hidden" name="content_format" value="text/html"/><textarea tabindex="0" cubicweb:type="wysiwyg" id="content" name="content" onkeypress="autogrow(this)"/>''')
+        self._test_richtextfield('''<input type="hidden" name="content_format:%(eid)s" value="text/html"/><textarea tabindex="0" cubicweb:type="wysiwyg" id="content:%(eid)s" name="content:%(eid)s" onkeypress="autogrow(this)">&lt;h1&gt;new widgets system&lt;/h1&gt;</textarea>''')
 
 
     def test_filefield(self):
@@ -80,12 +86,16 @@
                                data=Binary('new widgets system'))
         form = FFForm(self.req, redirect_path='perdu.com', entity=file)
         self.assertTextEquals(self._render_entity_field('data', form),
-                              '''<input id="data" type="file" name="data" value="" tabindex="0"/>
-<a href="javascript: toggleVisibility(&#39;data-advanced&#39;)" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a>
-<div id="data-advanced" class="hidden">
-<label for="data_format">data_format</label><input id="data_format" type="text" name="data_format" value="" tabindex="1"/><br/><br/>
-<label for="data_encoding">data_encoding</label><input id="data_encoding" type="text" name="data_encoding" value="" tabindex="2"/><br/><br/>
-</div>''')
+                              '''<input id="data:%(eid)s" type="file" name="data:%(eid)s" value="" tabindex="0"/>
+<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>
+<div id="data:%(eid)s-advanced" class="hidden">
+<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/>
+<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/>
+</div>
+<br/>
+<input type="checkbox" name="data:594__detach"/>
+detach attached file
+''' % {'eid': file.eid})
 
         
     def test_editablefilefield(self):
@@ -100,25 +110,29 @@
                                data=Binary('new widgets system'))
         form = EFFForm(self.req, redirect_path='perdu.com', entity=file)
         self.assertTextEquals(self._render_entity_field('data', form),
-                              '''<input id="data" type="file" name="data" value="" tabindex="0"/>
-<a href="javascript: toggleVisibility(&#39;data-advanced&#39;)" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a>
-<div id="data-advanced" class="hidden">
-<label for="data_format">data_format</label><input id="data_format" type="text" name="data_format" value="" tabindex="1"/><br/><br/>
-<label for="data_encoding">data_encoding</label><input id="data_encoding" type="text" name="data_encoding" value="" tabindex="2"/><br/><br/>
+                              '''<input id="data:%(eid)s" type="file" name="data:%(eid)s" value="" tabindex="0"/>
+<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>
+<div id="data:%(eid)s-advanced" class="hidden">
+<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/>
+<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/>
 </div>
+<br/>
+<input type="checkbox" name="data:594__detach"/>
+detach attached file
 <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>
-<textarea tabindex="3" name="data" onkeypress="autogrow(this)">new widgets system</textarea>''')
+<textarea tabindex="3" name="data:%(eid)s" onkeypress="autogrow(this)">new widgets system</textarea>''' % {'eid': file.eid})
+
 
     def test_passwordfield(self):
         class PFForm(EntityFieldsForm):
             upassword = StringField(widget=PasswordInput)
         form = PFForm(self.req, redirect_path='perdu.com', entity=self.entity)
         self.assertTextEquals(self._render_entity_field('upassword', form),
-                              '''<input id="upassword" type="password" name="upassword" value="" tabindex="0"/>
+                              '''<input id="upassword:%(eid)s" type="password" name="upassword:%(eid)s" value="__cubicweb_internal_field__" tabindex="0"/>
 <br/>
-<input type="password" id="upassword" name="upassword-confirm" tabindex="0"/>
+<input type="password" name="upassword-confirm:%(eid)s" tabindex="0"/>
 &nbsp;
-<span class="emphasis">confirm password</span>''')
+<span class="emphasis">confirm password</span>''' % {'eid': self.entity.eid})
 
         
 if __name__ == '__main__':