[Product-Developers] zope.testbrowser, redirecting and cookies

Bert Vanderbauwhede batlock666 at gmail.com
Thu Feb 4 12:32:19 UTC 2010


Hi,

I've developed a BrowserView that does 2 things:

   1. it sets a cookie
   2. it redirects the browser back to the previous page

Everything works without problems when I test it in a browser. But now I
want to write doctests for it.
I simulate a browser-session with zope.testbrowser, and go to my view. I get
a "HTTP Error 302" back
(as expected), and the headers also seem fine (ie. there is a Set-Cookie
header):

Go to my view::

    >>> link = browser.getLink("My view")
    >>> link.click()  # doctest: +ELLIPSIS
    Traceback (most recent call last):
    ...
    HTTPError: HTTP Error 302: Moved Temporarily

Check the headers::

    >>> for header in browser.headers.headers:
    ...     print header.replace("\x00", "")
    Status: 302 Moved Temporarily
    Content-Length: 0
    Location: http://nohost/plone
    Set-Cookie: my_cookie="hello"; Path=/

But here the test-browser just stops. I don't get redirected to the previous
page, and
the cookie isn't actually set. The mechanize-part seems to work, the
HTTPRedirectHandler
is called, but I don't seem to get the results back. Is there something I'm
doing wrong?


--
Bert Vanderbauwhede
--
"I don't know if you noticed or not, but I'm an extremely arrogant man, who
thinks all his plans will work."
Rodney McKay, Stargate Atlantis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.plone.org/pipermail/plone-product-developers/attachments/20100204/466d6aa7/attachment.html>


More information about the Product-Developers mailing list