[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/session/ftests.py Decent functional test for the sessions-and-virtualhosts event integration

Martijn Pieters mj at zopatista.com
Wed Aug 2 08:57:48 EDT 2006


Log message for revision 69338:
  Decent functional test for the sessions-and-virtualhosts event integration

Changed:
  U   Zope3/trunk/src/zope/app/session/ftests.py

-=-
Modified: Zope3/trunk/src/zope/app/session/ftests.py
===================================================================
--- Zope3/trunk/src/zope/app/session/ftests.py	2006-08-02 12:35:56 UTC (rev 69337)
+++ Zope3/trunk/src/zope/app/session/ftests.py	2006-08-02 12:57:47 UTC (rev 69338)
@@ -16,9 +16,14 @@
 $Id: tests.py 26427 2004-07-12 16:05:02Z Zen $
 """
 import unittest
+from zope.component import provideHandler, getGlobalSiteManager
+from zope.app.folder import Folder
+from zope.app.publication.interfaces import IBeforeTraverseEvent
 from zope.app.testing.functional import BrowserTestCase
 from zope.app.zptpage.zptpage import ZPTPage
 
+from interfaces import ISession
+
 class ZPTSessionTest(BrowserTestCase):
     content = u'''
         <div tal:define="
@@ -58,10 +63,50 @@
         response3 = self.fetch()
         self.failUnlessEqual(response3, u'3')
 
-
+class VirtualHostSessionTest(BrowserTestCase):
+    def setUp(self):
+        super(VirtualHostSessionTest, self).setUp()
+        page = ZPTPage()
+        page.source = (u'<div '
+                       u'tal:define="session request/session:products.foo"/>')
+        page.evaluateInlineCode = True
+        root = self.getRootFolder()
+        root['folder'] = Folder()
+        root['folder']['page'] = page
+        self.commit()
+        
+        provideHandler(self.accessSessionOnTraverse, (IBeforeTraverseEvent,))
+        
+    def tearDown(self):
+        getGlobalSiteManager().unregisterHandler(self.accessSessionOnTraverse,
+                                                 (IBeforeTraverseEvent,))
+        
+    def accessSessionOnTraverse(self, event):
+        session = ISession(event.request)
+        
+    def assertCookiePath(self, path):
+        cookie = self.cookies.values()[0]
+        self.assertEqual(cookie['path'], path)
+    
+    def testShortendPath(self):
+        self.publish(
+            '/++skin++Rotterdam/folder/++vh++http:localhost:80/++/page')
+        self.assertCookiePath('/')
+        
+    def testLongerPath(self):
+        self.publish(
+            '/folder/++vh++http:localhost:80/foo/bar/++/page')
+        self.assertCookiePath('/foo/bar')
+        
+    def testDifferentHostname(self):
+        self.publish(
+            '/folder/++vh++http:foo.bar:80/++/page')
+        self.assertCookiePath('/')
+        
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(ZPTSessionTest),
+        unittest.makeSuite(VirtualHostSessionTest),
         ))
 
 if __name__ == '__main__':



More information about the Zope3-Checkins mailing list