jsonrpc: Make dict returns from plain objects work

This commit is contained in:
Stein Magnus Jodal 2012-11-22 12:11:22 +01:00
parent b038c4c2db
commit 6e2ffb0820
2 changed files with 23 additions and 1 deletions

View File

@ -3,6 +3,8 @@ from __future__ import unicode_literals
import json
import traceback
import pykka
class JsonRpcWrapper(object):
"""
@ -167,7 +169,7 @@ class JsonRpcWrapper(object):
return 'id' not in request
def _is_future(self, result):
return callable(getattr(result, 'get', None))
return isinstance(result, pykka.Future)
class JsonRpcError(Exception):

View File

@ -22,6 +22,12 @@ class Calculator(object):
def sub(self, a, b):
return a - b
def describe(self):
return {
'add': 'Returns the sum of the terms',
'sub': 'Returns the diff of the terms',
}
def _secret(self):
return 'Grand Unified Theory'
@ -118,6 +124,20 @@ class JsonRpcSingleCommandTest(JsonRpcTestBase):
self.assertNotIn('error', response)
self.assertEqual(response['result'], 'TI83')
def test_call_method_which_returns_dict_from_plain_object(self):
request = {
'jsonrpc': '2.0',
'method': 'calculator.describe',
'id': 1,
}
response = self.jrw.handle_data(request)
self.assertEqual(response['jsonrpc'], '2.0')
self.assertEqual(response['id'], 1)
self.assertNotIn('error', response)
self.assertIn('add', response['result'])
self.assertIn('sub', response['result'])
def test_call_method_on_actor_root(self):
request = {
'jsonrpc': '2.0',