| 1 |
Integration regression test for case where ClientForm handled RFC 3986 |
| 2 |
url unparsing incorrectly (it was using "" in place of None for |
| 3 |
fragment, due to continuing to support use of stdlib module urlparse |
| 4 |
as well as mechanize._rfc3986). Fixed in ClientForm r33622 . |
| 5 |
|
| 6 |
>>> import mechanize |
| 7 |
>>> from mechanize._response import test_response |
| 8 |
|
| 9 |
>>> def forms(): |
| 10 |
... forms = [] |
| 11 |
... for method in ["GET", "POST"]: |
| 12 |
... data = ('<form action="" method="%s">' |
| 13 |
... '<input type="submit" name="s"/></form>' % method |
| 14 |
... ) |
| 15 |
... br = mechanize.Browser() |
| 16 |
... br.set_html(data, "http://example.com/") |
| 17 |
... br.select_form(nr=0) |
| 18 |
... forms.append(br.form) |
| 19 |
... return forms |
| 20 |
|
| 21 |
>>> getform, postform = forms() |
| 22 |
>>> getform.click().get_full_url() |
| 23 |
'http://example.com/?s=' |
| 24 |
>>> postform.click().get_full_url() |
| 25 |
'http://example.com/' |
| 26 |
|
| 27 |
|
| 28 |
If something (e.g. calling .forms() triggers parsing, and parsing |
| 29 |
fails, the next attempt should not succeed! This used to happen |
| 30 |
because the response held by LinksFactory etc was stale, since it had |
| 31 |
already been .read(). Fixed by calling Factory.set_response() on |
| 32 |
error. |
| 33 |
|
| 34 |
>>> import mechanize |
| 35 |
>>> br = mechanize.Browser() |
| 36 |
>>> br.set_html("""\ |
| 37 |
... <form> |
| 38 |
... <input type="text" name="foo" value="a"></input><!!!> |
| 39 |
... <input type="text" name="bar" value="b"></input> |
| 40 |
... </form> |
| 41 |
... """) |
| 42 |
>>> try: |
| 43 |
... br.select_form(nr=0) |
| 44 |
... except mechanize.ParseError: |
| 45 |
... pass |
| 46 |
>>> br.select_form(nr=0) |