diff options
-rw-r--r-- | funcweb/funcweb/tests/test_widget_validation.py | 29 | ||||
-rw-r--r-- | funcweb/funcweb/widget_validation.py | 19 |
2 files changed, 48 insertions, 0 deletions
diff --git a/funcweb/funcweb/tests/test_widget_validation.py b/funcweb/funcweb/tests/test_widget_validation.py index adb4a15..c800d41 100644 --- a/funcweb/funcweb/tests/test_widget_validation.py +++ b/funcweb/funcweb/tests/test_widget_validation.py @@ -89,6 +89,25 @@ class TestWidgetValidator(unittest.TestCase): print "Happy test!" + + def test_bool_validator(self): + testing_data = self.get_bool_params() + wf = WidgetSchemaFactory(testing_data) + schema_man=wf.get_ready_schema() + + for argument_name,arg_options in testing_data.iteritems(): + #print argument_name + #should all the argument names really + assert hasattr(schema_man,argument_name)==True + #print " ",argument_name," : ",getattr(schema_man,argument_name) + + if arg_options.has_key('optional'): + #print " ",argument_name," : ",getattr(schema_man,argument_name) + assert not getattr(getattr(schema_man,argument_name),'not_empty') == arg_options['optional'] + + print "Happy test!" + + def test_list_validator(self,the_type='list'): if the_type == 'list': @@ -305,6 +324,16 @@ class TestWidgetValidator(unittest.TestCase): 'validator':'^[A-Z]$' }, } + + def get_bool_params(self): + return { + 'bool_default':{ + 'type':'boolean', + 'default':{'hey':12}, + 'description':'default hash', + 'optional':False, + }, + } diff --git a/funcweb/funcweb/widget_validation.py b/funcweb/funcweb/widget_validation.py index ae1203e..35d099a 100644 --- a/funcweb/funcweb/widget_validation.py +++ b/funcweb/funcweb/widget_validation.py @@ -29,6 +29,25 @@ class WidgetSchemaFactory(object): #for ex : _add_int_validator(some_arg) getattr(self,"_add_%s_validator"%(argument_values['type']))(argument_name) + def _add_boolean_validator(self,argument_name): + bool_data_set = {} + + #the optional keyword + if self.method_argument_dict[argument_name].has_key('optional'): + if self.method_argument_dict[argument_name]['optional']: + bool_data_set['not_empty']=False + else: + bool_data_set['not_empty']=True + + + if bool_data_set: + self.validator_list[argument_name]=validators.Bool(**bool_data_set) + else: + self.validator_list[argument_name]=validators.Bool() + + + + def _add_int_validator(self,argument_name): """ Gets the options of the int type and adds a |