[Zope3-checkins] SVN: Zope3/trunk/ Changed the functional tests to use a utility, provided by a security

Jim Fulton jim at zope.com
Tue Feb 8 17:37:51 EST 2005


Log message for revision 29087:
  Changed the functional tests to use a utility, provided by a security
  policy, to grant access to the test manager.  This is to avoid a
  dependcy on the security policy. (I'm using an alternate polciy for an
  application of mine.)
  
  This is an interim solution, we really need a lot more flexibility in
  our functional test setup.
  

Changed:
  U   Zope3/trunk/ftesting.zcml
  A   Zope3/trunk/securitypolicy-ftesting.zcml
  A   Zope3/trunk/src/zope/app/securitypolicy/tests/functional.py
  A   Zope3/trunk/src/zope/app/securitypolicy/tests/functional.zcml
  U   Zope3/trunk/src/zope/app/tests/functional.py

-=-
Modified: Zope3/trunk/ftesting.zcml
===================================================================
--- Zope3/trunk/ftesting.zcml	2005-02-08 20:14:41 UTC (rev 29086)
+++ Zope3/trunk/ftesting.zcml	2005-02-08 22:37:51 UTC (rev 29087)
@@ -13,6 +13,7 @@
   <include files="package-includes/*-ftesting.zcml" />
 
   <include file="securitypolicy.zcml" />
+  <include file="securitypolicy-ftesting.zcml" />
 
   <!-- Principals -->
 

Added: Zope3/trunk/securitypolicy-ftesting.zcml
===================================================================
--- Zope3/trunk/securitypolicy-ftesting.zcml	2005-02-08 20:14:41 UTC (rev 29086)
+++ Zope3/trunk/securitypolicy-ftesting.zcml	2005-02-08 22:37:51 UTC (rev 29087)
@@ -0,0 +1 @@
+<include package="zope.app.securitypolicy.tests" file="functional.zcml" />


Property changes on: Zope3/trunk/securitypolicy-ftesting.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: Zope3/trunk/src/zope/app/securitypolicy/tests/functional.py
===================================================================
--- Zope3/trunk/src/zope/app/securitypolicy/tests/functional.py	2005-02-08 20:14:41 UTC (rev 29086)
+++ Zope3/trunk/src/zope/app/securitypolicy/tests/functional.py	2005-02-08 22:37:51 UTC (rev 29087)
@@ -0,0 +1,38 @@
+##############################################################################
+#
+# Copyright (c) 2004 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.
+#
+##############################################################################
+"""Functional test case support
+
+$Id$
+"""
+
+from zope import interface
+from zope.app.tests import functional
+
+class ManagerSetup:
+    interface.implements(functional.IManagerSetup)
+
+    def setUpManager(self):
+        functional.HTTPCaller()(grant_request, handle_errors=False)
+
+grant_request = (r"""
+POST /@@grant.html HTTP/1.1
+Authorization: Basic Z2xvYmFsbWdyOmdsb2JhbG1ncnB3
+Content-Length: 5796
+Content-Type: application/x-www-form-urlencoded
+
+field.principal=em9wZS5tZ3I_"""
+"""&field.principal.displayed=y"""
+"""&GRANT_SUBMIT=Change"""
+"""&field.em9wZS5tZ3I_.role.zope.Manager=allow"""
+"""&field.em9wZS5tZ3I_.role.zope.Manager-empty-marker=1""")


Property changes on: Zope3/trunk/src/zope/app/securitypolicy/tests/functional.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope3/trunk/src/zope/app/securitypolicy/tests/functional.zcml
===================================================================
--- Zope3/trunk/src/zope/app/securitypolicy/tests/functional.zcml	2005-02-08 20:14:41 UTC (rev 29086)
+++ Zope3/trunk/src/zope/app/securitypolicy/tests/functional.zcml	2005-02-08 22:37:51 UTC (rev 29087)
@@ -0,0 +1,7 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    >
+
+  <utility factory=".functional.ManagerSetup" />
+
+</configure>


Property changes on: Zope3/trunk/src/zope/app/securitypolicy/tests/functional.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: Zope3/trunk/src/zope/app/tests/functional.py
===================================================================
--- Zope3/trunk/src/zope/app/tests/functional.py	2005-02-08 20:14:41 UTC (rev 29086)
+++ Zope3/trunk/src/zope/app/tests/functional.py	2005-02-08 22:37:51 UTC (rev 29087)
@@ -31,7 +31,8 @@
 from transaction import abort, commit
 from ZODB.DB import DB
 from ZODB.DemoStorage import DemoStorage
-import zope.interface
+
+from zope import interface, component
 from zope.publisher.browser import BrowserRequest
 from zope.publisher.http import HTTPRequest
 from zope.publisher.publish import publish
@@ -97,18 +98,19 @@
     return skin or IDefaultBrowserLayer
 
 
-grant_request = (r"""
-POST /@@grant.html HTTP/1.1
-Authorization: Basic Z2xvYmFsbWdyOmdsb2JhbG1ncnB3
-Content-Length: 5796
-Content-Type: application/x-www-form-urlencoded
+class IManagerSetup(interface.Interface):
+    """Utility for enabling up a functional testing manager with needed grants
 
-field.principal=em9wZS5tZ3I_"""
-"""&field.principal.displayed=y"""
-"""&GRANT_SUBMIT=Change"""
-"""&field.em9wZS5tZ3I_.role.zope.Manager=allow"""
-"""&field.em9wZS5tZ3I_.role.zope.Manager-empty-marker=1""")
+    XXX This is an interim solution.  It tries to break the dependence
+    on a particular security policy, however, we need a much better
+    way of managing functional-testing configurations.
+    
+    """
 
+    def setUpManager():
+        """Set up the manager, zope.mgr
+        """
+
 class FunctionalTestSetup(object):
     """Keeps shared state across several functional test cases."""
 
@@ -140,12 +142,10 @@
             self._init = True
 
             # Make a local grant for the test user
-            # TODO, find a better way to make this grant happen.
-            # The way I did this is way too messy, given how
-            # strang FunctionalTestSetup is.  Later, when we
-            # have time, we should clean up this (perhaps with an
-            # event) and clean up FunctionalTestSetup.
-            response = HTTPCaller()(grant_request, handle_errors=False)
+            setup = component.queryUtility(IManagerSetup)
+            if setup is not None:
+                setup.setUpManager()
+            
             FunctionalTestSetup().connection = None
             
         elif config_file and config_file != self._config_file:
@@ -276,7 +276,7 @@
                                environment=environment,
                                basic=basic, form=form,
                                request=BrowserRequest)
-        zope.interface.directlyProvides(request, _getDefaultSkin())
+        interface.directlyProvides(request, _getDefaultSkin())
         return request
 
     def publish(self, path, basic=None, form=None, env={},
@@ -435,7 +435,7 @@
 
 class HTTPHeaderOutput:
 
-    zope.interface.implements(zope.publisher.interfaces.http.IHeaderOutput)
+    interface.implements(zope.publisher.interfaces.http.IHeaderOutput)
 
     def __init__(self, protocol, omit):
         self.headers = {}
@@ -615,7 +615,7 @@
             request=request_cls, publication=publication_cls)
         if request_cls is BrowserRequest:
             # Only browser requests have skins
-            zope.interface.directlyProvides(request, _getDefaultSkin())
+            interface.directlyProvides(request, _getDefaultSkin())
         request.response.setHeaderOutput(header_output)
         response = DocResponseWrapper(
             request.response, outstream, path, header_output)



More information about the Zope3-Checkins mailing list