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

/tests/web/test_encodings.py

https://bitbucket.org/prologic/circuits/
Python | 39 lines | 27 code | 12 blank | 0 comment | 0 complexity | 04e7e4342156cc9e8d103a53f816ad21 MD5 | raw file
 1from circuits.web import Controller
 2
 3from .helpers import urlencode, urlopen, HTTPError
 4
 5class Root(Controller):
 6
 7    def index(self):
 8        return "Hello World!".encode('utf-16be')
 9
10    def foo(self):
11        return b"Hello World!".decode()
12
13
14def test_utf_16_manual(webapp):
15    f = urlopen(webapp.server.base)
16    s = f.read()
17    assert s == "Hello World!".encode('utf-16be')
18
19
20def test_utf_16_server():
21    from circuits import Component
22
23    class WebApp(Component):
24        def __init__(self):
25            super(WebApp, self).__init__()
26            from circuits.web import Server
27            self.server = Server(0, encoding='utf-16be').register(self)
28
29    webapp = WebApp()
30    Root().register(webapp)
31
32    webapp.start()
33
34    try:
35        f = urlopen("%s/foo" % webapp.server.base)
36        s = f.read()
37        assert s == "Hello World!".encode('utf-16be')
38    finally:
39        webapp.stop()