Anonymous avatar Anonymous committed 91c0c5b

fix checked input error messages

Comments (0)

Files changed (3)

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)

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()
         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):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.