コード例 #1
0
ファイル: __init__.py プロジェクト: chitopunk/jsonrpc2
def test_unicode_params():
    """
    --> {"jsonrpc": "2.0", "method": "subtract", "params": {"minuend": 42, "subtrahend": 23}, "id": 4}
    
    <-- {"jsonrpc": "2.0", "result": 19, "id": 4}
    """
    app = JsonRpcApplication(dict(greeting=greeting))
    app = TestApp(app)
    data = {
        "jsonrpc": "2.0",
        "method": "greeting",
        "params": {
            u"name": u"あ"
        },
        "id": 4
    }
    res = app.post('/',
                   params=json.dumps(data),
                   extra_environ={'CONTENT_TYPE': 'application/json'})
    assert res.status_int == 200
    print res.body
    data = res.json
    assert data['jsonrpc'] == '2.0'
    assert data['result'] == u"Hello, あ!"
    assert data['id'] == 4
コード例 #2
0
ファイル: test_rpc.py プロジェクト: aodag/jsonrpc2
def test_lazy_loading1():
    app = JsonRpcApplication(rpcs={"greeting":"tests.sample:greeting"})
    app = TestApp(app)
    data = {"jsonrpc": "2.0", "method": "greeting", "params": {"n":"あ"}, "id": 4}
    res = app.post('/', params=json.dumps(data),
                   extra_environ={'CONTENT_TYPE':'application/json'})
    assert res.status_int == 200
    d = res.json
    assert d.get('error') is None
    assert d['result'] == 'Hello, あ'
コード例 #3
0
ファイル: test_rpc.py プロジェクト: aodag/jsonrpc2
def test_add_module():
    app = JsonRpcApplication()
    from . import sample
    app.rpc.addModule(sample)
    assert len(app.rpc.methods) == 2

    app = TestApp(app)
    data = {"jsonrpc": "2.0", "method": "tests.sample.greeting", "params": {"n":"あ"}, "id": 4}
    res = app.post('/', params=json.dumps(data),
                   extra_environ={'CONTENT_TYPE':'application/json'})
    assert res.status_int == 200
    d = res.json
    assert d.get('error') is None
    assert d['result'] == 'Hello, あ'

    data = {"jsonrpc": "2.0", "method": "tests.sample.add", "params": [1, 2], "id": 4}
    res = app.post('/', params=json.dumps(data),
                   extra_environ={'CONTENT_TYPE':'application/json'})
    assert res.status_int == 200
    d = res.json
    assert d.get('error') is None
    assert d.get('result') == 3
コード例 #4
0
ファイル: __init__.py プロジェクト: chitopunk/jsonrpc2
def test_add_module():
    app = JsonRpcApplication()
    import sample
    app.rpc.addModule(sample)
    print app.rpc.methods
    assert len(app.rpc.methods) == 2

    app = TestApp(app)
    data = {
        "jsonrpc": "2.0",
        "method": "tests.sample.greeting",
        "params": {
            u"n": u"あ"
        },
        "id": 4
    }
    res = app.post('/',
                   params=json.dumps(data),
                   extra_environ={'CONTENT_TYPE': 'application/json'})
    assert res.status_int == 200
    d = res.json
    assert d.get('error') is None
    print d['result'].encode('cp932')
    assert d['result'] == u'Hello, あ'

    data = {
        "jsonrpc": "2.0",
        "method": "tests.sample.add",
        "params": [1, 2],
        "id": 4
    }
    res = app.post('/',
                   params=json.dumps(data),
                   extra_environ={'CONTENT_TYPE': 'application/json'})
    assert res.status_int == 200
    d = res.json
    assert d.get('error') is None
    assert d.get('result') == 3
コード例 #5
0
ファイル: test_rpc.py プロジェクト: aodag/jsonrpc2
def test_unicode_params():
    """
    --> {"jsonrpc": "2.0", "method": "subtract", "params": {"minuend": 42, "subtrahend": 23}, "id": 4}
    
    <-- {"jsonrpc": "2.0", "result": 19, "id": 4}
    """
    app = JsonRpcApplication(dict(greeting=greeting))
    app = TestApp(app)
    data = {"jsonrpc": "2.0", "method": "greeting", "params": {"name":"あ"}, "id": 4}
    res = app.post('/', params=json.dumps(data),
                   extra_environ={'CONTENT_TYPE':'application/json'})
    assert res.status_int == 200
    data = res.json
    assert data['jsonrpc'] == '2.0'
    assert data['result'] == "Hello, あ!"
    assert data['id'] == 4
コード例 #6
0
ファイル: __init__.py プロジェクト: chitopunk/jsonrpc2
def test_lazy_loading1():
    app = JsonRpcApplication(rpcs={"greeting": "tests.sample:greeting"})
    app = TestApp(app)
    data = {
        "jsonrpc": "2.0",
        "method": "greeting",
        "params": {
            u"n": u"あ"
        },
        "id": 4
    }
    res = app.post('/',
                   params=json.dumps(data),
                   extra_environ={'CONTENT_TYPE': 'application/json'})
    assert res.status_int == 200
    d = res.json
    assert d.get('error') is None
    assert d['result'] == u'Hello, あ'