Permalink
Browse files

Fixed Browser cookies retrievial with Zope 2.13.

svn path=/plone.testing/trunk/; revision=48061
  • Loading branch information...
1 parent a5f5fd2 commit 280a73eb8d96de4234528f135933e907f1014d97 @vincentfretin vincentfretin committed Mar 13, 2011
Showing with 15 additions and 1 deletion.
  1. +3 −0 CHANGES.txt
  2. +12 −1 src/plone/testing/_z2_testbrowser.py
View
@@ -4,6 +4,9 @@ Changelog
4.0a6 (Unreleased)
------------------
+- Fixed Browser cookies retrievial with Zope 2.13.
+ [vincentfretin]
+
- Add ``ZCMLSandbox`` layer to load a ZCML file; replaces ``setUpZcmlFiles`` and
``tearDownZcmlFiles`` helper functions.
[gotcha]
@@ -8,10 +8,21 @@
from cStringIO import StringIO
import mechanize
+import pkg_resources
import zope.testbrowser.testing
import zope.testbrowser.browser
+
+try:
+ pkg_resources.get_distribution('Zope2>=2.13')
+ def get_cookies(request):
+ return request.response._cookie_list()
+except (pkg_resources.VersionConflict, pkg_resources.DistributionNotFound):
+ def get_cookies(request):
+ return [(c[:10], c[12:]) for c in request.response._cookie_list()]
+
+
class Browser(zope.testbrowser.browser.Browser):
"""A test browser client that uses the Zope 2 publisher. It must be
passed the Zope 2 application root as an argument.
@@ -87,7 +98,7 @@ def getresponse(self):
headers.append((key, val))
# Get the cookies, breaking them into tuples for sorting
- cookies = [(c[:10], c[12:]) for c in self.response._cookie_list()]
+ cookies = get_cookies(self)
headers.extend(cookies)
headers.sort()
headers.insert(0, ('Status', "%s %s" % (status, reason)))

0 comments on commit 280a73e

Please sign in to comment.