[Checkins] SVN: zope.app.wsgi/trunk/ Add a http function to write functional test like using the http

Sylvain Viollon sylvain at infrae.com
Tue Apr 13 10:23:57 EDT 2010


Log message for revision 110797:
  Add a http function to write functional test like using the http 
  function of zope.app.testing.
  

Changed:
  U   zope.app.wsgi/trunk/CHANGES.txt
  U   zope.app.wsgi/trunk/src/zope/app/wsgi/testlayer.py

-=-
Modified: zope.app.wsgi/trunk/CHANGES.txt
===================================================================
--- zope.app.wsgi/trunk/CHANGES.txt	2010-04-13 13:38:34 UTC (rev 110796)
+++ zope.app.wsgi/trunk/CHANGES.txt	2010-04-13 14:23:56 UTC (rev 110797)
@@ -8,6 +8,10 @@
 - Rewrite tests in order not to dependent on zope.app.testing and
   zope.app.zcmlfiles.
 
+- Add an test http function and a Browser class and BrowserLayer test
+  layer to write functional tests.
+
+
 3.6.1 (2010-01-29)
 ------------------
 

Modified: zope.app.wsgi/trunk/src/zope/app/wsgi/testlayer.py
===================================================================
--- zope.app.wsgi/trunk/src/zope/app/wsgi/testlayer.py	2010-04-13 13:38:34 UTC (rev 110796)
+++ zope.app.wsgi/trunk/src/zope/app/wsgi/testlayer.py	2010-04-13 14:23:56 UTC (rev 110797)
@@ -11,6 +11,8 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
+from StringIO import StringIO
+
 import wsgi_intercept
 from zope.app.appsetup.testlayer import ZODBLayer
 
@@ -38,7 +40,6 @@
         ZopeTestbrowser.__init__(self, *args, **kwargs)
 
 
-
 class BrowserLayer(ZODBLayer):
     """This create a test layer with a test database and register a wsgi
     application to use that test database.
@@ -48,10 +49,12 @@
     application.
     """
 
+    handleErrors = True
+
     def testSetUp(self):
         super(BrowserLayer, self).testSetUp()
         wsgi_app = WSGIPublisherApplication(
-            self.db, HTTPPublicationRequestFactory, False)
+            self.db, HTTPPublicationRequestFactory, self.handleErrors)
 
         def factory():
             return wsgi_app
@@ -62,3 +65,25 @@
     def testTearDown(self):
         super(BrowserLayer, self).testTearDown()
         wsgi_intercept.remove_wsgi_intercept('localhost', 80)
+
+
+class NotInBrowserLayer(Exception):
+    """The current test is not running in a layer inheriting from
+    BrowserLayer.
+    """
+
+
+def http(string):
+    key = ('localhost', 80)
+
+    if key not in wsgi_intercept._wsgi_intercept:
+        raise NotInBrowserLayer(NotInBrowserLayer.__doc__)
+
+    (app_fn, script_name) = wsgi_intercept._wsgi_intercept[key]
+    app = app_fn()
+
+    socket = wsgi_intercept.wsgi_fake_socket(app, 'localhost', 80, '')
+    socket.sendall(string.lstrip())
+    result = socket.makefile()
+    return result.getvalue()
+



More information about the checkins mailing list