[Checkins] SVN: zope.app.testing/branches/matt-fix-cookie-leak/src/zope/app/testing/ Added tests to insure cookies don't leak across a doctest suite.

matt@zope.com cvs-admin at zope.org
Fri Oct 10 13:38:55 EDT 2008


Log message for revision 92012:
  Added tests to insure cookies don't leak across a doctest suite.
  

Changed:
  U   zope.app.testing/branches/matt-fix-cookie-leak/src/zope/app/testing/doctest.txt
  A   zope.app.testing/branches/matt-fix-cookie-leak/src/zope/app/testing/doctest2.txt
  U   zope.app.testing/branches/matt-fix-cookie-leak/src/zope/app/testing/functional.py

-=-
Modified: zope.app.testing/branches/matt-fix-cookie-leak/src/zope/app/testing/doctest.txt
===================================================================
--- zope.app.testing/branches/matt-fix-cookie-leak/src/zope/app/testing/doctest.txt	2008-10-10 17:38:34 UTC (rev 92011)
+++ zope.app.testing/branches/matt-fix-cookie-leak/src/zope/app/testing/doctest.txt	2008-10-10 17:38:54 UTC (rev 92012)
@@ -143,3 +143,49 @@
 
   >>> list(root.keys())
   [u'f1']
+
+Now we will run tests to ensure that cookies are not saved across doctests.
+
+  >>> from zope.app.testing import functional
+  >>> from zope.app.testing.tests import DummyCookiesResponse
+
+
+We will create some cookie values and saved them in our 'http' value, which
+is a CookieHandler() object.
+
+  >>> response = DummyCookiesResponse(dict(
+  ...     green=dict(value='grass', path='/foo', comment='rest is ignored'),
+  ...     red=dict(value='keychain')))
+
+If 'http' is created as a global variable, then every doctest in this
+suite will be saving cookies in it, and one doctest may see cookies for
+another doctest. We only want two cookies in 'http' - the ones we just
+created.
+
+  >>> http.saveCookies(response)
+  >>> len(http.cookies)
+  2
+
+  >>> http.cookies['green'].OutputString()
+  'green=grass; Path=/foo;'
+
+  >>> http.cookies
+  <SimpleCookie: green='grass' red='keychain'>
+
+  >>> http.cookies['green'] = 'grass'
+  >>> http.cookies['green']['path'] = '/foo'
+  >>> http.cookies['blue'] = 'cottage'
+  >>> http.cookies['blue']['path'] = '/foo/baz'
+  >>> http.cookies['red'] = 'keychain'
+
+  >>> cookieHeader = http.httpCookie('/foo/bar')
+  >>> parts = cookieHeader.split('; ')
+  >>> parts.sort()
+  >>> parts
+  ['green=grass', 'red=keychain']
+
+  >>> cookieHeader = http.httpCookie('/foo/baz')
+  >>> parts = cookieHeader.split('; ')
+  >>> parts.sort()
+  >>> parts
+  ['blue=cottage', 'green=grass', 'red=keychain']

Added: zope.app.testing/branches/matt-fix-cookie-leak/src/zope/app/testing/doctest2.txt
===================================================================
--- zope.app.testing/branches/matt-fix-cookie-leak/src/zope/app/testing/doctest2.txt	                        (rev 0)
+++ zope.app.testing/branches/matt-fix-cookie-leak/src/zope/app/testing/doctest2.txt	2008-10-10 17:38:54 UTC (rev 92012)
@@ -0,0 +1,48 @@
+========================
+DocTest Functional Tests
+========================
+
+This file documents and tests doctest-based functional tests and basic
+Zope web-application functionality.
+
+This second DocTest, zope/app/testing/doctest2.txt, has specifically
+been created in order to make sure cookie information is not being saved
+across a test suite. If we are saving these via a global 'http' instance,
+we will see more results than those listed below. 'http' is instead
+created in setUp within _prepare_doctest_keywords, rather than in the
+global declarations.
+
+  >>> from zope.app.testing import functional
+  >>> from zope.app.testing.tests import DummyCookiesResponse
+
+  >>> response = DummyCookiesResponse(dict(
+  ...     cobalt=dict(value='ocean', path='/foo', comment='rest is ignored'),
+  ...     crimson=dict(value='campfire')))
+
+  >>> http.saveCookies(response)
+  >>> len(http.cookies)
+  2
+        
+  >>> http.cookies['cobalt'].OutputString()
+  'cobalt=ocean; Path=/foo;'
+
+  >>> http.cookies
+  <SimpleCookie: cobalt='ocean' crimson='campfire'>
+
+  >>> http.cookies['cobalt'] = 'ocean'
+  >>> http.cookies['cobalt']['path'] = '/foo'
+  >>> http.cookies['amber'] = 'coast'
+  >>> http.cookies['amber']['path'] = '/foo/baz'
+  >>> http.cookies['crimson'] = 'campfire'
+
+  >>> cookieHeader = http.httpCookie('/foo/bar')
+  >>> parts = cookieHeader.split('; ')
+  >>> parts.sort()
+  >>> parts
+  ['cobalt=ocean', 'crimson=campfire']
+
+  >>> cookieHeader = http.httpCookie('/foo/baz')
+  >>> parts = cookieHeader.split('; ')
+  >>> parts.sort()
+  >>> parts
+  ['amber=coast', 'cobalt=ocean', 'crimson=campfire']

Modified: zope.app.testing/branches/matt-fix-cookie-leak/src/zope/app/testing/functional.py
===================================================================
--- zope.app.testing/branches/matt-fix-cookie-leak/src/zope/app/testing/functional.py	2008-10-10 17:38:34 UTC (rev 92011)
+++ zope.app.testing/branches/matt-fix-cookie-leak/src/zope/app/testing/functional.py	2008-10-10 17:38:54 UTC (rev 92012)
@@ -780,8 +780,8 @@
 
 def _prepare_doctest_keywords(kw):
     globs = kw.setdefault('globs', {})
+    globs['getRootFolder'] = getRootFolder
     # globs['http'] = HTTPCaller()
-    globs['getRootFolder'] = getRootFolder
     globs['sync'] = sync
 
     kwsetUp = kw.get('setUp')



More information about the Checkins mailing list