[Checkins] SVN: zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/ Fix bug where the wsgi environment variable wsgi.url_scheme was not set correctly for HTTPS urls. Also add an echo_one method to the test application to get one environment variable.
Brian Sutherland
jinty at web.de
Fri Dec 17 08:36:23 EST 2010
Log message for revision 118994:
Fix bug where the wsgi environment variable wsgi.url_scheme was not set correctly for HTTPS urls. Also add an echo_one method to the test application to get one environment variable.
Changed:
U zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/ftests/__init__.py
U zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/ftests/ftesting.zcml
U zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/tests.py
U zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/wsgi.py
A zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/wsgi.txt
-=-
Modified: zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/ftests/__init__.py
===================================================================
--- zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/ftests/__init__.py 2010-12-17 12:45:07 UTC (rev 118993)
+++ zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/ftests/__init__.py 2010-12-17 13:36:22 UTC (rev 118994)
@@ -41,6 +41,14 @@
items.append('Body: %r' % self.request.bodyStream.read())
return '\n'.join(items)
+
+class EchoOne(View):
+ """Echo one variable from the request"""
+
+ def __call__(self):
+ return repr(self.request.get(self.request.form['var']))
+
+
class GetCookie(View):
"""Gets cookie value"""
Modified: zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/ftests/ftesting.zcml
===================================================================
--- zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/ftests/ftesting.zcml 2010-12-17 12:45:07 UTC (rev 118993)
+++ zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/ftests/ftesting.zcml 2010-12-17 13:36:22 UTC (rev 118994)
@@ -36,6 +36,13 @@
/>
<browser:page
+ name="echo_one.html"
+ for="*"
+ class=".ftests.EchoOne"
+ permission="zope.Public"
+ />
+
+ <browser:page
name="set_cookie.html"
for="*"
class=".ftests.SetCookie"
Modified: zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/tests.py
===================================================================
--- zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/tests.py 2010-12-17 12:45:07 UTC (rev 118993)
+++ zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/tests.py 2010-12-17 13:36:22 UTC (rev 118994)
@@ -514,8 +514,12 @@
globs=globals)
fixed_bugs.layer = TestBrowserLayer
- tests.extend([readme, cookies, fixed_bugs])
+ wsgi = FunctionalDocFileSuite('wsgi.txt', optionflags=flags,
+ checker=checker, globs=globals)
+ wsgi.layer = TestBrowserLayer
+ tests.extend([readme, cookies, fixed_bugs, wsgi])
+
return unittest.TestSuite(tests)
Modified: zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/wsgi.py
===================================================================
--- zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/wsgi.py 2010-12-17 12:45:07 UTC (rev 118993)
+++ zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/wsgi.py 2010-12-17 13:36:22 UTC (rev 118994)
@@ -69,6 +69,11 @@
extra_environ['wsgi.handleErrors'] = False # zope.app.wsgi does this
extra_environ['paste.throw_errors'] = True # the paste way of doing this
+ scheme_key = 'X-Zope-Scheme'
+ extra_environ['wsgi.url_scheme'] = headers.get(scheme_key, 'http')
+ if scheme_key in headers:
+ del headers[scheme_key]
+
app = self._test_app
# Here we do a complicated dance to sync the webtest apps idea of what
@@ -123,7 +128,11 @@
def _connect(self, *args, **kw):
return WSGIConnection(self._test_app, *args, **kw)
+ def https_request(self, req):
+ req.add_unredirected_header('X-Zope-Scheme', 'https')
+ return self.http_request(req)
+
class WSGIMechanizeBrowser(zope.testbrowser.testing.PublisherMechanizeBrowser):
"""Special ``mechanize`` browser using the Zope Publisher HTTP handler."""
Added: zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/wsgi.txt
===================================================================
--- zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/wsgi.txt (rev 0)
+++ zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/wsgi.txt 2010-12-17 13:36:22 UTC (rev 118994)
@@ -0,0 +1,20 @@
+Detailed tests for WSGI Browser
+===============================
+
+ >>> browser = Browser()
+
+HTTPS support
+-------------
+
+Depending on the scheme of the request the variable wsgi.url_scheme will be set
+correctly on the request:
+
+ >>> browser.open('http://localhost/echo_one.html?var=wsgi.url_scheme')
+ >>> print browser.contents
+ 'http'
+
+ >>> browser.open('https://localhost/echo_one.html?var=wsgi.url_scheme')
+ >>> print browser.contents
+ 'https'
+
+see http://www.python.org/dev/peps/pep-3333/ for details.
Property changes on: zope.testbrowser/branches/jinty-webtest/src/zope/testbrowser/wsgi.txt
___________________________________________________________________
Added: svn:eol-style
+ native
More information about the checkins
mailing list