| Integration regression test for case where ClientForm handled RFC 3986 |
| url unparsing incorrectly (it was using "" in place of None for |
| fragment, due to continuing to support use of stdlib module urlparse |
| as well as mechanize._rfc3986). Fixed in ClientForm r33622 . |
| |
| >>> import mechanize |
| >>> from mechanize._response import test_response |
| |
| >>> def forms(): |
| ... forms = [] |
| ... for method in ["GET", "POST"]: |
| ... data = ('<form action="" method="%s">' |
| ... '<input type="submit" name="s"/></form>' % method |
| ... ) |
| ... br = mechanize.Browser() |
| ... response = test_response(data, [("content-type", "text/html")]) |
| ... br.set_response(response) |
| ... br.select_form(nr=0) |
| ... forms.append(br.form) |
| ... return forms |
| |
| >>> getform, postform = forms() |
| >>> getform.click().get_full_url() |
| 'http://example.com/?s=' |
| >>> postform.click().get_full_url() |
| 'http://example.com/' |
| |
| >>> data = '<form action=""><isindex /></form>' |
| >>> br = mechanize.Browser() |
| >>> response = test_response(data, [("content-type", "text/html")]) |
| >>> br.set_response(response) |
| >>> br.select_form(nr=0) |
| >>> br.find_control(type="isindex").value = "blah" |
| >>> br.click(type="isindex").get_full_url() |
| 'http://example.com/?blah' |
| |
| |
| If something (e.g. calling .forms() triggers parsing, and parsing |
| fails, the next attempt should not succeed! This used to happen |
| because the response held by LinksFactory etc was stale, since it had |
| already been .read(). Fixed by calling Factory.set_response() on |
| error. |
| |
| >>> import mechanize |
| >>> br = mechanize.Browser() |
| >>> r = mechanize._response.test_html_response("""\ |
| ... <form> |
| ... <input type="text" name="foo" value="a"></input><!!!> |
| ... <input type="text" name="bar" value="b"></input> |
| ... </form> |
| ... """) |
| >>> br.set_response(r) |
| >>> try: |
| ... br.select_form(nr=0) |
| ... except mechanize.ParseError: |
| ... pass |
| >>> br.select_form(nr=0) # doctest: +IGNORE_EXCEPTION_DETAIL |
| Traceback (most recent call last): |
| ParseError: expected name token |