Commits

Anonymous committed 187a4bd

more test coverage

Comments (0)

Files changed (1)

pyramid_simpleform/tests.py

 
 class SimpleColanderSchema(colander.MappingSchema):
 
-    name = colander.SchemaNode(colander.String(), required=True)
+    name = colander.SchemaNode(
+        colander.String(), 
+        required=True, 
+        validator=colander.Length(1, 100)
+    )
 
 
 class SimpleObj(object):
         request = testing.DummyRequest()
         request.method = "POST"
 
-        form = Form(request, SimpleColanderSchema)
+        form = Form(request, SimpleColanderSchema())
 
         self.assert_(not(form.validate()))
         self.assert_(form.is_validated)
 
     def test_is_validated_with_specified_params(self):
-        from pyramid_simpleform import Form
+        from pyramid_simpleform.form import Form
 
         request = testing.DummyRequest()
         request.method = "POST"
 
-        form = Form(request, SimpleFESchema)
+        form = Form(request, SimpleColanderSchema())
         form.validate(params={'name' : 'foo'})
         obj = form.bind(SimpleObj())
         self.assert_(obj.name == 'foo')
  
     def test_bind(self):
-        from pyramid_simpleform import Form
+        from pyramid_simpleform.form import Form
 
         request = testing.DummyRequest()
         request.method = "POST"
         request.POST['name'] = 'test'
 
-        form = Form(request, SimpleFESchema)
+        form = Form(request, SimpleColanderSchema())
         form.validate()
         obj = form.bind(SimpleObj())
         self.assert_(obj.name == 'test')
 
     def test_bind_ignore_underscores(self):
-        from pyramid_simpleform import Form
+        from pyramid_simpleform.form import Form
 
         request = testing.DummyRequest()
         request.method = "POST"
         class SimpleObjWithPrivate(SimpleObj):
             _ignoreme = None
 
-        class SimpleFESchemaWithPrivate(SimpleFESchema):
+        class SimpleSchemaWithPrivate(SimpleColanderSchema):
             _ignoreme = validators.String()
 
-        form = Form(request, SimpleFESchemaWithPrivate)
+        form = Form(request, SimpleSchemaWithPrivate())
         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
+        from pyramid_simpleform.form import Form
 
         request = testing.DummyRequest()
         request.method = "POST"
         request.POST['name'] = 'test'
 
-        form = Form(request, SimpleFESchema)
+        form = Form(request, SimpleColanderSchema())
         self.assertRaises(RuntimeError, form.bind, SimpleObj())
  
     def test_bind_with_errors(self):
-        from pyramid_simpleform import Form
+        from pyramid_simpleform.form import Form
 
         request = testing.DummyRequest()
         request.method = "POST"
         request.POST['name'] = ''
 
-        form = Form(request, SimpleFESchema)
+        form = Form(request, SimpleColanderSchema())
         self.assert_(not form.validate())
         self.assertRaises(RuntimeError, form.bind, SimpleObj())
 
     def test_bind_with_exclude(self):
-        from pyramid_simpleform import Form
+        from pyramid_simpleform.form import Form
 
         request = testing.DummyRequest()
         request.method = "POST"
         request.POST['name'] = 'test'
 
-        form = Form(request, SimpleFESchema)
+        form = Form(request, SimpleColanderSchema())
         form.validate()
         obj = form.bind(SimpleObj(), exclude=["name"])
         self.assert_(obj.name == None)
  
     def test_bind_with_include(self):
-        from pyramid_simpleform import Form
+        from pyramid_simpleform.form import Form
 
         request = testing.DummyRequest()
         request.method = "POST"
         request.POST['name'] = 'test'
 
-        form = Form(request, SimpleFESchema)
+        form = Form(request, SimpleColanderSchema())
         form.validate()
         obj = form.bind(SimpleObj(), include=['foo'])
         self.assert_(obj.name == None)
  
     def test_initialize_with_obj(self):
-        from pyramid_simpleform import Form
+        from pyramid_simpleform.form import Form
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleFESchema, obj=SimpleObj(name='test'))
+
+        form = Form(
+            request, 
+            SimpleColanderSchema(), 
+            obj=SimpleObj(name='test')
+        )
 
         self.assert_(form.data['name'] == 'test')
 
     def test_initialize_with_defaults(self):
-        from pyramid_simpleform import Form
+        from pyramid_simpleform.form import Form
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleFESchema, defaults={'name' : 'test'})
+        form = Form(
+            request, 
+            SimpleColanderSchema(), 
+            defaults={'name' : 'test'}
+        )
 
         self.assert_(form.data['name'] == 'test')
 
     def test_initialize_with_obj_and_defaults(self):
-        from pyramid_simpleform import Form
+        from pyramid_simpleform.form import Form
 
         request = testing.DummyRequest()
-        form = Form(request, SimpleFESchema, 
+        form = Form(request, SimpleColanderSchema(), 
                     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
+        from pyramid_simpleform.form import Form
 
         request = testing.DummyRequest()
         request.method = "GET"
         request.GET['name'] = 'test'
 
-        form = Form(request, SimpleFESchema, method="GET")
+        form = Form(request, SimpleColanderSchema(), method="GET")
 
         self.assert_(form.validate())
         self.assert_(form.is_validated)
 
+    def test_validate_from_GET_if_on_POST(self):
+        from pyramid_simpleform.form import Form
+
+        request = testing.DummyRequest()
+        request.method = "GET"
+        request.GET['name'] = 'test'
+
+        form = Form(request, SimpleColanderSchema())
+
+        self.assert_(not form.validate())
+        self.assert_(not form.is_validated)
+
+
     def test_force_validate(self):
-        from pyramid_simpleform import Form
+        from pyramid_simpleform.form import Form
 
         request = testing.DummyRequest()
         request.GET['name'] = 'test'
 
-        form = Form(request, SimpleFESchema)
+        form = Form(request, SimpleColanderSchema())
 
         self.assert_(form.validate(force_validate=True))
         self.assert_(form.is_validated)
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.