[Zope3-dev] zope.testbrowser.browser problem

Gary Poster gary at zope.com
Thu Dec 1 09:12:28 EST 2005


On Dec 1, 2005, at 5:46 AM, Chris Withers wrote:

> Gary Poster wrote:
>>> I have a form as follows:
>>>
>>> <form action="aPythonScript"
>>>       method="POST" name="form_name">
>>> ...
>>> <input type="submit" name="action" value=" Go " />
>>> <input type="submit" name="action" value=" Do Something " />
>>> ...
>>> </form>
>>>
>>> Now, I do the following with a zope.testbrowser.browser:
>>>
>>> browser.getForm(name='form_name').getControl(' Do Something  
>>> ').click()
>>>
>>> However, the value of REQUEST.form['action'] in aPythonScript is  
>>> "  Go ", not " Do Something ", as I'd expect.
>>>
>>> Any idea what's causing this and how I can fix it?
>> Unfortunately, not off-hand.  If you send me a smallest-possible-  
>> failing doctest (which might be pretty close to this email?) I'll   
>> look at it and try to make it pass.
>
> Well, I've just been thinking about how to do this, and then  
> realised I have no idea how to write a form submit handler in Zope  
> 3 and then how to weave that into a functional test.
>
> How would I go about doing that?

form submit handler: for this case, all you need is to look at the  
request.form, which looks identical (or as close as I remember) to  
the Zope 2 approach.

Making a pertinent test: let's see--plenty of ways to approach this.   
How about setting a view up that simply returns a prettily formatted  
version of request.form, and then using ellipses to just verify what  
you want.  Make your form's action point to this view.  Sound doable?

This should only be a small addition to the approach that Stephan  
took with the testbrowser tests.  Extra points if you want to include  
the text of your test file in the README so readers can have a better  
idea what you are clicking--you maybe could do this by creating and  
registering a resource with the text within the doctes.

Gary


More information about the Zope3-dev mailing list