How to use pylons (paste) web test with multiple checkboxes with the same name?

Suppose I have a form like this:

<form id='myform'> Favorite colors? <input type='checkbox' name='color' value='Green'>Green <input type='checkbox' name='color' value='Blue'>Blue <input type='checkbox' name='color' value='Red'>Red <input type='submit' value='Submit'> </form> 

How to use webtest form library to test sending multiple values?

+4
source share
1 answer

Not sure about the forms library, but you can use MultiDict (you might have to use UnicodeMultiDict in some cases, I'm not sure).

 from webob.multidict import MultiDict class TestSomeController(TestController): def test_something(self): params = MultiDict() params.add('some_param', '1') params.add('color', 'Green') params.add('color', 'Blue') response = self.app.post(url('something'), params=params) assert 'something' in response 

I never used WebTest to submit actual forms, but looking at the source of the Form class, you can set the index of the field that you want to set to disambiguate. I have not tested it, but maybe something like this:

 form = response.form form.set('color', True, 0) form.set('color', True, 2) 
+4
source

All Articles