[Zope-Checkins] SVN: Products.Five/trunk/test Commit patch and test to make testbrowser not swallow cookies. Contributed by Daniel Nouri and modified by me

Brian Sutherland jinty at web.de
Wed May 3 15:49:06 EDT 2006


Log message for revision 67936:
  Commit patch and test to make testbrowser not swallow cookies. Contributed by Daniel Nouri and modified by me

Changed:
  U   Products.Five/trunk/testbrowser.py
  A   Products.Five/trunk/tests/test_testbrowser.py

-=-
Modified: Products.Five/trunk/testbrowser.py
===================================================================
--- Products.Five/trunk/testbrowser.py	2006-05-03 15:37:44 UTC (rev 67935)
+++ Products.Five/trunk/testbrowser.py	2006-05-03 19:49:06 UTC (rev 67936)
@@ -30,8 +30,10 @@
         real_response = self.response._response
         status = real_response.getStatus()
         reason = zope.publisher.http.status_reasons[real_response.status]
-
         headers = real_response.headers.items()
+        # get the cookies, breaking them into tuples for sorting
+        cookies = [(c[:10], c[12:]) for c in real_response._cookie_list()]
+        headers.extend(cookies)
         headers.sort()
         headers.insert(0, ('Status', "%s %s" % (status, reason)))
         headers = '\r\n'.join('%s: %s' % h for h in headers)

Added: Products.Five/trunk/tests/test_testbrowser.py
===================================================================
--- Products.Five/trunk/tests/test_testbrowser.py	2006-05-03 15:37:44 UTC (rev 67935)
+++ Products.Five/trunk/tests/test_testbrowser.py	2006-05-03 19:49:06 UTC (rev 67936)
@@ -0,0 +1,60 @@
+##############################################################################
+#
+# Copyright (c) 2004, 2005 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.
+#
+##############################################################################
+"""Unit tests for the testbrowser module.
+
+$Id$
+"""
+
+import unittest
+from Testing.ZopeTestCase import FunctionalDocTestSuite
+from OFS.SimpleItem import Item
+
+class CookieStub(Item):
+    """This is a cookie stub."""
+
+    def __call__(self, REQUEST):
+        REQUEST.RESPONSE.setCookie('evil', 'cookie')
+        return 'Stub'
+
+def doctest_cookies():
+    """
+    We want to make sure that our testbrowser correctly understands
+    cookies.  We'll add a stub to ``self.folder`` that sets a cookie.
+
+        >>> from Products.Five.tests.test_testbrowser import CookieStub
+        >>> self.folder._setObject('stub', CookieStub())
+        'stub'
+
+    This response looks alright:
+
+        >>> response = self.publish('/test_folder_1_/stub')
+        >>> print str(response) #doctest: +ELLIPSIS
+        Status: 200 OK
+        ...
+        Set-Cookie: evil="cookie"
+        ...
+
+    Let's try to look at the same folder with testbrowser:
+
+        >>> from Products.Five.testbrowser import Browser
+        >>> browser = Browser()
+        >>> browser.open('http://localhost/test_folder_1_/stub')
+        >>> 'Set-Cookie: evil="cookie"' in str(browser.headers)
+        True
+    """
+
+def test_suite():
+    return unittest.TestSuite((
+            FunctionalDocTestSuite(),
+            ))


Property changes on: Products.Five/trunk/tests/test_testbrowser.py
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Zope-Checkins mailing list