[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/pas/ Added extractionplugins.py with session extractor, tests.py with sessionSetUp()

Helmut Merz helmutm at cyberconcepts.de
Sun Oct 10 08:26:07 EDT 2004


Log message for revision 27890:
  Added extractionplugins.py with session extractor, tests.py with sessionSetUp()


Changed:
  A   Zope3/trunk/src/zope/app/pas/extractionplugins.py
  U   Zope3/trunk/src/zope/app/pas/tests.py


-=-
Added: Zope3/trunk/src/zope/app/pas/extractionplugins.py
===================================================================
--- Zope3/trunk/src/zope/app/pas/extractionplugins.py	2004-10-10 12:20:43 UTC (rev 27889)
+++ Zope3/trunk/src/zope/app/pas/extractionplugins.py	2004-10-10 12:26:07 UTC (rev 27890)
@@ -0,0 +1,48 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+""" Implementations of standard credentials extractor plugins.
+
+$Id$
+"""
+
+import zope.interface
+from zope.app.session.interfaces import ISession
+from zope.app.pas import interfaces
+
+class SessionExtractor:
+    """ session-based credential extractor
+    """
+    zope.interface.implements(interfaces.IExtractionPlugin)
+
+    def extractCredentials(self, request):
+        """ Extract the credentials that are referenced in the
+            request by looking them up in the session.
+
+            >>> from zope.app.session.session import RAMSessionDataContainer
+            >>> from zope.app.session.session import Session
+            >>> from tests import sessionSetUp
+            >>> request = sessionSetUp(RAMSessionDataContainer)
+            >>> sessionData = Session(request)['pas_credentials']
+            >>> sessionData['username'] = 'scott'
+            >>> sessionData['password'] = 'tiger'
+
+            >>> se = SessionExtractor()
+            >>> se.extractCredentials(request)
+            {'username': 'scott', 'password': 'tiger'}
+        """
+        sessionData = ISession(request)['pas_credentials']
+        return {'username': sessionData['username'],
+                'password': sessionData['password']}
+
+


Property changes on: Zope3/trunk/src/zope/app/pas/extractionplugins.py
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: Zope3/trunk/src/zope/app/pas/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/pas/tests.py	2004-10-10 12:20:43 UTC (rev 27889)
+++ Zope3/trunk/src/zope/app/pas/tests.py	2004-10-10 12:26:07 UTC (rev 27890)
@@ -21,7 +21,29 @@
 from zope.app.tests import placelesssetup, ztapi
 from zope.app.event.tests.placelesssetup import getEvents
 
+from zope.app.session.interfaces import \
+        IClientId, IClientIdManager, ISession, ISessionDataContainer, \
+        ISessionPkgData, ISessionData
+from zope.app.session.session import \
+        ClientId, Session, \
+        PersistentSessionDataContainer, RAMSessionDataContainer
+from zope.app.session.http import CookieClientIdManager
 
+from zope.publisher.interfaces import IRequest
+from zope.publisher.http import HTTPRequest
+
+def sessionSetUp(session_data_container_class=PersistentSessionDataContainer):
+    placelesssetup.setUp()
+    ztapi.provideAdapter(IRequest, IClientId, ClientId)
+    ztapi.provideAdapter(IRequest, ISession, Session)
+    ztapi.provideUtility(IClientIdManager, CookieClientIdManager())
+    sdc = session_data_container_class()
+    for product_id in ('', 'products.foo', 'products.bar', 'products.baz'):
+        ztapi.provideUtility(ISessionDataContainer, sdc, product_id)
+    request = HTTPRequest(None, None, {}, None)
+    return request
+
+
 def test_suite():
     return unittest.TestSuite((
         doctest.DocFileSuite('README.txt',
@@ -29,8 +51,8 @@
                              tearDown=placelesssetup.tearDown,
                              globs={'provideUtility': ztapi.provideUtility,
                                     'getEvents': getEvents,
-                                    },
-                             ),
+                                    }),
+        doctest.DocTestSuite('zope.app.pas.extractionplugins'),
         ))
 
 if __name__ == '__main__':



More information about the Zope3-Checkins mailing list