Commits

Anonymous committed 7cd5ca3

added colander support

  • Participants
  • Parent commits 9fb181e

Comments (0)

Files changed (2)

pyramid_simpleform/tests.py

 import unittest
 
+import colander
+
 from formencode import Schema
 from formencode import validators
 
 from pyramid.config import Configurator
 
 
-class SimpleSchema(Schema):
+class SimpleFESchema(Schema):
 
     name = validators.NotEmpty()
 
 
+class SimpleColanderSchema(colander.MappingSchema):
+
+    name = colander.SchemaNode(colander.String(), required=True)
+
+
 class SimpleObj(object):
 
     def __init__(self, name=None):
         self.name = name
 
-class TestState(unittest.TestCase):
 
-    def test_state(self):
-
-        from pyramid_simpleform import State
-        obj = State(foo="bar")
-        self.assert_(obj.foo=="bar")
-
-    def test_state_contains(self):
-
-        from pyramid_simpleform import State
-        obj = State(foo="bar")
-        self.assert_("foo" in obj)
-
-    def test_state_not_contains(self):
-
-        from pyramid_simpleform import State
-        obj = State(foo="bar")
-        self.assert_("bar" not in obj)
-
-    def test_getitem(self):
-
-        from pyramid_simpleform import State
-        obj = State(foo="bar")
-        self.assert_(obj['foo'] == 'bar')
-
-    def test_setitem(self):
-
-        from pyramid_simpleform import State
-        obj = State()
-        obj['foo'] = "bar"
-        self.assert_(obj['foo'] == 'bar')
-        self.assert_(obj.foo == 'bar')
-
-    def test_get(self):
-
-        from pyramid_simpleform import State
-        obj = State(foo="bar")
-        self.assert_(obj.get('foo') == 'bar')
-        self.assert_(obj.get('bar', 'foo') == 'foo')
-
-
-class TestForm(unittest.TestCase):
+class TestFormencodeForm(unittest.TestCase):
     
 
     def test_is_error(self):
         request = testing.DummyRequest()
         request.method = "POST"
 
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
 
         self.assert_(not(form.validate()))
         self.assert_(form.is_validated)
         request = testing.DummyRequest()
         request.method = "POST"
 
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         form.errors = u"Name is missing"
         self.assert_(form.all_errors() == [u"Name is missing"])
 
         request = testing.DummyRequest()
         request.method = "POST"
 
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         form.errors = [u"Name is missing"]
         self.assert_(form.all_errors() == [u"Name is missing"])
 
         request = testing.DummyRequest()
         request.method = "POST"
 
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         form.errors = {"name" : [u"Name is missing"],
                        "value" : u"Value is missing"}
         self.assert_(form.all_errors() == [
         request = testing.DummyRequest()
         request.method = "POST"
 
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
 
         self.assert_(not(form.validate()))
         self.assert_(form.is_validated)
         request = testing.DummyRequest()
         request.method = "POST"
 
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
 
         self.assert_(not(form.validate()))
         self.assert_(form.is_validated)
         request = testing.DummyRequest()
         request.method = "POST"
 
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         form.validate(params={'name' : 'foo'})
         obj = form.bind(SimpleObj())
         self.assert_(obj.name == 'foo')
         request.method = "POST"
         request.POST['name'] = 'test'
 
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         form.validate()
         obj = form.bind(SimpleObj())
         self.assert_(obj.name == 'test')
         class SimpleObjWithPrivate(SimpleObj):
             _ignoreme = None
 
-        class SimpleSchemaWithPrivate(SimpleSchema):
+        class SimpleFESchemaWithPrivate(SimpleFESchema):
             _ignoreme = validators.String()
 
-        form = Form(request, SimpleSchemaWithPrivate)
+        form = Form(request, SimpleFESchemaWithPrivate)
         form.validate()
         obj = form.bind(SimpleObjWithPrivate())
         self.assert_(obj.name == 'test')
         request.method = "POST"
         request.POST['name'] = 'test'
 
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         self.assertRaises(RuntimeError, form.bind, SimpleObj())
  
     def test_bind_with_errors(self):
         request.method = "POST"
         request.POST['name'] = ''
 
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         self.assert_(not form.validate())
         self.assertRaises(RuntimeError, form.bind, SimpleObj())
 
         request.method = "POST"
         request.POST['name'] = 'test'
 
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         form.validate()
         obj = form.bind(SimpleObj(), exclude=["name"])
         self.assert_(obj.name == None)
         request.method = "POST"
         request.POST['name'] = 'test'
 
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         form.validate()
         obj = form.bind(SimpleObj(), include=['foo'])
         self.assert_(obj.name == None)
         from pyramid_simpleform import Form
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema, obj=SimpleObj(name='test'))
+        form = Form(request, SimpleFESchema, obj=SimpleObj(name='test'))
 
         self.assert_(form.data['name'] == 'test')
 
         from pyramid_simpleform import Form
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema, defaults={'name' : 'test'})
+        form = Form(request, SimpleFESchema, defaults={'name' : 'test'})
 
         self.assert_(form.data['name'] == 'test')
 
         from pyramid_simpleform import Form
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema, 
+        form = Form(request, SimpleFESchema, 
                     obj=SimpleObj(name='test1'),
                     defaults={'name' : 'test2'})
 
         request.POST['name'] = 'test'
         request.method = "POST"
         
