From c49abde5eaa2bf37015589a2589e40d4b1d5f2e9 Mon Sep 17 00:00:00 2001 From: makkalot Date: Fri, 20 Jun 2008 11:52:07 +0300 Subject: Adding tests for integer validator --- funcweb/funcweb/tests/test_widget_validation.py | 37 +++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/funcweb/funcweb/tests/test_widget_validation.py b/funcweb/funcweb/tests/test_widget_validation.py index 7c2b8c4..d9e2d8c 100644 --- a/funcweb/funcweb/tests/test_widget_validation.py +++ b/funcweb/funcweb/tests/test_widget_validation.py @@ -1,7 +1,8 @@ import unittest import turbogears from turbogears import testutil -from funcweb.widget_validation import WidgetSchemaFactory +from funcweb.widget_validation import WidgetSchemaFactory,MinionIntValidator +from turbogears import validators class TestWidgetValidator(unittest.TestCase): @@ -22,20 +23,46 @@ class TestWidgetValidator(unittest.TestCase): #not very efficient but it si just a test :) if argument_name != 'string_mix': for arg,value in arg_options.iteritems(): - print getattr(schema_man,argument_name) + #print getattr(schema_man,argument_name) if conversion_schema.has_key(arg): if hasattr(getattr(schema_man,argument_name),conversion_schema[arg]): - print arg,value + #print arg,value #couldnt find a way to test it !?? if arg != 'validator': assert getattr(getattr(schema_man,argument_name),conversion_schema[arg])==value - print getattr(getattr(schema_man,argument_name),conversion_schema[arg]) + #print getattr(getattr(schema_man,argument_name),conversion_schema[arg]) else: #just print it to see what is inside because the test will be very hardcoded otherwise - print getattr(schema_man,argument_name) + #print getattr(schema_man,argument_name) continue print "Happy tests !" + + def test_minion_int_validator(self): + mv=MinionIntValidator(max_int = 44,min_int=2) + self.assertRaises(validators.Invalid,mv.to_python,100) + self.assertRaises(validators.Invalid,mv.to_python,1) + self.assertRaises(validators.Invalid,mv.to_python,'some_string') + assert mv.to_python(21) == 21 + + #dont use the min + mv=MinionIntValidator(max_int = 44) + self.assertRaises(validators.Invalid,mv.to_python,100) + assert mv.to_python(1)==1 + self.assertRaises(validators.Invalid,mv.to_python,'some_string') + assert mv.to_python(21) == 21 + + mv=MinionIntValidator(min_int=12) + self.assertRaises(validators.Invalid,mv.to_python,10) + assert mv.to_python(14)==14 + self.assertRaises(validators.Invalid,mv.to_python,'some_string') + assert mv.to_python(21) == 21 + + mv=MinionIntValidator() + assert mv.to_python(14)==14 + self.assertRaises(validators.Invalid,mv.to_python,'some_string') + + def get_string_params(self): return { 'string_default':{ -- cgit