How to use jsonrpcserver - 10 common examples

To help you get started, we’ve selected a few jsonrpcserver examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bcb / jsonrpcserver / tests / test_request.py View on Github external
def test_positionals_with_context(self):
        methods = {"square": lambda foo, context=None: context}
        req = Request(
            {"jsonrpc": "2.0", "method": "square", "params": [FOO], "id": 1},
            context=BAR,
        )
        self.assertEqual(BAR, req.call(methods)["result"])
github bcb / jsonrpcserver / tests / test_request.py View on Github external
def test_configuring_http_status(self):
        NotificationResponse.http_status = status.HTTP_OK
        req = Request({"jsonrpc": "2.0", "method": "foo"}).call([foo])
        self.assertEqual(status.HTTP_OK, req.http_status)
        NotificationResponse.http_status = status.HTTP_NO_CONTENT
github bcb / jsonrpcserver / tests / test_request.py View on Github external
def test_positionals(self):
        methods = {"square": lambda x: x * x}
        req = Request({"jsonrpc": "2.0", "method": "square", "params": [3], "id": 1})
        self.assertEqual(9, req.call(methods)["result"])
github bcb / jsonrpcserver / tests / test_request.py View on Github external
def test_methods_functions_with_decorator(self):
        methods = Methods()

        @methods.add
        def foo():
            return "bar"

        req = Request({"jsonrpc": "2.0", "method": "foo", "id": 1})
        self.assertEqual("bar", req.call(methods)["result"])
github bcb / jsonrpcserver / tests / test_request.py View on Github external
def test_dict_partials(self):
        multiply = lambda x, y: x * y
        req = Request({"jsonrpc": "2.0", "method": "baz", "params": [3], "id": 1})
        self.assertEqual(6, req.call({"baz": partial(multiply, 2)})["result"])
github bcb / jsonrpcserver / tests / test_request.py View on Github external
def test_request_id_notification(self):
        req = Request({"jsonrpc": "2.0", "method": "foo"})
        self.assertEqual(None, req.request_id)
github bcb / jsonrpcserver / tests / test_request.py View on Github external
def test_methods_lambdas(self):
        methods = Methods()
        methods.add(lambda: "bar", "foo")
        req = Request({"jsonrpc": "2.0", "method": "foo", "id": 1})
        self.assertEqual("bar", req.call(methods)["result"])
github bcb / jsonrpcserver / tests / test_request.py View on Github external
def test_invalid_request(self):
        req = Request({"jsonrpc": "2.0"})
        self.assertIsInstance(req.response, ErrorResponse)
github bcb / jsonrpcserver / tests / test_methods.py View on Github external
def test_add_lambda_no_name():
    lmb = lambda x, y: x + y
    methods = Methods(lmb)
    # The lambda's __name__ will be ''!
    assert "" in methods.items
github bcb / jsonrpcserver / tests / test_dispatcher.py View on Github external
def test_safe_call_method_not_found():
    response = safe_call(
        Request(method="nonexistant", id=1),
        Methods(ping),
        debug=True,
        serialize=default_serialize,
    )
    assert isinstance(response, MethodNotFoundResponse)