Enhance functional test framework so that a boolean form field ( checkbox ) can have a false value ( be unchecked ). Add a 2nd test to gops_concat that uses this behavior.

This commit is contained in:
Greg Von Kuster
2010-02-17 11:07:08 -05:00
parent a2c20d2f69
commit 72e7836cbb
3 changed files with 30 additions and 4 deletions
+22 -2
View File
@@ -857,8 +857,28 @@ class TwillTestCase( unittest.TestCase ):
elif control.is_of_kind( "list" ):
try:
if control.is_of_kind( "multilist" ):
for elem in control_value:
control.get( name=elem ).selected = True
if control.type == "checkbox":
def is_checked( value ):
# Copied from form_builder.CheckboxField
if value == True:
return True
if isinstance( value, basestring ) and value.lower() in ( "yes", "true", "on" ):
return True
# This may look strange upon initial inspection, but see the comments in the get_html() method
# above for clarification. Basically, if value is not True, then it will always be a list with
# 2 input fields ( a checkbox and a hidden field ) if the checkbox is checked. If it is not
# checked, then value will be only the hidden field.
return isinstance( value, list ) and len( value ) == 2
try:
checkbox = control.get()
checkbox.selected = is_checked( control_value )
except ClientForm.AmbiguityError:
# if there's more than one checkbox, use the behaviour for
# ClientForm.ListControl - see twill code..
pass
else:
for elem in control_value:
control.get( name=elem ).selected = True
else: # control.is_of_kind( "singlelist" )
for elem in control_value:
tc.fv( f.name, control.name, str( elem ) )
+8 -2
View File
@@ -20,8 +20,14 @@
<param name="input1" value="1.bed" />
<param name="input2" value="2.bed" />
<param name="sameformat" value="true" />
<output name="output" file="gops-concat.dat" />
</test>
<output name="output" file="gops_concat_out1.bed" />
</test>
<test>
<param name="input1" value="1.bed" />
<param name="input2" value="1.interval" />
<param name="sameformat" value="false" />
<output name="output" file="gops_concat_out2.bed" />
</test>
</tests>
<help>