33 lines
804 B
Python
33 lines
804 B
Python
# -*- coding: utf-8 -*-
|
|
from bthlabs_jsonrpc_core import exceptions
|
|
|
|
|
|
def test_to_rpc():
|
|
# Given
|
|
exception = exceptions.BaseJSONRPCError(data='spam')
|
|
exception.ERROR_CODE = -32604
|
|
exception.ERROR_MESSAGE = 'Test error'
|
|
|
|
# When
|
|
result = exception.to_rpc()
|
|
|
|
# Then
|
|
assert result['code'] == exception.ERROR_CODE
|
|
assert result['message'] == exception.ERROR_MESSAGE
|
|
assert result['data'] == exception.data
|
|
|
|
|
|
def test_to_rpc_without_data():
|
|
# Given
|
|
exception = exceptions.BaseJSONRPCError()
|
|
exception.ERROR_CODE = -32604
|
|
exception.ERROR_MESSAGE = 'Test error'
|
|
|
|
# When
|
|
result = exception.to_rpc()
|
|
|
|
# Then
|
|
assert result['code'] == exception.ERROR_CODE
|
|
assert result['message'] == exception.ERROR_MESSAGE
|
|
assert 'data' not in result
|