1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
import unittest
import turbogears
from turbogears import testutil
from funcweb.widget_validation import WidgetSchemaFactory
class TestWidgetValidator(unittest.TestCase):
def test_string_validator(self):
wf = WidgetSchemaFactory(self.get_string_params())
schema_man=wf.get_ready_schema()
conversion_schema = {
'max_length':'max',
'min_length':'min',
'validator':'regex'
}
#do better test here
for argument_name,arg_options in self.get_string_params().iteritems():
#print argument_name
assert hasattr(schema_man,argument_name)==True
#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)
if conversion_schema.has_key(arg):
if hasattr(getattr(schema_man,argument_name),conversion_schema[arg]):
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])
else:
#just print it to see what is inside because the test will be very hardcoded otherwise
print getattr(schema_man,argument_name)
continue
print "Happy tests !"
def get_string_params(self):
return {
'string_default':{
'type':'string',
'default':'default string',
'description':'default description'
},
'string_regex':{
'type':'string',
'default':'some',
'validator':'^[a-z]*$'
}
,
#will be converted to dropdown
'min_max_string':{
'type':'string',
'default':'myfirst',
'optional':False,
'description':'default dropdown list',
'max_length':12,
'min_length':5
},
'string_mix':{
'type':'string',
'optional':False,
'max_length':123,
'min_length':12,
'validator':'^[A-Z]+$'
}
}
|