[Checkins] SVN: zope.app.wsgi/trunk/ Merge sylvain-testlayers.

Sylvain Viollon sylvain at infrae.com
Tue Apr 13 07:49:56 EDT 2010


Log message for revision 110773:
  Merge sylvain-testlayers.
  Update CHANGES.txt and version.
  
  

Changed:
  U   zope.app.wsgi/trunk/CHANGES.txt
  U   zope.app.wsgi/trunk/buildout.cfg
  U   zope.app.wsgi/trunk/setup.py
  U   zope.app.wsgi/trunk/src/zope/app/wsgi/README.txt
  U   zope.app.wsgi/trunk/src/zope/app/wsgi/ftesting.zcml
  U   zope.app.wsgi/trunk/src/zope/app/wsgi/testing.py
  A   zope.app.wsgi/trunk/src/zope/app/wsgi/testlayer.py
  U   zope.app.wsgi/trunk/src/zope/app/wsgi/tests.py

-=-
Modified: zope.app.wsgi/trunk/CHANGES.txt
===================================================================
--- zope.app.wsgi/trunk/CHANGES.txt	2010-04-13 11:38:57 UTC (rev 110772)
+++ zope.app.wsgi/trunk/CHANGES.txt	2010-04-13 11:49:56 UTC (rev 110773)
@@ -2,12 +2,12 @@
 CHANGES
 =======
 
-3.6.2 (unreleased)
+3.7.0 (unreleased)
 ------------------
 
-- Nothing changed yet.
+- Rewrite tests in order not to dependent on zope.app.testing and
+  zope.app.zcmlfiles.
 
-
 3.6.1 (2010-01-29)
 ------------------
 

Modified: zope.app.wsgi/trunk/buildout.cfg
===================================================================
--- zope.app.wsgi/trunk/buildout.cfg	2010-04-13 11:38:57 UTC (rev 110772)
+++ zope.app.wsgi/trunk/buildout.cfg	2010-04-13 11:49:56 UTC (rev 110773)
@@ -1,8 +1,12 @@
 [buildout]
 develop = . 
-parts = test
+parts = svn test
 
+[svn]
+recipe = infrae.subversion
+as_eggs = True
+urls = svn://svn.zope.org/repos/main/zope.app.appsetup/trunk zope.app.appsetup
+
 [test]
 recipe = zc.recipe.testrunner
 eggs = zope.app.wsgi [test]
-

