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

/tests/web/test_cookies.py

https://bitbucket.org/prologic/circuits/
Python | 29 lines | 20 code | 8 blank | 1 comment | 2 complexity | f7deb028dfef297a9fce907e25499120 MD5 | raw file
 1#!/usr/bin/env python
 2
 3from circuits.web import Controller
 4
 5from .helpers import build_opener, HTTPCookieProcessor
 6from .helpers import CookieJar
 7
 8
 9class Root(Controller):
10    def index(self):
11        visited = self.cookie.get("visited")
12        if visited and visited.value:
13            return "Hello again!"
14        else:
15            self.cookie["visited"] = True
16            return "Hello World!"
17
18
19def test(webapp):
20    cj = CookieJar()
21    opener = build_opener(HTTPCookieProcessor(cj))
22
23    f = opener.open(webapp.server.http.base)
24    s = f.read()
25    assert s == b"Hello World!"
26
27    f = opener.open(webapp.server.http.base)
28    s = f.read()
29    assert s == b"Hello again!"