Esempio n. 1
0
def make_jsonrpc_wrapper(core_actor):
    inspector = jsonrpc.JsonRpcInspector(
        objects={
            'core.get_uri_schemes': core.Core.get_uri_schemes,
            'core.get_version': core.Core.get_version,
            'core.history': core.HistoryController,
            'core.library': core.LibraryController,
            'core.mixer': core.MixerController,
            'core.playback': core.PlaybackController,
            'core.playlists': core.PlaylistsController,
            'core.tracklist': core.TracklistController,
        })
    return jsonrpc.JsonRpcWrapper(
        objects={
            'core.describe': inspector.describe,
            'core.get_uri_schemes': core_actor.get_uri_schemes,
            'core.get_version': core_actor.get_version,
            'core.history': core_actor.history,
            'core.library': core_actor.library,
            'core.mixer': core_actor.mixer,
            'core.playback': core_actor.playback,
            'core.playlists': core_actor.playlists,
            'core.tracklist': core_actor.tracklist,
        },
        decoders=[models.model_json_decoder],
        encoders=[models.ModelJSONEncoder]
    )
Esempio n. 2
0
    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,
                "core.tracklist": core.TracklistController,
            }
        )

        methods = inspector.describe()

        assert "core.get_uri_schemes" in methods
        assert len(methods["core.get_uri_schemes"]["params"]) == 0

        assert "core.library.lookup" in methods
        assert methods["core.library.lookup"]["params"][0]["name"] == "uris"

        assert "core.playback.next" in methods
        assert len(methods["core.playback.next"]["params"]) == 0

        assert "core.playlists.as_list" in methods
        assert len(methods["core.playlists.as_list"]["params"]) == 0

        assert "core.tracklist.filter" in methods
        assert (
            methods["core.tracklist.filter"]["params"][0]["name"] == "criteria"
        )
Esempio n. 3
0
    def test_can_describe_method_on_root(self):
        inspector = jsonrpc.JsonRpcInspector({"hello": lambda: "Hello, world!"})

        methods = inspector.describe()

        assert "hello" in methods
        assert len(methods["hello"]["params"]) == 0
Esempio n. 4
0
    def test_inspector_can_describe_an_object_with_methods(self):
        inspector = jsonrpc.JsonRpcInspector({"calc": Calculator})

        methods = inspector.describe()

        assert "calc.add" in methods
        assert (methods["calc.add"]["description"] ==
                "Returns the sum of the given numbers")

        assert "calc.sub" in methods
        assert "calc.take_it_all" in methods
        assert "calc._secret" not in methods
        assert "calc.__init__" not in methods

        method = methods["calc.take_it_all"]
        assert "params" in method

        params = method["params"]

        assert params[0]["name"] == "a"
        assert "default" not in params[0]

        assert params[1]["name"] == "b"
        assert "default" not in params[1]

        assert params[2]["name"] == "c"
        assert params[2]["default"] is True

        assert params[3]["name"] == "args"
        assert "default" not in params[3]
        assert params[3]["varargs"] is True

        assert params[4]["name"] == "kwargs"
        assert "default" not in params[4]
        assert params[4]["kwargs"] is True
Esempio n. 5
0
    def test_can_describe_method_on_root(self):
        inspector = jsonrpc.JsonRpcInspector({
            'hello': lambda: 'Hello, world!',
        })

        methods = inspector.describe()

        self.assertIn('hello', methods)
        self.assertEqual(len(methods['hello']['params']), 0)
Esempio n. 6
0
    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,
            'core.tracklist':
            core.TracklistController,
        })

        methods = inspector.describe()

        self.assertIn('core.get_uri_schemes', methods)
        self.assertEqual(len(methods['core.get_uri_schemes']['params']), 0)

        self.assertIn('core.library.lookup', methods.keys())
        self.assertEqual(methods['core.library.lookup']['params'][0]['name'],
                         'uri')

        self.assertIn('core.playback.next', methods)
        self.assertEqual(len(methods['core.playback.next']['params']), 0)

        self.assertIn('core.playlists.get_playlists', methods)
        self.assertEqual(
            len(methods['core.playlists.get_playlists']['params']), 1)

        self.assertIn('core.tracklist.filter', methods.keys())
        self.assertEqual(methods['core.tracklist.filter']['params'][0]['name'],
                         'criteria')
        self.assertEqual(methods['core.tracklist.filter']['params'][1]['name'],
                         'kwargs')
        self.assertEqual(
            methods['core.tracklist.filter']['params'][1]['kwargs'], True)
Esempio n. 7
0
    def test_inspector_can_describe_an_object_with_methods(self):
        inspector = jsonrpc.JsonRpcInspector({
            'calc': Calculator,
        })

        methods = inspector.describe()

        self.assertIn('calc.add', methods)
        self.assertEqual(methods['calc.add']['description'],
                         'Returns the sum of the given numbers')

        self.assertIn('calc.sub', methods)
        self.assertIn('calc.take_it_all', methods)
        self.assertNotIn('calc._secret', methods)
        self.assertNotIn('calc.__init__', methods)

        method = methods['calc.take_it_all']
        self.assertIn('params', method)

        params = method['params']

        self.assertEqual(params[0]['name'], 'a')
        self.assertNotIn('default', params[0])

        self.assertEqual(params[1]['name'], 'b')
        self.assertNotIn('default', params[1])

        self.assertEqual(params[2]['name'], 'c')
        self.assertEqual(params[2]['default'], True)

        self.assertEqual(params[3]['name'], 'args')
        self.assertNotIn('default', params[3])
        self.assertEqual(params[3]['varargs'], True)

        self.assertEqual(params[4]['name'], 'kwargs')
        self.assertNotIn('default', params[4])
        self.assertEqual(params[4]['kwargs'], True)
Esempio n. 8
0
 def test_empty_object_mounts_is_not_allowed(self):
     with self.assertRaises(AttributeError):
         jsonrpc.JsonRpcInspector(objects={'': Calculator})