--- tests.py 2008-05-10 08:37:31.000000000 +0200 +++ tests.py.bug98437 2009-03-26 20:51:57.000000000 +0100 @@ -183,21 +183,15 @@ >>> browser.getControl('BAD').value 'BAD' - >>> browser.getControl('BAD').click() # doctest: +REPORT_NDIFF + >>> browser.getControl('BAD').click() # doctest: +REPORT_NDIFF +ELLIPSIS POST / HTTP/1.1 - Content-length: 176 - Connection: close - Content-type: multipart/form-data; boundary=---------------------------100167997466992641913031254 - Host: localhost - User-agent: Python-urllib/2.4 - - -----------------------------100167997466992641913031254 + ... + Content-type: multipart/form-data; ... Content-disposition: form-data; name="submit_me" BAD - -----------------------------100167997466992641913031254-- - - + ... + This also works if the labels have whitespace around them (this tests a regression caused by the original fix for the above): @@ -214,21 +208,14 @@ >>> browser.getControl('BAD').value ' BAD ' - >>> browser.getControl('BAD').click() # doctest: +REPORT_NDIFF + >>> browser.getControl('BAD').click() # doctest: +REPORT_NDIFF +ELLIPSIS POST / HTTP/1.1 - Content-length: 176 - Connection: close - Content-type: multipart/form-data; boundary=---------------------------100167997466992641913031254 - Host: localhost - User-agent: Python-urllib/2.4 - - -----------------------------100167997466992641913031254 + ... + Content-type: multipart/form-data;... Content-disposition: form-data; name="submit_me" BAD - -----------------------------100167997466992641913031254-- - - + ... """ def test_file_upload(): @@ -252,44 +239,30 @@ >>> browser.getControl(name='foo').add_file( ... StringIO('sample_data'), 'text/foo', 'x.foo') - >>> browser.getControl('OK').click() + >>> browser.getControl('OK').click() # doctest: +REPORT_NDIFF +ELLIPSIS POST / HTTP/1.1 - Content-length: 173 - Connection: close - Content-type: multipart/form-data; boundary=127.0.0.11000318041146699896411 - Host: localhost - User-agent: Python-urllib/2.99 - - --127.0.0.11000318041146699896411 + ... + Content-type: multipart/form-data;... Content-disposition: form-data; name="foo"; filename="x.foo" Content-type: text/foo sample_data - --127.0.0.11000318041146699896411-- - - + ... + You can pass a string to add_file: >>> browser.getControl(name='foo').add_file( ... 'blah blah blah', 'text/blah', 'x.blah') - >>> browser.getControl('OK').click() + >>> browser.getControl('OK').click() # doctest: +REPORT_NDIFF +ELLIPSIS POST / HTTP/1.1 - Content-length: 178 - Connection: close - Content-type: multipart/form-data; boundary=127.0.0.11000318541146700017052 - Host: localhost - User-agent: Python-urllib/2.98 - - --127.0.0.11000318541146700017052 + ... + Content-type: multipart/form-data;... Content-disposition: form-data; name="foo"; filename="x.blah" Content-type: text/blah blah blah blah - --127.0.0.11000318541146700017052-- - - - + ... """ @@ -352,6 +325,33 @@ ' Foo ' """ +def test_submit_gets_referrer(): + """ +This tests for bug #98437: No HTTP_REFERER was send when submitting a form. + + >>> browser = Browser() + +A simple form for testing, like abobe. + + >>> browser.open('''\ + ... + ...
+ ... + ...
+ ... ''') # doctest: +ELLIPSIS + GET / HTTP/1.1 + ... + +Now submit the form, and see that we get an referrer along. + + >>> form = browser.getForm(id='form') + >>> form.submit(name='submit_me') # doctest: +ELLIPSIS + POST / HTTP/1.1 + ... + Referer: http://localhost/ + ... +""" + checker = renormalizing.RENormalizing([ (re.compile(r'^--\S+\.\S+\.\S+', re.M), '-'*30), (re.compile(r'boundary=\S+\.\S+\.\S+'), 'boundary='+'-'*30),