[Checkins] SVN: zope.testbrowser/trunk/ LP #98396: testbrowser resolves relative URLs incorrectly.

Tres Seaver tseaver at palladion.com
Wed Apr 14 21:34:34 EDT 2010


Log message for revision 110919:
  LP #98396:  testbrowser resolves relative URLs incorrectly.
  
  This test applies the OPs patch for tests of the bug, but the tests
  pass without any changes to non-test code.
  

Changed:
  U   zope.testbrowser/trunk/CHANGES.txt
  U   zope.testbrowser/trunk/src/zope/testbrowser/tests.py

-=-
Modified: zope.testbrowser/trunk/CHANGES.txt
===================================================================
--- zope.testbrowser/trunk/CHANGES.txt	2010-04-14 22:29:36 UTC (rev 110918)
+++ zope.testbrowser/trunk/CHANGES.txt	2010-04-15 01:34:33 UTC (rev 110919)
@@ -5,7 +5,7 @@
 3.8.1 (unreleased)
 ------------------
 
-- TBD
+- LP #98396:  testbrowser resolves relative URLs incorrectly.
 
 
 3.8.0 (2010-03-05)

Modified: zope.testbrowser/trunk/src/zope/testbrowser/tests.py
===================================================================
--- zope.testbrowser/trunk/src/zope/testbrowser/tests.py	2010-04-14 22:29:36 UTC (rev 110918)
+++ zope.testbrowser/trunk/src/zope/testbrowser/tests.py	2010-04-15 01:34:33 UTC (rev 110919)
@@ -165,9 +165,10 @@
         mech_browser = FauxMechanizeBrowser()
         super(Browser, self).__init__(url=url, mech_browser=mech_browser)
 
-    def open(self, body, headers=None, status=200, reason='OK'):
+    def open(self, body, headers=None, status=200, reason='OK',
+             url='http://localhost/'):
         set_next_response(body, headers, status, reason)
-        zope.testbrowser.browser.Browser.open(self, 'http://localhost/')
+        zope.testbrowser.browser.Browser.open(self, url)
 
 def test_submit_duplicate_name():
     """
@@ -377,6 +378,58 @@
     '  Foo  '
     """
 
+def test_relative_link():
+    """
+    RFC 1808 specifies how relative URLs should be resolved, let's see
+    that we conform to it. Let's start with a simple example.
+
+    >>> browser = Browser()
+    >>> browser.open('''\
+    ... <html><body>
+    ...     <a href="foo">link</a>
+    ... </body></html>
+    ... ''', url='http://localhost/bar') # doctest: +ELLIPSIS
+    GET /bar HTTP/1.1
+    ...
+
+    >>> link = browser.getLink('link')
+    >>> link.url
+    'http://localhost/foo'
+
+    It's possible to have a relative URL consisting of only a query part. In
+    that case it should simply be appended to the base URL.
+
+    >>> browser.open('''\
+    ... <html><body>
+    ...     <a href="?key=value">link</a>
+    ... </body></html>
+    ... ''', url='http://localhost/bar') # doctest: +ELLIPSIS
+    GET /bar HTTP/1.1
+    ...
+
+    >>> link = browser.getLink('link')
+    >>> link.url
+    'http://localhost/bar?key=value'
+
+    In the example above, the base URL was the page URL, but we can also
+    specify a base URL using a <base> tag.
+
+    >>> browser.open('''\
+    ... <html><head><base href="http://localhost/base" /></head><body>
+    ...     <a href="?key=value">link</a>
+    ... </body></html>
+    ... ''', url='http://localhost/base/bar') # doctest: +ELLIPSIS
+    GET /base/bar HTTP/1.1
+    ...
+
+    >>> link = browser.getLink('link')
+    >>> link.url
+    'http://localhost/base?key=value'
+
+    """
+
+
+
 class win32CRLFtransformer(object):
     def sub(self, replacement, text):
         return text.replace(r'\r','')



More information about the checkins mailing list