jsonrpc: Handle Pykka's CallableProxy objects as regular methods

This commit is contained in:
Stein Magnus Jodal 2013-03-30 21:01:01 +01:00
parent 0c05d7c60e
commit e6460b6945
2 changed files with 23 additions and 1 deletions

View File

@ -181,7 +181,7 @@ class JsonRpcWrapper(object):
data='"params", if given, must be an array or an object')
def _get_method(self, method_path):
if inspect.isroutine(self.objects.get(method_path, None)):
if callable(self.objects.get(method_path, None)):
# The mounted object is the callable
return self.objects[method_path]

View File

@ -48,6 +48,7 @@ class JsonRpcTestBase(unittest.TestCase):
'core': self.core,
'core.playback': self.core.playback,
'core.tracklist': self.core.tracklist,
'get_uri_schemes': self.core.get_uri_schemes,
},
encoders=[models.ModelJSONEncoder],
decoders=[models.model_json_decoder])
@ -188,6 +189,23 @@ class JsonRpcSingleCommandTest(JsonRpcTestBase):
self.assertEqual(response['result'], None)
def test_call_method_which_is_a_directly_mounted_actor_member(self):
# 'get_uri_schemes' isn't a regular callable, but a Pykka
# CallableProxy. This test checks that CallableProxy objects are
# threated by JsonRpcWrapper like any other callable.
request = {
'jsonrpc': '2.0',
'method': 'get_uri_schemes',
'id': 1,
}
response = self.jrw.handle_data(request)
self.assertEqual(response['jsonrpc'], '2.0')
self.assertEqual(response['id'], 1)
self.assertNotIn('error', response)
self.assertEqual(response['result'], ['dummy'])
def test_call_method_with_positional_params(self):
request = {
'jsonrpc': '2.0',
@ -588,6 +606,7 @@ class JsonRpcInspectorTest(JsonRpcTestBase):
def test_inspector_can_describe_a_bunch_of_large_classes(self):
inspector = jsonrpc.JsonRpcInspector({
'core.get_uri_schemes': core.Core.get_uri_schemes,
'core.library': core.LibraryController,
'core.playback': core.PlaybackController,
'core.playlists': core.PlaylistsController,
@ -596,6 +615,9 @@ class JsonRpcInspectorTest(JsonRpcTestBase):
methods = inspector.describe()
self.assertIn('core.get_uri_schemes', methods)
self.assertEquals(len(methods['core.get_uri_schemes']['params']), 0)
self.assertIn('core.library.lookup', methods.keys())
self.assertEquals(
methods['core.library.lookup']['params'][0]['name'], 'uri')