--- a/web/test/unittest_formfields.py Tue May 19 10:05:19 2009 +0200
+++ b/web/test/unittest_formfields.py Tue May 19 10:05:56 2009 +0200
@@ -1,12 +1,15 @@
"""unittests for cw.web.formfields"""
+from logilab.common.testlib import TestCase, unittest_main
+
from yams.constraints import StaticVocabularyConstraint, SizeConstraint
-from logilab.common.testlib import TestCase, unittest_main
+
from cubicweb.devtools import TestServerConfiguration
+from cubicweb.devtools.testlib import EnvBasedTC
+from cubicweb.web.form import EntityFieldsForm
from cubicweb.web.formwidgets import PasswordInput, TextArea, Select
from cubicweb.web.formfields import *
-from cubicweb.entities.wfobjs import State
-from cubicweb.entities.authobjs import CWUser
+
from cubes.file.entities import File
config = TestServerConfiguration('data')
@@ -43,12 +46,13 @@
self.assertEquals(description_format_field.sort, True)
self.assertEquals(description_format_field.initial(None), 'text/rest')
+
# wikiid_field = guess_field(state_schema, schema['wikiid'])
# self.assertIsInstance(wikiid_field, StringField)
# self.assertEquals(wikiid_field.required, False)
- def test_euser_fields(self):
+ def test_cwuser_fields(self):
upassword_field = guess_field(cwuser_schema, schema['upassword'])
self.assertIsInstance(upassword_field, StringField)
self.assertIsInstance(upassword_field.widget, PasswordInput)
@@ -89,5 +93,21 @@
[SizeConstraint, StaticVocabularyConstraint])
self.assertIsInstance(salesterm_field.widget, Select)
+class MoreFieldsTC(EnvBasedTC):
+ def test_rtf_format_field(self):
+ req = self.request()
+ req.use_fckeditor = lambda: False
+ e = self.etype_instance('State')
+ form = EntityFieldsForm(req, entity=e)
+ description_field = guess_field(state_schema, schema['description'])
+ description_format_field = description_field.get_format_field(form)
+ self.assertEquals(description_format_field.internationalizable, True)
+ self.assertEquals(description_format_field.sort, True)
+ # unlike below, initial is bound to form.form_field_format
+ self.assertEquals(description_format_field.initial(form), 'text/html')
+ self.execute('INSERT CWProperty X: X pkey "ui.default-text-format", X value "text/rest", X for_user U WHERE U login "admin"')
+ self.commit()
+ self.assertEquals(description_format_field.initial(form), 'text/rest')
+
if __name__ == '__main__':
unittest_main()