Commits

Chris McDonough committed e8f5699

remove duplicate copy of TestFormencodeForm; change test_getitem_notfound to get 100% coverage

Comments (0)

Files changed (2)

 
 .git
 .gitignore
+
+env26/

pyramid_simpleform/tests.py

         self.name = name
 
 
-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)
-
- 
 class TestState(unittest.TestCase):
 
     def test_state(self):
 
         from pyramid_simpleform import State
         obj = State()
-        try:
-            obj['foo'] == 'bar'
-            assert False
-        except KeyError:
-            pass
+        self.assertRaises(KeyError, obj.__getitem__, 'foo')
 
     def test_setitem(self):