PageRenderTime 20ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/web/test_sessions.py

https://bitbucket.org/prologic/circuits/
Python | 37 lines | 24 code | 12 blank | 1 comment | 1 complexity | a108c4e90a84ad218d055a8dadc90f1b MD5 | raw file
 1#!/usr/bin/env python
 2
 3from circuits.web import Controller, Sessions
 4
 5from .helpers import build_opener, HTTPCookieProcessor
 6from .helpers import CookieJar
 7
 8
 9class Root(Controller):
10
11    def index(self, vpath=None):
12        if vpath:
13            name = vpath
14            self.session["name"] = name
15        else:
16            name = self.session.get("name", "World!")
17
18        return "Hello %s" % name
19
20
21def test(webapp):
22    Sessions().register(webapp)
23
24    cj = CookieJar()
25    opener = build_opener(HTTPCookieProcessor(cj))
26
27    f = opener.open(webapp.server.http.base)
28    s = f.read()
29    assert s == b"Hello World!"
30
31    f = opener.open(webapp.server.http.base + "/test")
32    s = f.read()
33    assert s == b"Hello test"
34
35    f = opener.open(webapp.server.http.base)
36    s = f.read()
37    assert s == b"Hello test"