[Checkins] SVN: zope.app.wsgi/branches/sylvain-testlayers/s Test layer modification.

Sylvain Viollon sylvain at infrae.com
Wed Jan 27 03:09:00 EST 2010


Log message for revision 108554:
  Test layer modification.
  
  

Changed:
  U   zope.app.wsgi/branches/sylvain-testlayers/setup.py
  U   zope.app.wsgi/branches/sylvain-testlayers/src/zope/app/wsgi/ftesting.zcml
  U   zope.app.wsgi/branches/sylvain-testlayers/src/zope/app/wsgi/testing.py
  A   zope.app.wsgi/branches/sylvain-testlayers/src/zope/app/wsgi/testlayer.py
  U   zope.app.wsgi/branches/sylvain-testlayers/src/zope/app/wsgi/tests.py

-=-
Modified: zope.app.wsgi/branches/sylvain-testlayers/setup.py
===================================================================
--- zope.app.wsgi/branches/sylvain-testlayers/setup.py	2010-01-27 08:06:59 UTC (rev 108553)
+++ zope.app.wsgi/branches/sylvain-testlayers/setup.py	2010-01-27 08:09:00 UTC (rev 108554)
@@ -49,6 +49,7 @@
                                   'zope.app.zcmlfiles',
                                   'zope.testbrowser']),
       install_requires=['setuptools',
+                        'wsgi_intercept',
                         'ZConfig',
                         'zope.app.appsetup >= 3.11.0',
                         'zope.processlifetime',

Modified: zope.app.wsgi/branches/sylvain-testlayers/src/zope/app/wsgi/ftesting.zcml
===================================================================
--- zope.app.wsgi/branches/sylvain-testlayers/src/zope/app/wsgi/ftesting.zcml	2010-01-27 08:06:59 UTC (rev 108553)
+++ zope.app.wsgi/branches/sylvain-testlayers/src/zope/app/wsgi/ftesting.zcml	2010-01-27 08:09:00 UTC (rev 108554)
@@ -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/branches/sylvain-testlayers/src/zope/app/wsgi/testing.py
===================================================================
--- zope.app.wsgi/branches/sylvain-testlayers/src/zope/app/wsgi/testing.py	2010-01-27 08:06:59 UTC (rev 108553)
+++ zope.app.wsgi/branches/sylvain-testlayers/src/zope/app/wsgi/testing.py	2010-01-27 08:09:00 UTC (rev 108554)
@@ -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)
+

Added: zope.app.wsgi/branches/sylvain-testlayers/src/zope/app/wsgi/testlayer.py
===================================================================
--- zope.app.wsgi/branches/sylvain-testlayers/src/zope/app/wsgi/testlayer.py	                        (rev 0)
+++ zope.app.wsgi/branches/sylvain-testlayers/src/zope/app/wsgi/testlayer.py	2010-01-27 08:09:00 UTC (rev 108554)
@@ -0,0 +1,68 @@
+
+import wsgi_intercept
+import wsgi_intercept.zope_testbrowser
+##############################################################################
+#
+# 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/branches/sylvain-testlayers/src/zope/app/wsgi/tests.py
===================================================================
--- zope.app.wsgi/branches/sylvain-testlayers/src/zope/app/wsgi/tests.py	2010-01-27 08:06:59 UTC (rev 108553)
+++ zope.app.wsgi/branches/sylvain-testlayers/src/zope/app/wsgi/tests.py	2010-01-27 08:09:00 UTC (rev 108554)
@@ -20,11 +20,12 @@
 import re
 
 from zope import component, interface
+from zope.component.testlayer import ZCMLFileLayer
 from zope.testing import doctest
 from zope.testing import renormalizing
 
+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
@@ -32,11 +33,10 @@
 from zope.app.security.principalregistry import principalRegistry
 
 
-def setUp(test):
-    placelesssetup.setUp(test)
-    factoryRegistry.register('GET', '*', 'browser', 0, BrowserFactory())
-    ztapi.provideUtility(IAuthentication, principalRegistry)
+class WSGILayer(ZCMLFileLayer):
 
+    def tearDown(self):
+        import pdb ; pdb.set_trace()
 
 
 class FileView:
@@ -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')
@@ -108,15 +108,14 @@
     ])
     functional_suite = doctest.DocTestSuite()
     functional_suite.layer = AppWSGILayer
+    doctest_suite = doctest.DocFileSuite(
+            'README.txt', 'fileresult.txt', 'paste.txt',
+            checker=checker,
+            optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
+    doctest_suite.layer = WSGILayer(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, doctest_suite))
 
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')



More information about the checkins mailing list