Ignore:
Timestamp:
2 Jun 2011, 12:14:53 (14 years ago)
Author:
uli
Message:

Prove that the converter can handle simple vocabularies.

File:
1 edited

Legend:

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

    r6266 r6267  
    4343from waeup.sirp.utils.converters import IObjectConverter
    4444from waeup.sirp.utils.helpers import attrs_to_fields
     45from waeup.sirp.interfaces import SimpleWAeUPVocabulary
     46
     47colors = SimpleWAeUPVocabulary(
     48    ('Red', u'red'),
     49    ('Green', u'green'),
     50    ('Blue', u'blue'),
     51    )
    4552
    4653class IContact(Interface):
     
    6875        title = u'Birthday',
    6976        default = None,
     77        )
     78    fav_color = schema.Choice(
     79        title = u'Favourite color',
     80        default = u'red',
     81        vocabulary = colors,
    7082        )
    7183    @invariant
     
    255267        # ...with the values from the dict set.
    256268        self.assertEqual(contact.name, 'Gabi')
     269        return
     270
     271    def test_choice_vocab(self):
     272        # We can handle vocabularies
     273        converter = IObjectConverter(IContact) # a converter to IContact
     274        err, inv_err, contact = converter.applyRowData(
     275            dict(fav_color='blue'), 'contact')
     276        assert contact.fav_color == u'blue'
     277        assert isinstance(contact.fav_color, unicode)
     278        return
     279
     280    def test_choice_vocab_invalid_value(self):
     281        # We can handle vocabularies
     282        converter = IObjectConverter(IContact) # a converter to IContact
     283        err, inv_err, contact = converter.applyRowData(
     284            dict(fav_color='magenta'), 'contact')
     285        self.assertEqual(err, [('fav_color', u'Invalid value')])
     286        assert contact.fav_color == u'red'
    257287        return
    258288
Note: See TracChangeset for help on using the changeset viewer.