[Zope-Checkins] SVN: Products.Five/branches/1.4/ Merge from trunk
and add CHANGES.txt message.
Brian Sutherland
jinty at web.de
Wed May 3 20:56:12 EDT 2006
Log message for revision 67959:
Merge from trunk and add CHANGES.txt message.
------------------------------------------------------------------------
r67957 | jinty | 2006-05-04 02:11:01 +0200 (Thu, 04 May 2006) | 1 line
Five.testbrowser did not do the munging of the headers that the zope2 HTTP response did. It was also inconsistent with Zope3 testbrowser tests. Fix that.
------------------------------------------------------------------------
r67936 | jinty | 2006-05-03 21:49:06 +0200 (Wed, 03 May 2006) | 1 line
Commit patch and test to make testbrowser not swallow cookies. Contributed by Daniel Nouri and modified by me
Changed:
U Products.Five/branches/1.4/CHANGES.txt
U Products.Five/branches/1.4/testbrowser.py
A Products.Five/branches/1.4/tests/test_testbrowser.py
-=-
Modified: Products.Five/branches/1.4/CHANGES.txt
===================================================================
--- Products.Five/branches/1.4/CHANGES.txt 2006-05-04 00:27:31 UTC (rev 67958)
+++ Products.Five/branches/1.4/CHANGES.txt 2006-05-04 00:56:11 UTC (rev 67959)
@@ -2,6 +2,19 @@
Five Changes
============
+Five 1.4 (Unreleased)
+=====================
+
+Bugfixes
+--------
+
+* Five.testbrowser does not swallow cookies anymore, based on patch by
+ Daniel Nouri.
+
+* Five.testbrowser capitalizes headers in the same way as the Zope2
+ HTTPResponse. i.e. content-length -> Content-Length.
+
+
Five 1.4c (2006-05-04)
======================
Modified: Products.Five/branches/1.4/testbrowser.py
===================================================================
--- Products.Five/branches/1.4/testbrowser.py 2006-05-04 00:27:31 UTC (rev 67958)
+++ Products.Five/branches/1.4/testbrowser.py 2006-05-04 00:56:11 UTC (rev 67959)
@@ -30,8 +30,23 @@
real_response = self.response._response
status = real_response.getStatus()
reason = zope.publisher.http.status_reasons[real_response.status]
-
- headers = real_response.headers.items()
+ headers = []
+ # Convert header keys to camel case. This is basically a copy
+ # paste from ZPublisher.HTTPResponse
+ for key, val in real_response.headers.items():
+ if key.lower() == key:
+ # only change non-literal header names
+ key = "%s%s" % (key[:1].upper(), key[1:])
+ start = 0
+ l = key.find('-',start)
+ while l >= start:
+ key = "%s-%s%s" % (key[:l],key[l+1:l+2].upper(),key[l+2:])
+ start = l + 1
+ l = key.find('-', start)
+ headers.append((key, val))
+ # 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)
Copied: Products.Five/branches/1.4/tests/test_testbrowser.py (from rev 67936, Products.Five/trunk/tests/test_testbrowser.py)
===================================================================
--- Products.Five/trunk/tests/test_testbrowser.py 2006-05-03 19:49:06 UTC (rev 67936)
+++ Products.Five/branches/1.4/tests/test_testbrowser.py 2006-05-04 00:56:11 UTC (rev 67959)
@@ -0,0 +1,83 @@
+##############################################################################
+#
+# 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 doctest_camel_case_headers():
+ """Make sure that the headers come out in camel case.
+
+ Some setup:
+
+ >>> from Products.Five.tests.test_testbrowser import CookieStub
+ >>> self.folder._setObject('stub', CookieStub())
+ 'stub'
+
+ The Zope2 response mungs headers so they come out in camel case we should
+ do the same. This is also more consistent with the Zope3 testbrowser tests.
+ We will test a few:
+
+ >>> from Products.Five.testbrowser import Browser
+ >>> browser = Browser()
+ >>> browser.open('http://localhost/test_folder_1_/stub')
+ >>> 'Content-Length: ' in str(browser.headers)
+ True
+ >>> 'Content-Type: ' in str(browser.headers)
+ True
+ """
+
+
+def test_suite():
+ return unittest.TestSuite((
+ FunctionalDocTestSuite(),
+ ))
More information about the Zope-Checkins
mailing list