[Zope3-checkins] CVS: Zope3/src/zope/app/utilities/tests - test_session.py:1.1.2.2

Stuart Bishop zen at shangri-la.dropbear.id.au
Sun Feb 8 22:09:34 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/utilities/tests
In directory cvs.zope.org:/tmp/cvs-serv27663/src/zope/app/utilities/tests

Modified Files:
      Tag: ozzope-session-branch
	test_session.py 
Log Message:
Work in progress - API solidifying


=== Zope3/src/zope/app/utilities/tests/test_session.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/app/utilities/tests/test_session.py:1.1.2.1	Sat Feb  7 22:19:04 2004
+++ Zope3/src/zope/app/utilities/tests/test_session.py	Sun Feb  8 22:09:00 2004
@@ -1,7 +1,7 @@
 # -*- coding: ascii -*-
 ##############################################################################
 #
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# Copyright (c) 2004 Zope Corporation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -16,16 +16,21 @@
 $Id$
 '''
 
-__rcs_id__  = '$Id$'
-__version__ = '$Revision$'[11:-2]
-
 import unittest, doctest
+from zope.app import zapi
 from zope.app.tests import placelesssetup
 from zope.app.tests import ztapi
+from zope.app.tests import setup
+
+from zope.app.interfaces.utilities.session import \
+        IBrowserId, IBrowserIdManager, ISession, ISessionDataContainer, \
+        BrowserIdManager
+
+from zope.app.utilities.session import \
+        CookieBrowserIdManager, Session, getSession, \
+        PersistentSessionDataContainer
 
-from zope.app.interfaces.utilities.session import IBrowserId, IBrowserIdManager
-from zope.app.utilities.session import CookieBrowserIdManager
-from zope.app.utilities.session import getBrowserId
+from zope.publisher.interfaces.http import IHTTPRequest
 from zope.publisher.http import HTTPRequest
 
 def test_CookieBrowserIdManager():
@@ -91,20 +96,126 @@
 
     """
 
-def test_getBrowserId():
+def test_PersistentSessionIdContainer():
+    """
+    >>> sdc = PersistentSessionDataContainer()
+    >>> sdc['a']
+    Traceback (most recent call last):
+    File "<stdin>", line 1, in ?
+    File "/usr/python-2.3.3/lib/python2.3/UserDict.py", line 19, in __getitem__
+        def __getitem__(self, key): return self.data[key]
+    KeyError: 'a'
+    >>> from zodb.btrees.OOBTree import OOBTree
+    >>> sdc['a'] = OOBTree()
+    >>> pdict = OOBTree()
+    >>> sdc['a'] = pdict
+    >>> id(pdict) == id(sdc['a'])
+    True
+    >>> del sdc['a']
+    >>> sdc['a']
+    Traceback (most recent call last):
+    File "<stdin>", line 1, in ?
+    File "/usr/python-2.3.3/lib/python2.3/UserDict.py", line 19, in __getitem__
+        def __getitem__(self, key): return self.data[key]
+    KeyError: 'a'
+    >>> del sdc['a']
+    Traceback (most recent call last):
+    File "<stdin>", line 1, in ?
+    File "/usr/python-2.3.3/lib/python2.3/UserDict.py", line 21, in __delitem__
+        def __delitem__(self, key): del self.data[key]
+    KeyError: 'a'
+    """
+
+def test_Session():
     """
-    >>> placelesssetup.setUp()
-    >>> ztapi.provideUtility(IBrowserIdManager, CookieBrowserIdManager())
+    >>> data_container = PersistentSessionDataContainer()
+    >>> session = Session(data_container, 'browser id', 'zopeproducts.foo')
+    >>> session['color']
+    Traceback (most recent call last):
+    File "<stdin>", line 1, in ?
+    File "zope/app/utilities/session.py", line 157, in __getitem__
+        return self._data[key]
+    KeyError: 'color'
+    >>> session['color'] = 'red'
+    >>> session['color']
+    'red'
+
+    And make sure no namespace conflicts...
+
+    >>> session2 = Session(data_container, 'browser id', 'zopeproducts.bar')
+    >>> session2['color'] = 'blue'
+    >>> session['color']
+    'red'
+    >>> session2['color']
+    'blue'
+
+    Test the rest of the dictionary interface...
+
+    >>> 'foo' in session
+    False
+    >>> 'color' in session
+    True
+    >>> session.get('size', 'missing')
+    'missing'
+    >>> session.get('color', 'missing')
+    'red'
+    >>> list(session.keys())
+    ['color']
+    >>> list(session.values())
+    ['red']
+    >>> list(session.items())
+    [('color', 'red')]
+    >>> len(session)
+    1
+    >>> [x for x in session]
+    ['color']
+    >>> del session['color']
+    >>> session.get('color', 'missing')
+    'missing'
+    """
+
+
+def test_localutilities():
+    """
+    Setup a placeful environment with a IBrowserIdManager
+    and ISessionDataContainer
+
+    >>> root = setup.placefulSetUp(site=True)
+    >>> setup.createStandardServices(root)
+    >>> sm = setup.createServiceManager(root)
+    >>> bim = setup.addUtility(
+    ...     sm, BrowserIdManager, IBrowserIdManager, CookieBrowserIdManager())
+    >>> pdc = PersistentSessionDataContainer()
+    >>> sdc = setup.addUtility(sm, 'persistent', ISessionDataContainer, pdc)
+    >>> sdc = setup.addUtility(sm, 'products.foo',ISessionDataContainer, pdc)
+    >>> sdc = setup.addUtility(sm, 'products.bar', ISessionDataContainer, pdc)
     >>> request = HTTPRequest(None, None, {}, None)
-    >>> id1 = getBrowserId(request)
-    >>> id2 = getBrowserId(request)
-    >>> id1 == id2
-    True
-    >>> IBrowserId.isImplementedBy(id1)
+   
+    Make sure we can access utilities
+
+    >>> sdc = zapi.getUtility(root, ISessionDataContainer, 'persistent')
+    >>> bim = zapi.getUtility(root, IBrowserIdManager, BrowserIdManager)
+
+    Make sure getSession works
+
+    >>> session1 = getSession(root, request, 'products.foo')
+    >>> session2 = getSession(root, request, 'products.bar')
+
+    Make sure it returned sane values
+
+    >>> ISession.isImplementedBy(session1)
     True
-    >>> IBrowserId.isImplementedBy(id2)
+    >>> ISession.isImplementedBy(session2)
     True
-    >>> placelesssetup.tearDown()
+
+    Make sure that product_ids don't share a namespace
+
+    >>> session1['color'] = 'red'
+    >>> session2['color'] = 'blue'
+    >>> session1['color']
+    'red'
+    >>> session2['color']
+    'blue'
     """
 
 def test_suite():




More information about the Zope3-Checkins mailing list