app.browser and session problem

55 views
Skip to first unread message

Andrey Kuzmin

unread,
Sep 20, 2012, 9:47:37 AM9/20/12
to we...@googlegroups.com
Hi, I want to use app.browser to test my web.py app.

The problem is that session is not kept between requests.

I checked web.cookies() and they are empty.

How to make app.browser set and retrieve cookies from webpy app?

Tomas Schertel

unread,
Sep 20, 2012, 11:59:58 AM9/20/12
to we...@googlegroups.com
How about this become a feature request?
It would be nice to use web.py components to test web.py applications :)

Andrey Kuzmin

unread,
Sep 20, 2012, 12:11:08 PM9/20/12
to we...@googlegroups.com
I tried to narrow down the case, and it appears something is wrong with my app, because this works:

import web
web.config.debug = False

urls = '/', 'SetValue', '/getvalue', 'GetValue'

app = web.application(urls, globals())
store = web.session.DiskStore('sessions')
session = web.session.Session(app, store)

class SetValue:
    def GET(self):
        web.setcookie("param", "some-kind-of-cookie-value")
        session.param = "some-kind-of-session-value"
        raise web.seeother("/getvalue")
        
class GetValue:
    def GET(self):
        return "Got cookie value: " + web.cookies().param + "\n" + \
            "And session value: " + session.param

if __name__ == "__main__":
    b = app.browser()
    b.open("/")
    assert b.path == "/getvalue"
    assert "some-kind-of-cookie-value" in b.get_text()
    assert "some-kind-of-session-value" in b.get_text()

Andrey Kuzmin

unread,
Sep 20, 2012, 12:36:36 PM9/20/12
to we...@googlegroups.com
Ok, I found the problem was in web.config.session_parameters.cookie_domain, it should be empty to be used in tests.
Reply all
Reply to author
Forward
0 new messages