diff -r be43d95ebb52 -r 6636c75c4aa9 web/test/unittest_form.py --- a/web/test/unittest_form.py Wed Mar 11 11:51:52 2009 +0100 +++ b/web/test/unittest_form.py Wed Mar 11 14:33:26 2009 +0100 @@ -5,33 +5,23 @@ from cubicweb.web.views.baseforms import ChangeStateForm -class CustomChangeStateForm(ChangeStateForm): - hello = IntField(name='youlou') - creation_date = DateTimeField(widget=DateTimePicker) - - -class RTFForm(EntityFieldsForm): - content = RichTextField() - -class FFForm(EntityFieldsForm): - data = FileField(format_field=StringField(name='data_format'), - encoding_field=StringField(name='data_encoding')) - -class PFForm(EntityFieldsForm): - upassword = StringField(widget=PasswordInput) - - class EntityFieldsFormTC(WebTest): def setUp(self): super(EntityFieldsFormTC, self).setUp() self.req = self.request() self.entity = self.user(self.req) + self.renderer = FormRenderer() + # form tests ############################################################## + def test_form_inheritance(self): + class CustomChangeStateForm(ChangeStateForm): + hello = IntField(name='youlou') + creation_date = DateTimeField(widget=DateTimePicker) form = CustomChangeStateForm(self.req, redirect_path='perdu.com', entity=self.entity) - self.assertTextEquals(form.form_render(state=123), + self.assertTextEquals(form.form_render(state=123, trcomment=u''), ''' ''') def test_change_state_form(self): @@ -39,34 +29,90 @@ entity=self.entity) self.assertTextEquals(form.form_render(state=123, trcomment=u''), ''' ''') - - def test_richtextfield(self): - card = self.add_entity('Card', title=u"tls sprint fev 2009", - content=u'new widgets system') - form = RTFForm(self.req, redirect_path='perdu.com', - entity=card) - self.assertTextEquals(form.form_render(), - '''''') - - def test_filefield(self): - file = self.add_entity('File', name=u"pouet.txt", - data=Binary('new widgets system')) - form = FFForm(self.req, redirect_path='perdu.com', - entity=file) - self.assertTextEquals(form.form_render(), - '''''') - - def test_passwordfield(self): - form = PFForm(self.req, redirect_path='perdu.com', - entity=self.entity) - self.assertTextEquals(form.form_render(), - '''''') def test_delete_conf_form_multi(self): rset = self.execute('EGroup X') self.assertTextEquals(self.view('deleteconf', rset, template=None).source, '') + # fields tests ############################################################ + + def _render_entity_field(self, name, form): + 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): + class RTFForm(EntityFieldsForm): + content = RichTextField() + card = self.add_entity('Card', title=u"tls sprint fev 2009", + content=u'
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.
+''') + + 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), + ''' +