-        form = Form(request, SimpleSchema,
+        form = Form(request, SimpleFESchema,
                     variable_decode=True)
 
         self.assert_(form.validate())
         request.method = "GET"
         request.GET['name'] = 'test'
 
-        form = Form(request, SimpleSchema, method="GET")
+        form = Form(request, SimpleFESchema, method="GET")
 
         self.assert_(form.validate())
         self.assert_(form.is_validated)
         request = testing.DummyRequest()
         request.GET['name'] = 'test'
 
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
+
+        self.assert_(form.validate(force_validate=True))
+        self.assert_(form.is_validated)
+
+ 
+class TestState(unittest.TestCase):
+
+    def test_state(self):
+
+        from pyramid_simpleform import State
+        obj = State(foo="bar")
+        self.assert_(obj.foo=="bar")
+
+    def test_state_contains(self):
+
+        from pyramid_simpleform import State
+        obj = State(foo="bar")
+        self.assert_("foo" in obj)
+
+    def test_state_not_contains(self):
+
+        from pyramid_simpleform import State
+        obj = State(foo="bar")
+        self.assert_("bar" not in obj)
+
+    def test_getitem(self):
+
+        from pyramid_simpleform import State
+        obj = State(foo="bar")
+        self.assert_(obj['foo'] == 'bar')
+
+    def test_setitem(self):
+
+        from pyramid_simpleform import State
+        obj = State()
+        obj['foo'] = "bar"
+        self.assert_(obj['foo'] == 'bar')
+        self.assert_(obj.foo == 'bar')
+
+    def test_get(self):
+
+        from pyramid_simpleform import State
+        obj = State(foo="bar")
+        self.assert_(obj.get('foo') == 'bar')
+        self.assert_(obj.get('bar', 'foo') == 'foo')
+
+class TestColanderForm(unittest.TestCase):
+    
+
+    def test_is_error(self):
+        from pyramid_simpleform.form import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+
+        form = Form(request, SimpleColanderSchema())
+
+        self.assert_(not(form.validate()))
+        self.assert_(form.is_validated)
+        self.assert_('name' in form.errors)
+
+    def test_all_errors_with_dict(self):
+
+        from pyramid_simpleform.form import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+
+        form = Form(request, SimpleColanderSchema())
+        form.errors = {"name" : u"Name is missing",
+                       "value" : u"Value is missing"}
+        self.assert_(form.all_errors() == [
+            u"Name is missing", 
+            u"Value is missing"])
+
+    def test_errors_for(self):
+        from pyramid_simpleform.form import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+
+        form = Form(request, SimpleColanderSchema())
+
+        self.assert_(not(form.validate()))
+        self.assert_(form.is_validated)
+        self.assert_('name' in form.errors)
+
+        self.assert_(form.errors_for('name') == ['Required'])
+
+    def test_validate_twice(self):
+        
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+        request.POST = {'name' : 'ok'}
+
+        form = Form(request, 
+                    validators=dict(name=validators.NotEmpty()))
+
+        self.assert_(form.validate())
+        self.assert_(form.is_validated)
+        self.assert_(form.data['name'] == 'ok')
+
+        request.POST = {'name' : 'ok again'}
+
+        self.assert_(form.validate())
+        self.assert_(form.is_validated)
+        self.assert_(form.data['name'] == 'ok')
+
+    def test_validate_good_input_with_validators(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+        request.POST = {'name' : 'ok'}
+
+        form = Form(request, 
+                    validators=dict(name=validators.NotEmpty()))
+
+        self.assert_(form.validate())
+        self.assert_(form.is_validated)
+        self.assert_(form.data['name'] == 'ok')
+
+    def test_validate_bad_input_with_validators(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+
+        form = Form(request, 
+                    validators=dict(name=validators.NotEmpty()))
+
+        self.assert_(not form.validate())
+        self.assert_(form.is_validated)
+        self.assert_(form.is_error('name'))
+
+        self.assert_(form.errors_for('name') == ['Please enter a value'])
+
+    def test_is_validated_on_post(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+
+        form = Form(request, SimpleFESchema)
+
+        self.assert_(not(form.validate()))
+        self.assert_(form.is_validated)
+
+    def test_is_validated_with_specified_params(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+
+        form = Form(request, SimpleFESchema)
+        form.validate(params={'name' : 'foo'})
+        obj = form.bind(SimpleObj())
+        self.assert_(obj.name == 'foo')
+ 
+    def test_bind(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+        request.POST['name'] = 'test'
+
+        form = Form(request, SimpleFESchema)
+        form.validate()
+        obj = form.bind(SimpleObj())
+        self.assert_(obj.name == 'test')
+
+    def test_bind_ignore_underscores(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+        request.POST['name'] = 'test'
+        request.POST['_ignoreme'] = 'test'
+
+        class SimpleObjWithPrivate(SimpleObj):
+            _ignoreme = None
+
+        class SimpleFESchemaWithPrivate(SimpleFESchema):
+            _ignoreme = validators.String()
+
+        form = Form(request, SimpleFESchemaWithPrivate)
+        form.validate()
+        obj = form.bind(SimpleObjWithPrivate())
+        self.assert_(obj.name == 'test')
+        self.assert_(obj._ignoreme is None)
+        
+    def test_bind_not_validated_yet(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+        request.POST['name'] = 'test'
+
+        form = Form(request, SimpleFESchema)
+        self.assertRaises(RuntimeError, form.bind, SimpleObj())
+ 
+    def test_bind_with_errors(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+        request.POST['name'] = ''
+
+        form = Form(request, SimpleFESchema)
+        self.assert_(not form.validate())
+        self.assertRaises(RuntimeError, form.bind, SimpleObj())
+
+    def test_bind_with_exclude(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+        request.POST['name'] = 'test'
+
+        form = Form(request, SimpleFESchema)
+        form.validate()
+        obj = form.bind(SimpleObj(), exclude=["name"])
+        self.assert_(obj.name == None)
+ 
+    def test_bind_with_include(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+        request.POST['name'] = 'test'
+
+        form = Form(request, SimpleFESchema)
+        form.validate()
+        obj = form.bind(SimpleObj(), include=['foo'])
+        self.assert_(obj.name == None)
+ 
+    def test_initialize_with_obj(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleFESchema, obj=SimpleObj(name='test'))
+
+        self.assert_(form.data['name'] == 'test')
+
+    def test_initialize_with_defaults(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleFESchema, defaults={'name' : 'test'})
+
+        self.assert_(form.data['name'] == 'test')
+
+    def test_initialize_with_obj_and_defaults(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleFESchema, 
+                    obj=SimpleObj(name='test1'),
+                    defaults={'name' : 'test2'})
+
+        self.assert_(form.data['name'] == 'test1')
+
+    def test_variable_decode(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.POST['name'] = 'test'
+        request.method = "POST"
+        
+        form = Form(request, SimpleFESchema,
+                    variable_decode=True)
+
+        self.assert_(form.validate())
+        self.assert_(form.data['name'] == 'test')
+
+    def test_validate_from_GET(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "GET"
+        request.GET['name'] = 'test'
+
+        form = Form(request, SimpleFESchema, method="GET")
+
+        self.assert_(form.validate())
+        self.assert_(form.is_validated)
+
+    def test_force_validate(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.GET['name'] = 'test'
+
+        form = Form(request, SimpleFESchema)
+
+        self.assert_(form.validate(force_validate=True))
+        self.assert_(form.is_validated)
+ 
+class TestFormencodeForm(unittest.TestCase):
+    
+
+    def test_is_error(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+
+        form = Form(request, SimpleFESchema)
+
+        self.assert_(not(form.validate()))
+        self.assert_(form.is_validated)
+        self.assert_('name' in form.errors)
+
+    def test_all_errors_with_single_string(self):
+
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+
+        form = Form(request, SimpleFESchema)
+        form.errors = u"Name is missing"
+        self.assert_(form.all_errors() == [u"Name is missing"])
+
+    def test_all_errors_with_list(self):
+
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+
+        form = Form(request, SimpleFESchema)
+        form.errors = [u"Name is missing"]
+        self.assert_(form.all_errors() == [u"Name is missing"])
+
+    def test_all_errors_with_dict(self):
+
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+
+        form = Form(request, SimpleFESchema)
+        form.errors = {"name" : [u"Name is missing"],
+                       "value" : u"Value is missing"}
+        self.assert_(form.all_errors() == [
+            u"Name is missing", 
+            u"Value is missing"])
+
+    def test_errors_for(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+
+        form = Form(request, SimpleFESchema)
+
+        self.assert_(not(form.validate()))
+        self.assert_(form.is_validated)
+        self.assert_('name' in form.errors)
+
+        self.assert_(form.errors_for('name') == ['Missing value'])
+
+    def test_validate_twice(self):
+        
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+        request.POST = {'name' : 'ok'}
+
+        form = Form(request, 
+                    validators=dict(name=validators.NotEmpty()))
+
+        self.assert_(form.validate())
+        self.assert_(form.is_validated)
+        self.assert_(form.data['name'] == 'ok')
+
+        request.POST = {'name' : 'ok again'}
+
+        self.assert_(form.validate())
+        self.assert_(form.is_validated)
+        self.assert_(form.data['name'] == 'ok')
+
+    def test_validate_good_input_with_validators(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+        request.POST = {'name' : 'ok'}
+
+        form = Form(request, 
+                    validators=dict(name=validators.NotEmpty()))
+
+        self.assert_(form.validate())
+        self.assert_(form.is_validated)
+        self.assert_(form.data['name'] == 'ok')
+
+    def test_validate_bad_input_with_validators(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+
+        form = Form(request, 
+                    validators=dict(name=validators.NotEmpty()))
+
+        self.assert_(not form.validate())
+        self.assert_(form.is_validated)
+        self.assert_(form.is_error('name'))
+
+        self.assert_(form.errors_for('name') == ['Please enter a value'])
+
+    def test_is_validated_on_post(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+
+        form = Form(request, SimpleFESchema)
+
+        self.assert_(not(form.validate()))
+        self.assert_(form.is_validated)
+
+    def test_is_validated_with_specified_params(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+
+        form = Form(request, SimpleFESchema)
+        form.validate(params={'name' : 'foo'})
+        obj = form.bind(SimpleObj())
+        self.assert_(obj.name == 'foo')
+ 
+    def test_bind(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+        request.POST['name'] = 'test'
+
+        form = Form(request, SimpleFESchema)
+        form.validate()
+        obj = form.bind(SimpleObj())
+        self.assert_(obj.name == 'test')
+
+    def test_bind_ignore_underscores(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+        request.POST['name'] = 'test'
+        request.POST['_ignoreme'] = 'test'
+
+        class SimpleObjWithPrivate(SimpleObj):
+            _ignoreme = None
+
+        class SimpleFESchemaWithPrivate(SimpleFESchema):
+            _ignoreme = validators.String()
+
+        form = Form(request, SimpleFESchemaWithPrivate)
+        form.validate()
+        obj = form.bind(SimpleObjWithPrivate())
+        self.assert_(obj.name == 'test')
+        self.assert_(obj._ignoreme is None)
+        
+    def test_bind_not_validated_yet(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+        request.POST['name'] = 'test'
+
+        form = Form(request, SimpleFESchema)
+        self.assertRaises(RuntimeError, form.bind, SimpleObj())
+ 
+    def test_bind_with_errors(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+        request.POST['name'] = ''
+
+        form = Form(request, SimpleFESchema)
+        self.assert_(not form.validate())
+        self.assertRaises(RuntimeError, form.bind, SimpleObj())
+
+    def test_bind_with_exclude(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+        request.POST['name'] = 'test'
+
+        form = Form(request, SimpleFESchema)
+        form.validate()
+        obj = form.bind(SimpleObj(), exclude=["name"])
+        self.assert_(obj.name == None)
+ 
+    def test_bind_with_include(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+        request.POST['name'] = 'test'
+
+        form = Form(request, SimpleFESchema)
+        form.validate()
+        obj = form.bind(SimpleObj(), include=['foo'])
+        self.assert_(obj.name == None)
+ 
+    def test_initialize_with_obj(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleFESchema, obj=SimpleObj(name='test'))
+
+        self.assert_(form.data['name'] == 'test')
+
+    def test_initialize_with_defaults(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleFESchema, defaults={'name' : 'test'})
+
+        self.assert_(form.data['name'] == 'test')
+
+    def test_initialize_with_obj_and_defaults(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleFESchema, 
+                    obj=SimpleObj(name='test1'),
+                    defaults={'name' : 'test2'})
+
+        self.assert_(form.data['name'] == 'test1')
+
+    def test_variable_decode(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.POST['name'] = 'test'
+        request.method = "POST"
+        
+        form = Form(request, SimpleFESchema,
+                    variable_decode=True)
+
+        self.assert_(form.validate())
+        self.assert_(form.data['name'] == 'test')
+
+    def test_validate_from_GET(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.method = "GET"
+        request.GET['name'] = 'test'
+
+        form = Form(request, SimpleFESchema, method="GET")
+
+        self.assert_(form.validate())
+        self.assert_(form.is_validated)
+
+    def test_force_validate(self):
+        from pyramid_simpleform import Form
+
+        request = testing.DummyRequest()
+        request.GET['name'] = 'test'
+
+        form = Form(request, SimpleFESchema)
 
         self.assert_(form.validate(force_validate=True))
         self.assert_(form.is_validated)
 
         request.registry = config.registry
 
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
 
         result = form.render("test_form.html", htmlfill=False)
         self.assert_('<input type="text" name="name" size="20">' 
 
         request.registry = config.registry
 
-        form = Form(request, SimpleSchema, defaults={'name' : 'foo'})
+        form = Form(request, SimpleFESchema, defaults={'name' : 'foo'})
 
         result = form.render("test_form.html", htmlfill=True)
         self.assert_('<input type="text" name="name" size="20" value="foo">' 
         from pyramid_simpleform import Form
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema, 
+        form = Form(request, SimpleFESchema, 
                     defaults={"name" : "testing"})
 
         html = """
         html = form.htmlfill(html)
         self.assert_('value="testing"' in html)
 
+class TestColanderFormRenderer(unittest.TestCase):
+    
+    def test_begin_form(self):
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
 
-class TestFormRenderer(unittest.TestCase):
+        request = testing.DummyRequest()
+        form = Form(request, SimpleColanderSchema())
+        renderer = FormRenderer(form)
+
+        self.assert_(renderer.begin(url="/"),
+                     '<form action="/" method="post">')
+
+    def test_end_form(self):
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleColanderSchema())
+        renderer = FormRenderer(form)
+       
+        self.assert_(renderer.end() == "</form>")
+
+    def test_csrf(self):
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleColanderSchema())
+        renderer = FormRenderer(form)
+
+        self.assert_(renderer.csrf() == \
+            '<input id="_csrf" name="_csrf" type="hidden" value="csrft" />')
+ 
+    def test_csrf_token(self):
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleColanderSchema())
+        renderer = FormRenderer(form)
+
+        self.assert_(renderer.csrf_token() == \
+                '<div style="display:none;"><input id="_csrf" name="_csrf" '
+                'type="hidden" value="csrft" /></div>')
+
+    def test_hidden_tag_with_csrf_and_other_names(self):
+        
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleColanderSchema(), defaults={'name':'foo'})
+        renderer = FormRenderer(form)
+
+        self.assert_(renderer.hidden_tag('name') == \
+            '<div style="display:none;"><input id="name" name="name" '
+            'type="hidden" value="foo" /><input id="_csrf" name="_csrf" '
+            'type="hidden" value="csrft" /></div>')
+
+    def test_hidden_tag_with_just_csrf(self):
+        
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleColanderSchema())
+        renderer = FormRenderer(form)
+
+        self.assert_(renderer.hidden_tag() == \
+                '<div style="display:none;"><input id="_csrf" name="_csrf" '
+                'type="hidden" value="csrft" /></div>')
+
+
+ 
+ 
+ 
+    def test_text(self):
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleColanderSchema(), defaults={"name" : "Fred"})
+        renderer = FormRenderer(form)
+
+        self.assert_(renderer.text("name") == \
+                '<input id="name" name="name" type="text" value="Fred" />')
+
+    def test_textarea(self):
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleColanderSchema(), defaults={"name" : "Fred"})
+        renderer = FormRenderer(form)
+
+        self.assert_(renderer.textarea("name") == \
+                '<textarea id="name" name="name">Fred</textarea>')
+ 
+    def test_hidden(self):
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleColanderSchema(), defaults={"name" : "Fred"})
+        renderer = FormRenderer(form)
+
+        self.assert_(renderer.hidden("name") == \
+                '<input id="name" name="name" type="hidden" value="Fred" />')
+        
+    def test_select(self):
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleColanderSchema(), defaults={"name" : "Fred"})
+        renderer = FormRenderer(form)
+        
+        options = [
+            ("Fred", "Fred"),
+            ("Barney", "Barney"),
+            ("Wilma", "Wilma"),
+            ("Betty", "Betty"),
+        ]   
+
+        self.assert_(renderer.select("name", options) == \
+            """<select id="name" name="name">
+<option selected="selected" value="Fred">Fred</option>
+<option value="Barney">Barney</option>
+<option value="Wilma">Wilma</option>
+<option value="Betty">Betty</option>
+</select>""")
+ 
+    def test_file(self):
+  
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleColanderSchema())
+        renderer = FormRenderer(form)
+       
+        self.assert_(renderer.file('file') == \
+                   '<input id="file" name="file" type="file" />')
+
+    def test_password(self):
+  
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleColanderSchema())
+        renderer = FormRenderer(form)
+       
+        self.assert_(renderer.password('password') == \
+                   '<input id="password" name="password" type="password" />')
+
+
+    def test_radio(self):
+
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleColanderSchema(), defaults={"name" : 'Fred'})
+        renderer = FormRenderer(form)
+        
+        self.assert_(renderer.radio("name", value="Fred") == \
+                     '<input checked="checked" id="name_fred" name="name" '
+                     'type="radio" value="Fred" />')
+        
+        self.assert_(renderer.radio("name", value="Barney") == \
+                     '<input id="name_barney" name="name" '
+                     'type="radio" value="Barney" />')
+
+    def test_submit(self):
+
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleColanderSchema())
+        renderer = FormRenderer(form)
+
+        self.assert_(renderer.submit("submit", "Submit") == \
+            '<input id="submit" name="submit" type="submit" value="Submit" />')
+
+    def test_checkbox(self):
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleColanderSchema(), defaults={"name" : True})
+        renderer = FormRenderer(form)
+        
+        self.assert_(renderer.checkbox("name") == \
+            '<input checked="checked" id="name" name="name" type="checkbox" '
+            'value="1" />')
+
+    def test_is_error(self):
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+
+        form = Form(request, SimpleColanderSchema())
+
+        self.assert_(not(form.validate()))
+
+        renderer = FormRenderer(form)
+        self.assert_(renderer.is_error('name'))
+
+    def test_errors_for(self):
+
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+
+        form = Form(request, SimpleColanderSchema())
+
+        self.assert_(not(form.validate()))
+        renderer = FormRenderer(form)
+
+        self.assert_(renderer.errors_for('name') == ['Required'])
+
+    def test_errorlist(self):
+
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+
+        form = Form(request, SimpleColanderSchema())
+        form.validate()
+
+        renderer = FormRenderer(form)
+
+        self.assert_(renderer.errorlist() == \
+                     '<ul class="error"><li>Required</li></ul>')
+     
+
+    def test_errorlist_with_no_errors(self):
+
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+        request.POST['name'] = 'test'
+
+        form = Form(request, SimpleColanderSchema())
+        form.validate()
+
+        renderer = FormRenderer(form)
+
+        self.assert_(renderer.errorlist() == '')
+
+ 
+    def test_errorlist_with_field(self):
+
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        request.method = "POST"
+
+        form = Form(request, SimpleColanderSchema())
+        form.validate()
+
+        renderer = FormRenderer(form)
+
+        self.assert_(renderer.errorlist('name') == \
+                     '<ul class="error"><li>Required</li></ul>')
+ 
+    def test_label(self):
+
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleColanderSchema())
+        renderer = FormRenderer(form)
+       
+        self.assert_(renderer.label("name") == \
+                   '<label for="name">Name</label>') 
+
+    def test_label_using_field_name(self):
+
+        from pyramid_simpleform.form import Form
+        from pyramid_simpleform.renderers import FormRenderer
+
+        request = testing.DummyRequest()
+        form = Form(request, SimpleColanderSchema())
+        renderer = FormRenderer(form)
+       
+        self.assert_(renderer.label("name", "Your name") == \
+                   '<label for="name">Your name</label>') 
+
+class TestFormencodeFormRenderer(unittest.TestCase):
     
     def test_begin_form(self):
         from pyramid_simpleform import Form
         from pyramid_simpleform.renderers import FormRenderer
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         renderer = FormRenderer(form)
 
         self.assert_(renderer.begin(url="/"),
         from pyramid_simpleform.renderers import FormRenderer
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         renderer = FormRenderer(form)
        
         self.assert_(renderer.end() == "</form>")
         from pyramid_simpleform.renderers import FormRenderer
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         renderer = FormRenderer(form)
 
         self.assert_(renderer.csrf() == \
         from pyramid_simpleform.renderers import FormRenderer
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         renderer = FormRenderer(form)
 
         self.assert_(renderer.csrf_token() == \
         from pyramid_simpleform.renderers import FormRenderer
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema, defaults={'name':'foo'})
+        form = Form(request, SimpleFESchema, defaults={'name':'foo'})
         renderer = FormRenderer(form)
 
         self.assert_(renderer.hidden_tag('name') == \
         from pyramid_simpleform.renderers import FormRenderer
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         renderer = FormRenderer(form)
 
         self.assert_(renderer.hidden_tag() == \
         from pyramid_simpleform.renderers import FormRenderer
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema, defaults={"name" : "Fred"})
+        form = Form(request, SimpleFESchema, defaults={"name" : "Fred"})
         renderer = FormRenderer(form)
 
         self.assert_(renderer.text("name") == \
         from pyramid_simpleform.renderers import FormRenderer
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema, defaults={"name" : "Fred"})
+        form = Form(request, SimpleFESchema, defaults={"name" : "Fred"})
         renderer = FormRenderer(form)
 
         self.assert_(renderer.textarea("name") == \
         from pyramid_simpleform.renderers import FormRenderer
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema, defaults={"name" : "Fred"})
+        form = Form(request, SimpleFESchema, defaults={"name" : "Fred"})
         renderer = FormRenderer(form)
 
         self.assert_(renderer.hidden("name") == \
         from pyramid_simpleform.renderers import FormRenderer
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema, defaults={"name" : "Fred"})
+        form = Form(request, SimpleFESchema, defaults={"name" : "Fred"})
         renderer = FormRenderer(form)
         
         options = [
         from pyramid_simpleform.renderers import FormRenderer
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         renderer = FormRenderer(form)
        
         self.assert_(renderer.file('file') == \
         from pyramid_simpleform.renderers import FormRenderer
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         renderer = FormRenderer(form)
        
         self.assert_(renderer.password('password') == \
         from pyramid_simpleform.renderers import FormRenderer
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema, defaults={"name" : 'Fred'})
+        form = Form(request, SimpleFESchema, defaults={"name" : 'Fred'})
         renderer = FormRenderer(form)
         
         self.assert_(renderer.radio("name", value="Fred") == \
         from pyramid_simpleform.renderers import FormRenderer
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         renderer = FormRenderer(form)
 
         self.assert_(renderer.submit("submit", "Submit") == \
         from pyramid_simpleform.renderers import FormRenderer
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema, defaults={"name" : True})
+        form = Form(request, SimpleFESchema, defaults={"name" : True})
         renderer = FormRenderer(form)
         
         self.assert_(renderer.checkbox("name") == \
         request = testing.DummyRequest()
         request.method = "POST"
 
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
 
         self.assert_(not(form.validate()))
 
         request = testing.DummyRequest()
         request.method = "POST"
 
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
 
         self.assert_(not(form.validate()))
         renderer = FormRenderer(form)
         request = testing.DummyRequest()
         request.method = "POST"
 
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         form.validate()
 
         renderer = FormRenderer(form)
         request.method = "POST"
         request.POST['name'] = 'test'
 
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         form.validate()
 
         renderer = FormRenderer(form)
 
         state = State(_=lambda s:s.upper())
 
-        form = Form(request, SimpleSchema, state=state)
+        form = Form(request, SimpleFESchema, state=state)
         form.validate()
 
         renderer = FormRenderer(form)
         request = testing.DummyRequest()
         request.method = "POST"
 
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         form.validate()
 
         renderer = FormRenderer(form)
         from pyramid_simpleform.renderers import FormRenderer
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         renderer = FormRenderer(form)
        
         self.assert_(renderer.label("name") == \
         from pyramid_simpleform.renderers import FormRenderer
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleSchema)
+        form = Form(request, SimpleFESchema)
         renderer = FormRenderer(form)
        
         self.assert_(renderer.label("name", "Your name") == \
     'pyramid',
     'webhelpers',
     'formencode',
+    'colander',
 ]