Norman Khine wrote:
Titus Brown wrote:
p.s. sorry 'bout that... <sigh> Stephen added in a unit test to catch
exactly this problem, too!
ClientForm.AmbiguityError: id=None name=None label=None
Hi!
I'm looking at this problem too, and what I've come up with is that
commands.formvalue(formnum, fieldname, value) is insufficent for the
task of selecting, and deselecting, checkboxes.
The issue lays in that the action needs the following data:
What Form?
What Checkbox Name?
What Checkbox Value?
On or Off?
The API as it stands will select or deselect a single, or, if we let
commands.formvalue(formnum, fieldname, 'foo')
work, will allow selection, but not de-selection, of checkboxes.
Going back to the hackish API that PBP used to use, we could allow:
commands.formvalue(formnum, fieldname, '+foo')
commands.formvalue(formnum, fieldname, '-foo')
as well.
Please see attached patch and tests.
--
Regards,
Stephen Thorne
Development Engineer
Scanned by the NetBox from NetBox Blue
(http://netboxblue.com/)
New patches:
[handle multiple checkboxes of the same name
Stephen Thorne <[EMAIL PROTECTED]>**20060323025648] {
addfile ./tests/test-checkbox.py
hunk ./tests/test-checkbox.py 1
+
+import twilltestlib
+import twill
+from twill import namespaces, commands
+from twill.errors import TwillAssertionError
+from mechanize import BrowserStateError
+import ClientForm
+from tests import url
+
+def test_select_multiple():
+ namespaces.new_local_dict()
+ twill.commands.reset_browser()
+ browser = twill.get_browser()
+ try:
+ browser.get_title()
+ assert 0, "should never get here"
+ except BrowserStateError:
+ pass
+
+ commands.go(url)
+ commands.go('/test_checkboxes')
+
+ commands.fv('1', 'checkboxtest', 'one')
+ commands.fv('1', 'checkboxtest', 'two')
+ commands.fv('1', 'checkboxtest', 'three')
+
+ commands.fv('1', 'checkboxtest', '-one')
+ commands.fv('1', 'checkboxtest', '-two')
+ commands.fv('1', 'checkboxtest', '-three')
+
+ commands.submit()
+ assert not 'CHECKBOXTEST' in browser.get_html()
+
+ commands.fv('1', 'checkboxtest', '+one')
+ commands.fv('1', 'checkboxtest', '+two')
+ commands.fv('1', 'checkboxtest', '+three')
+
+ commands.submit()
+ assert 'CHECKBOXTEST: ==one,two,three==' in browser.get_html()
+
+ commands.fv('1', 'checkboxtest', '-one')
+ commands.fv('1', 'checkboxtest', '-two')
+ commands.fv('1', 'checkboxtest', '-three')
+
+ commands.submit()
+ assert not 'CHECKBOXTEST' in browser.get_html()
+
+def test_select_single():
+ namespaces.new_local_dict()
+ twill.commands.reset_browser()
+ browser = twill.get_browser()
+ try:
+ browser.get_title()
+ assert 0, "should never get here"
+ except BrowserStateError:
+ pass
+
+ commands.go(url)
+ commands.go('/test_checkboxes')
+
+ for x in ('1', '0', 'True', 'False'):
+ try:
+ commands.fv('1', 'checkboxtest', x)
+ assert False, ("Should not be able to use a bool style for when "
+ "there are multiple checkboxes")
+ except:
+ pass
+
+
hunk ./tests/twilltestserver.py 94
+ "test_checkboxes",
hunk ./tests/twilltestserver.py 316
+</form>
+""" % (s,)
+
+ def test_checkboxes(self):
+ request = get_request()
+
+ s = ""
+ if request.form and request.form.has_key('checkboxtest'):
+ val = request.form['checkboxtest']
+
+ if not isinstance(val, str):
+ val = ','.join(val)
+
+ s += "CHECKBOXTEST: ==%s==<p>" % val
+
+ return """\
+%s
+<form method=POST>
+<input type="checkbox" name="checkboxtest" value="one">
+<input type="checkbox" name="checkboxtest" value="two">
+<input type="checkbox" name="checkboxtest" value="three">
+<input type=submit value=post>
hunk ./twill/utils.py 158
- checkbox = control.get()
- flag = make_boolean(val)
-
- if flag:
- checkbox.selected = 1
- else:
- checkbox.selected = 0
-
- elif isinstance(control, ClientForm.ListControl):
+ try:
+ checkbox = control.get()
+ checkbox.selected = make_boolean(val)
+ return
+ except ClientForm.AmbiguityError:
+ # use the behaviour in isinstance(control, ClientForm.ListControl)
+ pass
+
+ if isinstance(control, ClientForm.ListControl):
}
Context:
[form display problem; equiv-refresh options
[EMAIL PROTECTED]
[applied a few fixes to checkbox stuff
[EMAIL PROTECTED]
[checkbox fix?
[EMAIL PROTECTED]
[add failing test for turning on a checkbox without a value
Stephen Thorne <[EMAIL PROTECTED]>**20060321003131]
[added in Jeff Martin's variable expansion patch
[EMAIL PROTECTED]
[more form/list stuff
[EMAIL PROTECTED]
[bumped alpha number to 8
[EMAIL PROTECTED]
[checkbox set/clear
[EMAIL PROTECTED]
[switched to using 'require success' instead of code 200
[EMAIL PROTECTED]
[only force controls to be writable if they're actually readonly
Stephen Thorne <[EMAIL PROTECTED]>**20060317060114]
[Sometimes we want to use HTTP auth without worrying about the realm, so add a config option 'with_default_realm' that will make add_auth swap around which urllib2 class to use for http auth.
Stephen Thorne <[EMAIL PROTECTED]>**20060316231727]
[bumped version #
[EMAIL PROTECTED]
[added require extension module
[EMAIL PROTECTED]
[more _journey cleanup
[EMAIL PROTECTED]
[minor cleanup
[EMAIL PROTECTED]
[refactored journey stuff
[EMAIL PROTECTED]
[bumped to a6
[EMAIL PROTECTED]
[extensions module docs, + contents, + check_links module
[EMAIL PROTECTED]
[added installation help
[EMAIL PROTECTED]
[updated docs: known problems, links to other test stuff
[EMAIL PROTECTED]
[switched default encoding over to utf-8 from latin-1
[EMAIL PROTECTED]
[used entry_points magic to specify twill-sh
[EMAIL PROTECTED]
[fixed SystemExit / KeyboardInterrupt problems
[EMAIL PROTECTED]
[newline issue hilighted
[EMAIL PROTECTED]
[added redirect_output/reset_output; fixed memory leak
[EMAIL PROTECTED]
[miscellaneous additional tests; test cleanup; shell tests
[EMAIL PROTECTED]
[cleaned up tests a bit
[EMAIL PROTECTED]
[made sure fps were closed
[EMAIL PROTECTED]
[fixed execute_command
[EMAIL PROTECTED]
[cleaned out some unused stuff
[EMAIL PROTECTED]
[fixed runfile
[EMAIL PROTECTED]
[fixes for execute_command
[EMAIL PROTECTED]
[fixed run_tidy stuff; fixed file URLs
[EMAIL PROTECTED]
[bumped to 0.8.4a1
[EMAIL PROTECTED]
[added equiv-refresh debugging
[EMAIL PROTECTED]
[oops
[EMAIL PROTECTED]
[TAG release-0.8.3
[EMAIL PROTECTED]
Patch bundle hash:
8c07df75b1d14fd607d17dd7efcd41e2ec27c995
_______________________________________________
twill mailing list
[email protected]
http://lists.idyll.org/listinfo/twill