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

/tests/web/test_jsonrpc.py

https://bitbucket.org/prologic/circuits/
Python | 39 lines | 24 code | 14 blank | 1 comment | 0 complexity | 0c338b57f78a956726e555f87af641c6 MD5 | raw file
 1#!/usr/bin/env python
 2
 3from circuits import Component
 4from circuits.web import Controller, JSONRPC
 5
 6from .jsonrpclib import ServerProxy
 7from .helpers import urlopen
 8
 9
10class App(Component):
11
12    def eval(self, s):
13        return eval(s)
14
15
16class Root(Controller):
17
18    def index(self):
19        return "Hello World!"
20
21
22def test(webapp):
23    rpc = JSONRPC("/rpc")
24    test = App()
25    rpc.register(webapp)
26    test.register(webapp)
27
28    f = urlopen(webapp.server.http.base)
29    s = f.read()
30    assert s == b"Hello World!"
31
32    url = "%s/rpc" % webapp.server.http.base
33    jsonrpc = ServerProxy(url, allow_none=True, encoding='utf-8')
34
35    data = jsonrpc.eval("1 + 2")
36    assert data["result"] == 3
37
38    rpc.unregister()
39    test.unregister()