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

Forms with default action wrongly submit to "/" #218

Open ionelmc opened 4 years ago

ionelmc commented 4 years ago

Eg, a form like:

<form method="post">....

would get parsed out as a form with "/" as action url but instead the current url should be the action url. as per the html5 spec at https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#form-submission-algorithm

  1. If action is the empty string, let action be the URL of the form document.
fillipe-gsm commented 3 years ago

I'm having the same problem. So far, I am changing the form action manually in the tests, like

response = test_app.get("/base_url")
form = response.form
form.action = "/base_url"
form_response = form.submit()

which also works if the URL is dynamic (e.g., it depends on an object's id):

form.action = f"/base_url/{object.id}"
form_response = form.submit()

It is annoying, but at least it works without having to change the template.