test and fixes tls-sprint
authorsylvain.thenault@logilab.fr
Fri, 20 Feb 2009 15:40:28 +0100
branchtls-sprint
changeset 894 e1f848785e3d
parent 893 1f9308b253ce
child 895 e78ae38506db
test and fixes
web/form.py
web/test/unittest_form.py
--- a/web/form.py	Fri Feb 20 15:40:13 2009 +0100
+++ b/web/form.py	Fri Feb 20 15:40:28 2009 +0100
@@ -308,12 +308,12 @@
         return super(self, FCKEditor, self).render(form, field)
 
 
-class EditableFile(Widget):
-    # XXX
-    pass
+#class EditableFile(Widget):
+#    # XXX
+#    pass
 
 class Select(FieldWidget):
-    def __init__(self, attrs, vocabulary=()):
+    def __init__(self, attrs=None, vocabulary=()):
         super(Select, self).__init__(attrs)
         self.vocabulary = ()
         
@@ -401,6 +401,7 @@
         if widget is not None:
             self.widget = widget
         if isinstance(self.widget, type):
+            print 'widget', self.widget
             self.widget = self.widget()
         self.name = name
         self.label = label or name
@@ -463,7 +464,7 @@
         return self.widget
 
     def get_format_field(self, form):
-        if self.format_field is _MARKER:
+        if not self.format_field:
             # if fckeditor is used and format field isn't explicitly
             # deactivated, we want an hidden field for the format
             if self.use_fckeditor(form):
@@ -477,7 +478,7 @@
     
     def actual_fields(self, form):
         yield self
-        format_field = self.get_format_field(self, form)
+        format_field = self.get_format_field(form)
         if format_field:
             yield format_field
             
@@ -490,7 +491,7 @@
         return False
 
     def render(self, form):
-        format_field = self.get_format_field()
+        format_field = self.get_format_field(form)
         if format_field:
             result = format_field.render(form)
         else:
@@ -599,7 +600,7 @@
         if previous_values:
             values.update(previous_values)
         for field in self.fields:
-            for field in field.actual_fields(form):
+            for field in field.actual_fields(self):
                 value = self.form_field_value(field, values)
                 context[field] = {'value': field.format_value(self.req, value),
                                   'rawvalue': value,
@@ -653,7 +654,7 @@
 
     def form_add_entity_hiddens(self, eschema):
         for field in self.fields[:]:
-            for field in field.actual_fields(form):
+            for field in field.actual_fields(self):
                 fieldname = field.name
                 if fieldname != 'eid' and (
                     (eschema.has_subject_relation(fieldname) or
--- a/web/test/unittest_form.py	Fri Feb 20 15:40:13 2009 +0100
+++ b/web/test/unittest_form.py	Fri Feb 20 15:40:28 2009 +0100
@@ -8,6 +8,10 @@
     hello = IntField(name='youlou')
     creation_date = DateTimeField(widget=DateTimePicker)
 
+
+class RTFStateForm(EntityFieldsForm):
+    content = RichTextField()
+
     
 class EntityFieldsFormTC(WebTest):
 
@@ -17,19 +21,29 @@
         self.entity = self.user(self.req)
         
     def test_form_inheritance(self):
-        form = CustomChangeStateForm(self.req, redirect_path='perdu.com')
-        self.assertEquals(form.form_render(self.entity, state=123),
+        form = CustomChangeStateForm(self.req, redirect_path='perdu.com',
+                                     entity=self.entity)
+        self.assertEquals(form.form_render(state=123),
                           ''' ''')
 
     def test_change_state_form(self):
-        form = ChangeStateForm(self.req, redirect_path='perdu.com')
-        self.assertEquals(form.form_render(self.entity, state=123),
+        form = ChangeStateForm(self.req, redirect_path='perdu.com',
+                               entity=self.entity)
+        self.assertEquals(form.form_render(state=123),
                           ''' ''')
 
     def test_delete_conf_form_multi(self):
         rset = self.execute('EGroup X')
         self.assertEquals(self.view('deleteconf', rset).source,
                           '')
+
+    def test_richtextfield(self):
+        card = self.add_entity('Card', title=u"tls sprint fev 2009",
+                               content=u'new widgets system')
+        form = CustomChangeStateForm(self.req, redirect_path='perdu.com',
+                                     entity=card)
+        self.assertEquals(form.form_render(),
+                          '''''')
         
 if __name__ == '__main__':
     unittest_main()