def test_form_update_widgets(self): from ptah import form request = DummyRequest() request.POST = {} form_ob = form.Form(None, request) form_ob.update() self.assertIsInstance(form_ob.widgets, form.FormWidgets) self.assertEqual(form_ob.widgets.mode, form_ob.mode) form_ob.mode = form.FORM_DISPLAY form_ob.update() self.assertEqual(form_ob.widgets.mode, form.FORM_DISPLAY) self.assertEqual(len(form_ob.widgets), 0) form_ob.fields = form.Fieldset(form.TextField('test')) form_ob.update() self.assertEqual(len(form_ob.widgets), 1) self.assertIn('test', form_ob.widgets) self.assertIn('test', [f.name for f in form_ob.widgets.fields()]) self.assertIsInstance(form_ob.widgets['test'], form.TextField) self.assertEqual(form_ob.widgets['test'].name, 'test') self.assertEqual(form_ob.widgets['test'].id, 'form-widgets-test')
def test_form_render(self): from ptah import form request = DummyRequest() form_ob = form.Form(None, request) form_ob.fields = form.Fieldset(form.TextField('test')) form_ob.update() self.assertIn('<form action="http://example.com"', form_ob.render())
def test_form_extract(self): from ptah import form request = DummyRequest() request.POST = {} form_ob = form.Form(None, request) form_ob.fields = form.Fieldset(form.TextField('test')) form_ob.update() data, errors = form_ob.extract() self.assertEqual(errors[0].msg, 'Required') request.POST = {'test': 'Test string'} form_ob.update() data, errors = form_ob.extract() self.assertEqual(data['test'], 'Test string')
class CustomForm(form.Form): fields = form.Fieldset(form.TextField('test')) @form.button('test') def handler(self): return HTTPFound(location='.')
class CustomForm(form.Form): fields = form.Fieldset(form.TextField('test'))