[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - test_cookiesessionservice.py:1.2

Steve Alexander steve@cat-box.net
Thu, 27 Feb 2003 03:12:04 -0500


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

Modified Files:
	test_cookiesessionservice.py 
Log Message:
Added a method getCookie to IHTTPResponse.
I needed this to fix a bug in sessions, where if you asked for the session
more than once in the same request, it wouldn't realise that it had already
created a session for that request. This was because the sessions code
was only looking in the request for the relevant cookie. It needs to look
in the response and in the request.


=== Zope3/src/zope/app/services/tests/test_cookiesessionservice.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/services/tests/test_cookiesessionservice.py:1.1	Thu Dec 26 14:13:09 2002
+++ Zope3/src/zope/app/services/tests/test_cookiesessionservice.py	Thu Feb 27 03:11:32 2003
@@ -36,20 +36,28 @@
     def deleteData(self, sid):
         del self.data[sid]
 
-
 class FakeRequest:
 
     def __init__(self):
         self.sets = 0
         self.cookies = {}
+        # This class implements methods of the response too.
         self.response = self
 
     def setCookie(self, k, v, **kw):
+        # This is actually a method on the response.
         self.sets += 1
         self.cookies[k] = v
         if (not abs(parse_http_date(kw["expires"]) - int(time.time()) - 1800)
             < 3):
             raise AssertionError
+
+    def getCookie(self, name, default=None):
+        # This is actually a method on the reponse.
+        value = self.cookies.get(name)
+        if value is None:
+            return default
+        return {'value':value}
 
 
 class SessionServiceTestCaseMixin(PlacefulSetup):