[Checkins] SVN: van.testing/trunk/ Add a wsgi_intercept layer and a functional_layer that combines both zcml and
Brian Sutherland
jinty at web.de
Wed Apr 1 14:28:32 EDT 2009
Log message for revision 98768:
Add a wsgi_intercept layer and a functional_layer that combines both zcml and
wsgi_intercept layer.
Changed:
_U van.testing/trunk/
U van.testing/trunk/CHANGES.txt
U van.testing/trunk/setup.py
U van.testing/trunk/van/testing/README.txt
U van.testing/trunk/van/testing/__init__.py
A van.testing/trunk/van/testing/ftesting.zcml
U van.testing/trunk/van/testing/layer.py
U van.testing/trunk/van/testing/tests.py
-=-
Property changes on: van.testing/trunk
___________________________________________________________________
Added: svn:ignore
+ develop-eggs
bootstrap.py
bin
parts
van.testing.egg-info
.installed.cfg
Modified: van.testing/trunk/CHANGES.txt
===================================================================
--- van.testing/trunk/CHANGES.txt 2009-04-01 18:21:34 UTC (rev 98767)
+++ van.testing/trunk/CHANGES.txt 2009-04-01 18:28:32 UTC (rev 98768)
@@ -1,13 +1,18 @@
Changes
=======
-1.0.1 (unknown)
+2.0.1 (unknown)
------------------
+2.0.0 (2009-04-01)
+------------------
+
- Remove dependencies by using zope.configuration.xmlconfig to setup zcml
rather than zope.app.appsetup. This leaves out some security configuration
but the win from less dependencies is massive. In my tests, no tests had any
issues with this.
+- Add a wsgi_intercept layer and a functional_layer that combines both zcml
+ and wsgi_intercept layer.
1.0.0 (2008-11-21)
------------------
Modified: van.testing/trunk/setup.py
===================================================================
--- van.testing/trunk/setup.py 2009-04-01 18:21:34 UTC (rev 98767)
+++ van.testing/trunk/setup.py 2009-04-01 18:28:32 UTC (rev 98768)
@@ -33,7 +33,9 @@
namespace_packages=["van"],
install_requires=[
'setuptools',
+ 'wsgi_intercept',
'zope.app.component',
+ 'zope.component',
'zope.configuration',
'zope.testing',
],
Modified: van.testing/trunk/van/testing/README.txt
===================================================================
--- van.testing/trunk/van/testing/README.txt 2009-04-01 18:21:34 UTC (rev 98767)
+++ van.testing/trunk/van/testing/README.txt 2009-04-01 18:28:32 UTC (rev 98768)
@@ -1,6 +1,38 @@
Testing Utilities
=================
+The most common use of this testing module is functional testing zope
+applications. It provides tools to setup layers which load the configuration
+ZCML as well as setting up wsgi_intercept in a layer.
+
+This test is part of such a layer (setup in van.testing.tests.FunctionalLayer):
+
+ >>> from wsgi_intercept import WSGI_HTTPConnection as HTTPConnection
+ >>> conn = HTTPConnection('localhost', 80)
+
+ >>> conn.request('GET', '/')
+ >>> r = conn.getresponse()
+ >>> print r.read() # doctest: +ELLIPSIS
+ {'HTTP_ACCEPT_ENCODING': 'identity',
+ 'HTTP_HOST': 'localhost',
+ 'PATH_INFO': '/',
+ 'QUERY_STRING': '',
+ 'REMOTE_ADDR': '127.0.0.1',
+ 'REQUEST_METHOD': 'GET',
+ 'SCRIPT_NAME': '',
+ 'SERVER_NAME': 'localhost',
+ 'SERVER_PORT': '80',
+ 'SERVER_PROTOCOL': 'HTTP/1.1\r\n',
+ 'wsgi.errors': <cStringIO.StringO object at ...>,
+ 'wsgi.input': <cStringIO.StringI object at ...>,
+ 'wsgi.multiprocess': 0,
+ 'wsgi.multithread': 0,
+ 'wsgi.run_once': 0,
+ 'wsgi.url_scheme': 'http',
+ 'wsgi.version': (1, 0)}
+ Marker: MARKER
+
+
Layers
------
Modified: van.testing/trunk/van/testing/__init__.py
===================================================================
--- van.testing/trunk/van/testing/__init__.py 2009-04-01 18:21:34 UTC (rev 98767)
+++ van.testing/trunk/van/testing/__init__.py 2009-04-01 18:28:32 UTC (rev 98768)
@@ -11,4 +11,3 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-
Added: van.testing/trunk/van/testing/ftesting.zcml
===================================================================
--- van.testing/trunk/van/testing/ftesting.zcml (rev 0)
+++ van.testing/trunk/van/testing/ftesting.zcml 2009-04-01 18:28:32 UTC (rev 98768)
@@ -0,0 +1,15 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ package="van.testing"
+ >
+
+ <include package="zope.component" file="meta.zcml"/>
+
+ <!-- Test declaration so we can see if it was registered -->
+ <utility
+ name="test"
+ component=".tests.MARKER"
+ provides="zope.interface.Interface"
+ />
+
+</configure>
Property changes on: van.testing/trunk/van/testing/ftesting.zcml
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: van.testing/trunk/van/testing/layer.py
===================================================================
--- van.testing/trunk/van/testing/layer.py 2009-04-01 18:21:34 UTC (rev 98767)
+++ van.testing/trunk/van/testing/layer.py 2009-04-01 18:28:32 UTC (rev 98768)
@@ -14,6 +14,7 @@
from zope.configuration import xmlconfig
from zope.app.component import hooks # BBB: import from zope.site at a later date
from zope.testing.cleanup import cleanUp
+import wsgi_intercept
def null_layer(layer):
"""Sets up a class as a layer that doesn nothing.
@@ -90,3 +91,39 @@
pass
layer.testSetUp = classmethod(null)
layer.testTearDown = classmethod(null)
+
+
+class ErrorHandler:
+ """This middleware sets up the environ so that handleErrors actually works.
+
+ zope.testbrowser.Browser.handleErrors that is.
+ """
+ def __init__(self, application):
+ self.application = application
+
+ def __call__(self, environ, start_response):
+ if environ.get('HTTP_X_ZOPE_HANDLE_ERRORS') == 'False':
+ environ['wsgi.handleErrors'] = False
+ def my_start_response(status, headers, exc_info=None):
+ headers = sorted(headers)
+ headers.insert(0, ('Status', status))
+ return start_response(status, sorted(headers), exc_info=exc_info)
+ return self.application(environ, my_start_response)
+
+
+def wsgi_intercept_layer(layer):
+
+ def make_debug_application():
+ return ErrorHandler(layer.make_application())
+
+ def setUp(cls):
+ wsgi_intercept.add_wsgi_intercept('localhost', 80, make_debug_application)
+ layer.setUp = classmethod(setUp)
+
+ def tearDown(cls):
+ wsgi_intercept.remove_wsgi_intercept('localhost', 80)
+
+ def null(cls):
+ pass
+ layer.testSetUp = classmethod(null)
+ layer.testTearDown = classmethod(null)
Modified: van.testing/trunk/van/testing/tests.py
===================================================================
--- van.testing/trunk/van/testing/tests.py 2009-04-01 18:21:34 UTC (rev 98767)
+++ van.testing/trunk/van/testing/tests.py 2009-04-01 18:28:32 UTC (rev 98768)
@@ -11,11 +11,37 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
+import os
import unittest
import doctest
+from pprint import pformat
+from van.testing.layer import zcml_layer, wsgi_intercept_layer
+from zope.component import getUtility
+from zope.interface import Interface
+MARKER = 'MARKER'
+_HERE = os.path.dirname(__file__)
+
+def simple_app(environ, start_response):
+ """Simplest possible application object"""
+ start_response('200 OK', [('Content-type','text/plain')])
+ marker = getUtility(Interface, name=u"test")
+ return [pformat(environ), "\nMarker: %s" % marker]
+
+class ZCMLLayer:
+ zcml = os.path.join(_HERE, 'ftesting.zcml')
+zcml_layer(ZCMLLayer)
+
+class FunctionalLayer(ZCMLLayer):
+ @classmethod
+ def make_application(cls):
+ return simple_app
+wsgi_intercept_layer(FunctionalLayer)
+
def test_suite():
+ ftest = doctest.DocFileSuite('README.txt')
+ ftest.layer = FunctionalLayer
return unittest.TestSuite([
- doctest.DocFileSuite('README.txt'),
+ ftest,
doctest.DocTestSuite('van.testing.layer'),
])
More information about the Checkins
mailing list