[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/pas/ Cleaned up tests for session extractor

Helmut Merz helmutm at cy55.de
Wed Oct 13 11:17:14 EDT 2004


Log message for revision 28099:
  Cleaned up tests for session extractor

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

-=-
Modified: Zope3/trunk/src/zope/app/pas/browserplugins.py
===================================================================
--- Zope3/trunk/src/zope/app/pas/browserplugins.py	2004-10-13 15:09:45 UTC (rev 28098)
+++ Zope3/trunk/src/zope/app/pas/browserplugins.py	2004-10-13 15:17:12 UTC (rev 28099)
@@ -24,8 +24,9 @@
 from zope.app.container.contained import Contained
 from zope.app.traversing.browser.absoluteurl import absoluteURL
 from zope.app import zapi
-from zope.app.session.interfaces import ISession
+from zope.app.session.interfaces import ISession, IClientId
 import transaction 
+import transaction 
 from urllib import urlencode
 
 from zope.app.pas.interfaces import IExtractionPlugin, IChallengePlugin
@@ -67,7 +68,9 @@
 
     def getPassword(self): return self.password
 
+    def __str__(self): return self.getLogin() + ':' + self.getPassword()
 
+
 class SessionExtractor(Persistent, Contained):
     """ session-based credential extractor.
 
@@ -76,34 +79,35 @@
 
         >>> from zope.app.session.session import RAMSessionDataContainer
         >>> from zope.app.session.session import Session
-        >>> from tests import sessionSetUp, createTestRequest
+        >>> from tests import sessionSetUp, TestRequest
 
         >>> sessionSetUp(RAMSessionDataContainer)
         >>> se = SessionExtractor()
 
-        No credentials available:
-        >>> request = createTestRequest()
+
+        Start: No credentials available
+        >>> request = TestRequest()
         >>> se.extractCredentials(request) is None
         True
 
+        Credentials provided by submitting login form:
         If the session does not contain the credentials check
-        the request for form variables.
-        >>> request = createTestRequest(login='scott', password='tiger')
+        the request for form variables and store the credentials in
+        the session.
+        >>> request = TestRequest(login='scott', password='tiger')
         >>> se.extractCredentials(request)
         {'login': 'scott', 'password': 'tiger'}
 
-        If there are credentials present use them.
-        >>> request = createTestRequest()
-        >>> sessionData = Session(request)['pas']
-        >>> sessionData['credentials'] = SessionCredentials('scott', 'tiger')
+        After login the credentials are stored in the session.
+        (The sessionSetUp() method ensures that in this test the request
+        always gets the same client id so we get the same session data.)
+        >>> request = TestRequest()
         >>> se.extractCredentials(request)
         {'login': 'scott', 'password': 'tiger'}
 
         Magic logout command in URL forces log out by deleting the
         credentials from the session.
-        >>> request = createTestRequest(authrequest='logout')
-        >>> sessionData = Session(request)['pas']
-        >>> sessionData['credentials'] = SessionCredentials('scott', 'tiger')
+        >>> request = TestRequest(authrequest='logout')
         >>> se.extractCredentials(request) is None
         True
         >>> Session(request)['pas']['credentials'] is None

Modified: Zope3/trunk/src/zope/app/pas/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/pas/tests.py	2004-10-13 15:09:45 UTC (rev 28098)
+++ Zope3/trunk/src/zope/app/pas/tests.py	2004-10-13 15:17:12 UTC (rev 28099)
@@ -21,6 +21,8 @@
 from zope.app.tests import placelesssetup, ztapi
 from zope.app.event.tests.placelesssetup import getEvents
 from zope.app.tests.setup import placefulSetUp, placefulTearDown
+from zope.interface import implements
+from zope.app.zapi import getUtility
 
 from zope.app.session.interfaces import \
         IClientId, IClientIdManager, ISession, ISessionDataContainer, \
@@ -33,9 +35,15 @@
 from zope.publisher.interfaces import IRequest
 from zope.publisher.tests.httprequest import TestRequest
 
+class TestClientId(object):
+    implements(IClientId)
+    def __new__(cls, request):
+        #return str.__new__(cls, getUtility(IClientIdManager).getClientId(request))
+        return 'dummyclientidfortesting'
+
 def sessionSetUp(session_data_container_class=PersistentSessionDataContainer):
     placelesssetup.setUp()
-    ztapi.provideAdapter(IRequest, IClientId, ClientId)
+    ztapi.provideAdapter(IRequest, IClientId, TestClientId)
     ztapi.provideAdapter(IRequest, ISession, Session)
     ztapi.provideUtility(IClientIdManager, CookieClientIdManager())
     sdc = session_data_container_class()
@@ -47,9 +55,6 @@
 def formAuthTearDown(self):
     placefulTearDown()
 
-def createTestRequest(**kw):
-    return TestRequest(**kw)
-
 def test_suite():
     return unittest.TestSuite((
         doctest.DocTestSuite('zope.app.pas.generic'),



More information about the Zope3-Checkins mailing list