Commits

Chris McDonough  committed 91c0c5b

fix checked input error messages

  • Participants
  • Parent commits ddd4004
  • Branches default_overhaul

Comments (0)

Files changed (3)

File deform/tests/test_field.py

         self.assertEqual(field.render('abc', readonly=True), 'abc')
         self.assertEqual(widget.rendered, 'readonly')
 
+    def test_serialize(self):
+        schema = DummySchema()
+        field = self._makeOne(schema)
+        widget = field.widget = DummyWidget()
+        self.assertEqual(field.serialize('abc'), 'abc')
+        self.assertEqual(widget.rendered, 'writable')
+
+    def test_serialize_default(self):
+        from colander import default
+        from colander import null
+        schema = DummySchema()
+        field = self._makeOne(schema)
+        widget = field.widget = DummyWidget()
+        self.assertEqual(field.serialize(default), null)
+        self.assertEqual(widget.rendered, 'writable')
+
+    def test_deserialize(self):
+        cstruct = {'name':'Name', 'title':'Title'}
+        schema = DummySchema()
+        field = self._makeOne(schema)
+        field.widget = DummyWidget()
+        result = field.deserialize(cstruct)
+        self.assertEqual(result, {'name':'Name', 'title':'Title'})
+
     def test___repr__(self):
         schema = DummySchema()
         field = self._makeOne(schema)

File deform/tests/test_widget.py

         result = widget.deserialize(field, null)
         self.assertEqual(result, default)
 
+    def test_deserialize_empty(self):
+        from colander import default
+        widget = self._makeOne()
+        field = DummyField()
+        result = widget.deserialize(field, {'value':'',
+                                            'confirm':''})
+        self.assertEqual(result, default)
+        self.assertEqual(field.error, None)
+
     def test_deserialize_nonmatching(self):
         widget = self._makeOne()
         field = DummyField()

File deform/widget.py

         value = pstruct.get('value') or ''
         confirm = pstruct.get('confirm') or ''
         field.confirm = confirm
-        if value != confirm:
+        if (value or confirm) and (value != confirm):
             raise Invalid(field.schema, self.mismatch_message, value)
+        if not value:
+            return default
         return value
 
 class CheckedPasswordWidget(CheckedInputWidget):