[Checkins] SVN: gocept.selenium/trunk/ - Added some notes how to test a Zope 2 WSGI application.

Michael Howitz mh at gocept.com
Tue Jun 21 02:47:58 EDT 2011


Log message for revision 121960:
  - Added some notes how to test a Zope 2 WSGI application.
  
  

Changed:
  U   gocept.selenium/trunk/CHANGES.txt
  U   gocept.selenium/trunk/src/gocept/selenium/README.txt

-=-
Modified: gocept.selenium/trunk/CHANGES.txt
===================================================================
--- gocept.selenium/trunk/CHANGES.txt	2011-06-16 09:43:34 UTC (rev 121959)
+++ gocept.selenium/trunk/CHANGES.txt	2011-06-21 06:47:57 UTC (rev 121960)
@@ -4,7 +4,7 @@
 0.10.2 (unreleased)
 -------------------
 
-- Nothing changed yet.
+- Added some notes how to test a Zope 2 WSGI application.
 
 
 0.10.1 (2011-02-02)

Modified: gocept.selenium/trunk/src/gocept/selenium/README.txt
===================================================================
--- gocept.selenium/trunk/src/gocept/selenium/README.txt	2011-06-16 09:43:34 UTC (rev 121959)
+++ gocept.selenium/trunk/src/gocept/selenium/README.txt	2011-06-21 06:47:57 UTC (rev 121960)
@@ -42,7 +42,36 @@
 
         layer = test_layer
 
+Quick start for WSGI applications (Zope 2)
+------------------------------------------
 
+When running Zope 2 as WSGI application you might need the following
+additional middleware around your WSGI application::
+
+    class CleanerMiddleware(object):
+        """Fix problems between WSGI server and middlewares."""
+
+        def __init__(self, app):
+            self.app = app
+
+        def __call__(self, environ, start_response):
+            # wsgiref.simple_server.ServerHandler.setup_environ adds
+            # 'CONTENT_LENGTH' key to environ which has the value '', but
+            # repoze.retry.Retry.__call__ 1.0. expects the value to be
+            # convertable to `int` See http://bugs.repoze.org/issue171.
+            if environ.get('CONTENT_LENGTH') == '':
+                del environ['CONTENT_LENGTH']
+
+            # gocept.selenium uses wsgiref but
+            # wsgiref.simple_server.ServerHandler.start_response bails when it
+            # sees the 'Connection' header, so we frankly remove it here:
+            def clean_start_response(status, headers, exc_info):
+                headers = [(k, v) for (k, v) in headers if k != 'Connection']
+                return start_response(status, headers, exc_info)
+
+            return self.app(environ, clean_start_response)
+
+
 Quick start with ZTK (zope.app.testing)
 ---------------------------------------
 



More information about the checkins mailing list