Modified: zope.app.wsgi/trunk/setup.py
===================================================================
--- zope.app.wsgi/trunk/setup.py	2010-04-13 11:38:57 UTC (rev 110772)
+++ zope.app.wsgi/trunk/setup.py	2010-04-13 11:49:56 UTC (rev 110773)
@@ -23,7 +23,7 @@
 from setuptools import setup, find_packages
 
 setup(name='zope.app.wsgi',
-      version = '3.6.2dev',
+      version = '3.7.0dev',
       url='http://pypi.python.org/pypi/zope.app.wsgi',
       license='ZPL 2.1',
       description='WSGI application for the zope.publisher',
@@ -44,20 +44,40 @@
       packages=find_packages('src'),
       package_dir = {'': 'src'},
       namespace_packages=['zope', 'zope.app'],
-      extras_require = dict(test=['zope.app.testing',
-                                  'zope.app.securitypolicy',
-                                  'zope.app.zcmlfiles',
-                                  'zope.testbrowser']),
-      install_requires=['setuptools',
-                        'ZConfig',
-                        'zope.app.appsetup >= 3.11.0',
-                        'zope.processlifetime',
-                        'zope.app.publication',
-                        'zope.event',
-                        'zope.interface',
-                        'zope.publisher',
-                        'zope.security',
-                        ],
+      extras_require = dict(test=[
+          'zope.annotation',
+          'zope.authentication',
+          'zope.browserpage',
+          'zope.componentvocabulary',
+          'zope.location',
+          'zope.login',
+          'zope.password',
+          'zope.principalregistry',
+          'zope.securitypolicy',
+          ]),
+      install_requires=[
+          'setuptools',
+          'ZConfig',
+          'wsgi_intercept',
+          'ZODB3',
+          'zope.app.appsetup >= 3.11.0',
+          'zope.processlifetime',
+          'zope.app.publication',
+          'zope.event',
+          'zope.interface',
+          'zope.publisher',
+          'zope.security',
+          'zope.component',
+          'zope.configuration',
+          'zope.container',
+          'zope.error',
+          'zope.lifecycleevent',
+          'zope.session',
+          'zope.site',
+          'zope.testbrowser',
+          'zope.testing',
+          'zope.traversing',
+          ],
       entry_points={
           'paste.app_factory': [
               'main = zope.app.wsgi.paste:ZopeApplication'

Modified: zope.app.wsgi/trunk/src/zope/app/wsgi/README.txt
===================================================================
--- zope.app.wsgi/trunk/src/zope/app/wsgi/README.txt	2010-04-13 11:38:57 UTC (rev 110772)
+++ zope.app.wsgi/trunk/src/zope/app/wsgi/README.txt	2010-04-13 11:49:56 UTC (rev 110773)
@@ -47,8 +47,8 @@
 Now we can send the fabricated HTTP request to the application for processing:
 
   >>> print ''.join(app(environ, start_response))
-  <html><head><title>ComponentLookupError</title></head>
-  <body><h2>ComponentLookupError</h2>
+  <html><head><title>SystemError</title></head>
+  <body><h2>SystemError</h2>
   A server error occurred.
   </body></html>
   <BLANKLINE>
@@ -100,46 +100,15 @@
 environ after being sent to the app and also see that a key has been set to
 store user names for use in access logs.
 
-The key points be default to ``-`` if no user info is found:
+This logging information is provided by an adapter registered for
+`ILoggingInfo`. Out-of-the-box, `zope.publisher` registers a base
+adapter that returns the principal id as value::
 
   >>> print environ
   {'wsgi.input': <cStringIO.StringI object at ...>,
-   'wsgi.logging_info': '-', 'PATH_INFO': '/'}
+   'wsgi.logging_info': 'zope.anybody', 'PATH_INFO': '/'}
 
-Since we do not have a principal available in this setup we simply provide
-a ILoggingInfo adapter for our missing principal e.g. None:
 
-  >>> import zope.interface
-  >>> import zope.component
-  >>> from zope.publisher.interfaces.logginginfo import ILoggingInfo
-  >>> from zope.security.interfaces import IPrincipal
-  >>> class LoggingInfoStub(object):
-  ...     zope.interface.implements(ILoggingInfo)
-  ...     zope.component.adapts(zope.interface.Interface)  
-  ...     def __init__(self, request):
-  ...         self.request = request 
-  ...     def getLogMessage(self):
-  ...         return 'foobar'
-
-Now register the ILoggingInfo adapter and check again:
-
-  >>> zope.component.provideAdapter(LoggingInfoStub) 
-  >>> print ''.join(app(environ, start_response))
-  <html><head><title>ComponentLookupError</title></head>
-  <body><h2>ComponentLookupError</h2>
-  A server error occurred.
-  </body></html>
-  <BLANKLINE>
-
-As you can see, the app is still not working but our ILoggingInfo stub get
-invoked and provides a custom logging_info message:
-
-  >>> print environ
-  {'wsgi.input': <cStringIO.StringI object at ...>,
-   'wsgi.logging_info': 'foobar',
-   'PATH_INFO': '/'}
-
-
 Creating A WSGI Application
 ---------------------------
 
@@ -182,6 +151,7 @@
   >>> import zope.component
   >>> from zope.app.wsgi.interfaces import IWSGIPublisherApplicationCreatedEvent
   >>> called = []
+
   >>> @zope.component.adapter(IWSGIPublisherApplicationCreatedEvent)
   ... def handler(event):
   ...     called.append(event)
@@ -206,6 +176,7 @@
   >>> import shutil
   >>> shutil.rmtree(temp_dir)
 
+
 About WSGI
 ----------
 

Modified: zope.app.wsgi/trunk/src/zope/app/wsgi/ftesting.zcml
===================================================================
--- zope.app.wsgi/trunk/src/zope/app/wsgi/ftesting.zcml	2010-04-13 11:38:57 UTC (rev 110772)
+++ zope.app.wsgi/trunk/src/zope/app/wsgi/ftesting.zcml	2010-04-13 11:49:56 UTC (rev 110773)
@@ -7,11 +7,27 @@
   <!-- This file is the equivalent of site.zcml and it is -->
   <!-- used for functional testing setup -->
 
+  <include package="zope.component" file="meta.zcml" />
+  <include package="zope.security" file="meta.zcml" />
+  <include package="zope.publisher" file="meta.zcml" />
+  <include package="zope.principalregistry" file="meta.zcml" />
+  <include package="zope.browserpage" file="meta.zcml" />
+  <include package="zope.app.publication" file="meta.zcml" />
   <include package="zope.securitypolicy" file="meta.zcml" />
-  <include package="zope.app.zcmlfiles" />
 
+  <include package="zope.login" />
+  <include package="zope.security" />
+  <include package="zope.authentication" />
   <include package="zope.securitypolicy" />
+  <include package="zope.principalregistry" />
+  <include package="zope.app.publication" />
+  <include package="zope.app.appsetup" file="ftesting.zcml"/>
+  <include package="zope.annotation" />
+  <include package="zope.publisher" />
+  <include package="zope.password" />
 
+  <include package="zope.app.wsgi" />
+
   <securityPolicy
     component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
 
@@ -20,10 +36,12 @@
   <grantAll role="zope.Manager" />
 
   <!-- Principals -->
-
   <unauthenticatedPrincipal
       id="zope.anybody"
       title="Unauthenticated User" />
+  <grant
+      permission="zope.View"
+      principal="zope.anybody" />
 
   <!-- Principal that tests generally run as -->
   <principal
@@ -32,14 +50,7 @@
       login="mgr"
       password="mgrpw" />
 
-  <!-- Bootstrap principal used to make local grant to the principal above -->
-  <principal
-      id="zope.globalmgr"
-      title="Manager"
-      login="globalmgr"
-      password="globalmgrpw" />
+  <grant role="zope.Manager" principal="zope.mgr" />
 
-  <grant role="zope.Manager" principal="zope.globalmgr" />
-
 </configure>
 

Modified: zope.app.wsgi/trunk/src/zope/app/wsgi/testing.py
===================================================================
--- zope.app.wsgi/trunk/src/zope/app/wsgi/testing.py	2010-04-13 11:38:57 UTC (rev 110772)
+++ zope.app.wsgi/trunk/src/zope/app/wsgi/testing.py	2010-04-13 11:49:56 UTC (rev 110773)
@@ -18,9 +18,8 @@
 
 __docformat__ = "reStructuredText"
 
-import os
-from zope.app.testing.functional import ZCMLLayer
+import zope.app.wsgi
+from zope.app.wsgi.testlayer import BrowserLayer
 
-AppWSGILayer = ZCMLLayer(
-    os.path.join(os.path.split(__file__)[0], 'ftesting.zcml'),
-    __name__, 'AppWSGILayer', allow_teardown=True)
+AppWSGILayer = BrowserLayer(zope.app.wsgi)
+

Copied: zope.app.wsgi/trunk/src/zope/app/wsgi/testlayer.py (from rev 109150, zope.app.wsgi/branches/sylvain-testlayers/src/zope/app/wsgi/testlayer.py)
===================================================================
--- zope.app.wsgi/trunk/src/zope/app/wsgi/testlayer.py	                        (rev 0)
+++ zope.app.wsgi/trunk/src/zope/app/wsgi/testlayer.py	2010-04-13 11:49:56 UTC (rev 110773)
@@ -0,0 +1,64 @@
+##############################################################################
+#
+# Copyright (c) 2010 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+import wsgi_intercept
+from zope.app.appsetup.testlayer import ZODBLayer
+
+from zope.app.wsgi import WSGIPublisherApplication
+from zope.app.publication.httpfactory import HTTPPublicationRequestFactory
+from wsgi_intercept.mechanize_intercept import Browser as BaseInterceptBrowser
+from zope.testbrowser.browser import Browser as ZopeTestbrowser
+
+class InterceptBrowser(BaseInterceptBrowser):
+
+    default_schemes = ['http']
+    default_others = ['_http_error', '_http_request_upgrade',
+                      '_http_default_error']
+    default_features = ['_redirect', '_cookies', '_referer', '_refresh',
+                        '_equiv', '_basicauth', '_digestauth']
+
+
+class Browser(ZopeTestbrowser):
+    """Override the zope.testbrowser.browser.Browser interface so that it
+    uses PatchedMechanizeBrowser
+    """
+
+    def __init__(self, *args, **kwargs):
+        kwargs['mech_browser'] = InterceptBrowser()
+        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.
+
+    A wsgi_intercept handler is installed as well, so you can use a
+    WSGI version of zope.testbrowser Browser instance to access the
+    application.
+    """
+
+    def testSetUp(self):
+        super(BrowserLayer, self).testSetUp()
+        wsgi_app = WSGIPublisherApplication(
+            self.db, HTTPPublicationRequestFactory, False)
+
+        def factory():
+            return wsgi_app
+
+        wsgi_intercept.add_wsgi_intercept('localhost', 80, factory)
+
+
+    def testTearDown(self):
+        super(BrowserLayer, self).testTearDown()
+        wsgi_intercept.remove_wsgi_intercept('localhost', 80)

Modified: zope.app.wsgi/trunk/src/zope/app/wsgi/tests.py
===================================================================
--- zope.app.wsgi/trunk/src/zope/app/wsgi/tests.py	2010-04-13 11:38:57 UTC (rev 110772)
+++ zope.app.wsgi/trunk/src/zope/app/wsgi/tests.py	2010-04-13 11:49:56 UTC (rev 110773)
@@ -18,27 +18,27 @@
 import tempfile
 import unittest
 import re
+import zope.component
 
 from zope import component, interface
+from zope.component.testlayer import ZCMLFileLayer
 from zope.testing import doctest
 from zope.testing import renormalizing
 
+import zope.event
+import zope.app.wsgi
 import zope.publisher.interfaces.browser
-from zope.app.testing import placelesssetup, ztapi
 from zope.app.publication.requestpublicationregistry import factoryRegistry
 from zope.app.publication.requestpublicationfactories import BrowserFactory
 from zope.app.wsgi.testing import AppWSGILayer
-from zope.app.security.interfaces import IAuthentication
-from zope.app.security.principalregistry import principalRegistry
+from zope.authentication.interfaces import IAuthentication
+from zope.securitypolicy.tests import principalRegistry
 
 
-def setUp(test):
-    placelesssetup.setUp(test)
-    factoryRegistry.register('GET', '*', 'browser', 0, BrowserFactory())
-    ztapi.provideUtility(IAuthentication, principalRegistry)
+def cleanEvents(s):
+    zope.event.subscribers.pop()
 
 
-
 class FileView:
 
     interface.implements(zope.publisher.interfaces.browser.IBrowserPublisher)
@@ -71,7 +71,7 @@
     ...     checker.NamesChecker(['browserDefault', '__call__']),
     ...     )
 
-    >>> from zope.testbrowser.testing import Browser
+    >>> from zope.app.wsgi.testlayer import Browser
     >>> browser = Browser()
     >>> browser.handleErrors = False
     >>> browser.open('http://localhost/@@test-file-view.html')
@@ -109,14 +109,22 @@
     functional_suite = doctest.DocTestSuite()
     functional_suite.layer = AppWSGILayer
 
+    readme_test = doctest.DocFileSuite(
+            'README.txt',
+            checker=checker, tearDown=cleanEvents,
+            optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
+
+    doctest_suite = doctest.DocFileSuite(
+            'fileresult.txt', 'paste.txt',
+            checker=checker,
+            optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
+
+    readme_test.layer = ZCMLFileLayer(zope.app.wsgi)
+    doctest_suite.layer = ZCMLFileLayer(zope.app.wsgi)
+
+
     return unittest.TestSuite((
-        functional_suite,
-        doctest.DocFileSuite(
-            'README.txt', 'fileresult.txt', 'paste.txt',
-            setUp=setUp, checker=checker,
-            tearDown=placelesssetup.tearDown,
-            optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
-        ))
+        functional_suite, readme_test, doctest_suite))
 
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')



More information about the checkins mailing list