Merge pull request #363 from jodal/feature/expose-uri-schemes-to-http-clients

Expose uri schemes to http clients
This commit is contained in:
Thomas Adamcik 2013-03-31 03:55:59 -07:00
commit 6283c6ee9b
4 changed files with 28 additions and 1 deletions

View File

@ -73,6 +73,9 @@ v0.13.0 (in development)
- Upgrade Mopidy.js' dependencies when.js from 1.6.1 to 1.8.1.
- Expose :meth:`mopidy.core.Core.get_uri_schemes` to HTTP clients. It is
available through Mopidy.js as ``mopidy.getUriSchemes()``.
**MPRIS frontend**
- Publish album art URIs if available.

View File

@ -20,6 +20,7 @@ class WebSocketResource(object):
self._core = core_proxy
inspector = jsonrpc.JsonRpcInspector(
objects={
'core.get_uri_schemes': core.Core.get_uri_schemes,
'core.library': core.LibraryController,
'core.playback': core.PlaybackController,
'core.playlists': core.PlaylistsController,
@ -28,6 +29,7 @@ class WebSocketResource(object):
self.jsonrpc = jsonrpc.JsonRpcWrapper(
objects={
'core.describe': inspector.describe,
'core.get_uri_schemes': self._core.get_uri_schemes,
'core.library': self._core.library,
'core.playback': self._core.playback,
'core.playlists': self._core.playlists,

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')