summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormakkalot <makkalot@gmail.com>2008-06-20 11:52:07 +0300
committermakkalot <makkalot@gmail.com>2008-06-20 11:52:07 +0300
commitc49abde5eaa2bf37015589a2589e40d4b1d5f2e9 (patch)
tree4cc8867cad540ebca7c45c6449d332558eb8388d
parent9269e9ac65c42e1d57d34c52755dba97a93f81a6 (diff)
downloadfunc-c49abde5eaa2bf37015589a2589e40d4b1d5f2e9.tar.gz
func-c49abde5eaa2bf37015589a2589e40d4b1d5f2e9.tar.xz
func-c49abde5eaa2bf37015589a2589e40d4b1d5f2e9.zip
Adding tests for integer validator
-rw-r--r--funcweb/funcweb/tests/test_widget_validation.py37
1 files 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':{