Pylons / webtest

Wraps any WSGI application and makes it easy to send test requests to that application, without starting up an HTTP server.
https://docs.pylonsproject.org/projects/webtest/en/latest/
Other
335 stars 109 forks source link

Can't have more then 1 form in html #238

Closed sjscott84 closed 2 years ago

sjscott84 commented 2 years ago

Hi, there is a disparity between the docs and the code and I'm not sure which is the "real" issue.

I am testing a form response and my html has more then one form on it and the tests are failing because it has multiple forms. Docs advise "You can use the form index if your html contains more than one form:" (https://docs.pylonsproject.org/projects/webtest/en/latest/forms.html) but now the tests fail with "TypeError: You used response.form, but more than one form exists" (thrown by the form property in webtest/response.py) when trying to use response.form[0].

Is this error now expected with an html template with multiple forms or is this a bug (as implied by the documentation)? Many thanks

stevepiercy commented 2 years ago

I think you need to use the plural, response.forms[0].

sjscott84 commented 2 years ago

Thanks @stevepiercy you are correct, I missed the plural! I have created a pull request https://github.com/Pylons/webtest/pull/239 just to make it a little clearer that there is a different property when you have multiple forms if someone feels like reviewing and merging but not urgent as most people probably read the docs more thoroughly then I did! Thanks again :)