def test_call_raising_exception(): def method(): raise ValueError("foo") assert call(Request("ping", [], 1), NOCONTEXT, method) == Left( ErrorResult(ERROR_INTERNAL_ERROR, "Internal error", "foo") )
def test_call_raising_jsonrpcerror(): def method(): raise JsonRpcError(code=1, message="foo", data=NODATA) assert call(Request("ping", [], 1), NOCONTEXT, method) == Left( ErrorResult(1, "foo") )
def test_validate_result_positionals_not_passed(): assert validate_args( Request("f", {"foo": "bar"}, NOID), NOCONTEXT, lambda x: None ) == Left( ErrorResult( ERROR_INVALID_PARAMS, "Invalid params", "missing a required argument: 'x'" ) )
def test_validate_result_no_arguments_too_many_positionals(): assert validate_args(Request("f", ["foo"], NOID), NOCONTEXT, lambda: None) == Left( ErrorResult( code=ERROR_INVALID_PARAMS, message="Invalid params", data="too many positional arguments", ) )
def test_to_response_ErrorResult(): assert ( to_response( Request("ping", [], sentinel.id), Left( ErrorResult( code=sentinel.code, message=sentinel.message, data=sentinel.data ) ), ) ) == Left( ErrorResponse(sentinel.code, sentinel.message, sentinel.data, sentinel.id) )
def test_Error(): assert Error(1, "foo", None) == Left(ErrorResult(1, "foo", None))
def test_ErrorResult_with_data(): result = ErrorResult(sentinel.code, sentinel.message, sentinel.data) assert result.code == sentinel.code assert result.message == sentinel.message assert result.data == sentinel.data
def test_ErrorResult_repr(): assert ( repr(ErrorResult(1, "foo", None)) == "ErrorResult(code=1, message='foo', data=None)" )
def test_ErrorResult(): result = ErrorResult(sentinel.code, sentinel.message) assert result.code == sentinel.code assert result.message == sentinel.message assert result.data == NODATA
def test_get_method(): assert get_method({"ping": ping}, "non-existant") == Left( ErrorResult(ERROR_METHOD_NOT_FOUND, "Method not found", "non-existant") )
def test_validate_args(): assert validate_args(Request("ping", ["foo"], 1), NOCONTEXT, ping) == Left( ErrorResult( ERROR_INVALID_PARAMS, "Invalid params", "too many positional arguments" ) )