Index: main/waeup.sirp/trunk/src/waeup/sirp/utils/tests/test_converters.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/utils/tests/test_converters.py	(revision 6262)
+++ main/waeup.sirp/trunk/src/waeup/sirp/utils/tests/test_converters.py	(revision 6264)
@@ -23,4 +23,5 @@
 Tests for converterts.
 """
+import datetime
 import os
 import shutil
@@ -32,7 +33,44 @@
 
 from waeup.sirp.app import University
-from waeup.sirp.interfaces import ISchemaTypeConverter
 from waeup.sirp.testing import FunctionalLayer, doctestsuite_for_module
-
+from waeup.sirp.utils.converters import IObjectConverter
+
+from zope import schema
+from zope.interface import Interface, implements, invariant, Invalid
+from waeup.sirp.utils.helpers import attrs_to_fields
+
+class IContact(Interface):
+    name = schema.TextLine(
+        title = u'Name',
+        default = u'Manfred'
+        )
+    age = schema.Int(
+        title = u'Age',
+        default = 23,
+        required = True,
+        )
+    city = schema.TextLine(
+        title = u'City',
+        required = True,
+        )
+    vip = schema.Bool(
+        title = u'Celebrity',
+        default = False,
+        required = True,
+        )
+    birthday = schema.Date(
+        title = u'Birthday',
+        default = None,
+        )
+    @invariant
+    def kevinIsYoung(contact):
+        if contact.age > 16 and contact.name == 'Kevin':
+            raise Invalid('Kevins are age 16 or below.')
+
+class Contact(object):
+    implements(IContact)
+    name = None
+    age = None
+Contact = attrs_to_fields(Contact)
 
 class ConverterTests(FunctionalTestCase):
@@ -62,42 +100,97 @@
         return
 
-    def test_foo(self):
-        from zope import schema
-        from zope.interface import Interface, implements
-
-        class IContact(Interface):
-            name = schema.TextLine(
-                title = u'Name',
-                default = u'Manfred'
-                )
-            age = schema.Int(
-                title = u'Age',
-                default = 23,
-                required = True,
-                )
-            city = schema.TextLine(
-                title = u'City',
-                required = True,
-                )
-
-
-        class Contact(object):
-            implements(IContact)
-            name = None
-            age = None
-
-        from waeup.sirp.utils.helpers import attrs_to_fields
-        Contact = attrs_to_fields(Contact)
-
-        context = Contact()
-        conv = ISchemaTypeConverter(IContact)
-        input_data = dict(name='Foo')
-        input_data = dict(name='Foo', age='sweet sixteen')
-        err, inv_err, data = conv.applyRowData(input_data, context)
-        #print context.name, context.age
-        #print err, inv_err, data
-        #import pdb; pdb.set_trace()
-        #val = conv._convertValueFromString('Foo', context=context)
-        #print field, conv
+    def test_valid_data(self):
+        contact = Contact()
+        contact.age = 33
+        input_data = dict(name='Rudi', age='99')
+        converter = IObjectConverter(IContact) # a converter to IContact
+        err, inv_err, new_contact = converter.applyRowData(
+            input_data, contact)
+        assert new_contact is contact
+        assert contact.name == 'Rudi'
+        assert contact.age == 99
+        return
+
+    def test_bool(self):
+        contact1 = Contact()
+        contact2 = Contact()
+        input_data1 = dict(vip='on')
+        input_data2 = dict(vip='')
+        converter = IObjectConverter(IContact) # a converter to IContact
+        err1, inv_err1, new_contact1 = converter.applyRowData(
+            input_data1, contact1)
+        err2, inv_err2, new_contact2 = converter.applyRowData(
+            input_data2, contact2)
+        assert contact1.vip is True
+        assert contact2.vip is False
+
+    def test_int(self):
+        contact = Contact()
+        input_data = dict(age='99')
+        converter = IObjectConverter(IContact) # a converter to IContact
+        err, inv_err, new_contact = converter.applyRowData(
+            input_data, contact)
+        assert contact.age == 99
+        return
+
+    def test_int_invalid(self):
+        contact = Contact()
+        input_data = dict(age='sweet sixteen')
+        converter = IObjectConverter(IContact) # a converter to IContact
+        err, inv_err, new_contact = converter.applyRowData(
+            input_data, contact)
+        self.assertEqual(err, [('age', u'Invalid integer data')])
+        return
+
+    def test_textline(self):
+        contact = Contact()
+        input_data = dict(name='Rudi')
+        converter = IObjectConverter(IContact) # a converter to IContact
+        err, inv_err, new_contact = converter.applyRowData(
+            input_data, contact)
+        self.assertEqual(contact.name, u'Rudi')
+        assert isinstance(contact.name, unicode)
+        return
+
+    def test_invariant(self):
+        contact = Contact()
+        input_data = dict(name='Kevin', age='22')
+        converter = IObjectConverter(IContact) # a converter to IContact
+        err, inv_err, new_contact = converter.applyRowData(
+            input_data, contact)
+        self.assertEqual(inv_err, ['Kevins are age 16 or below.'])
+        return
+
+    def test_date(self):
+        contact = Contact()
+        converter = IObjectConverter(IContact) # a converter to IContact
+        err, inv_err, new_contact = converter.applyRowData(
+            dict(birthday='1945/12/23'), contact)
+        assert contact.birthday == datetime.date(1945, 12, 23)
+        assert isinstance(contact.birthday, datetime.date)
+
+        err, inv_err, new_contact = converter.applyRowData(
+            dict(birthday='1945/23/12'), contact)
+        assert contact.birthday == datetime.date(1945, 12, 23)
+
+        err, inv_err, new_contact = converter.applyRowData(
+            dict(birthday='23/12/1945'), contact)
+        assert contact.birthday == datetime.date(1945, 12, 23)
+
+        err, inv_err, new_contact = converter.applyRowData(
+            dict(birthday='23.12.1945'), contact)
+        assert contact.birthday == datetime.date(1945, 12, 23)
+
+        err, inv_err, new_contact = converter.applyRowData(
+            dict(birthday='23-12-1945'), contact)
+        assert contact.birthday == datetime.date(1945, 12, 23)
+        return
+
+    def test_date_invalid(self):
+        contact = Contact()
+        converter = IObjectConverter(IContact) # a converter to IContact
+        err, inv_err, new_contact = converter.applyRowData(
+            dict(birthday='not-a-date'), contact)
+        self.assertEqual(err, [('birthday', u'Invalid datetime data')])
 
 def test_suite():
