Ignore:
Timestamp:
2 Jun 2011, 10:23:37 (13 years ago)
Author:
uli
Message:

Show that we can inject our own formfields when converting strings
into objects.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/tests/test_converters.py

    r6264 r6265  
    3030from zope.app.testing.functional import FunctionalTestCase
    3131from zope.component.hooks import setSite, clearSite
     32from zope.formlib import form
    3233from zope.interface.verify import verifyClass, verifyObject
    3334
     
    7374    age = None
    7475Contact = attrs_to_fields(Contact)
     76
     77form_fields_select = form.Fields(IContact).select('name', 'vip')
     78form_fields_omit = form.Fields(IContact).omit('name', 'vip')
    7579
    7680class ConverterTests(FunctionalTestCase):
     
    193197            dict(birthday='not-a-date'), contact)
    194198        self.assertEqual(err, [('birthday', u'Invalid datetime data')])
     199
     200    def test_inject_formfields_select(self):
     201        # We can use our own formfields and select only a subset of fields
     202        contact = Contact()
     203        converter = IObjectConverter(IContact) # a converter to IContact
     204        input_data = dict(name='Bruno', age='99', vip='on')
     205        err, inv_err, new_contact = converter.applyRowData(
     206            input_data, contact, form_fields=form_fields_select)
     207        self.assertEqual(contact.name, 'Bruno')
     208        self.assertEqual(contact.age, 23)
     209        self.assertEqual(contact.vip, True)
     210        return
     211
     212    def test_inject_formfields_omit(self):
     213        # We can use our own formfields and omit some fields
     214        contact = Contact()
     215        converter = IObjectConverter(IContact) # a converter to IContact
     216        input_data = dict(name='Bruno', age='99', vip='on')
     217        err, inv_err, new_contact = converter.applyRowData(
     218            input_data, contact, form_fields=form_fields_omit)
     219        self.assertEqual(contact.name, 'Manfred')
     220        self.assertEqual(contact.age, 99)
     221        self.assertEqual(contact.vip, False)
     222        return
    195223
    196224def test_suite():
Note: See TracChangeset for help on using the changeset viewer.