# -*- coding: utf-8 -*-
from homehub_backend.lib import rpc


class Test_BaseJSONRPCError:
    def test_to_json(self):
        exception = rpc.BaseJSONRPCError(data='spam')
        exception.ERROR_CODE = -32604
        exception.ERROR_MESSAGE = 'Test error'

        result = exception.to_json()
        assert result['code'] == exception.ERROR_CODE
        assert result['message'] == exception.ERROR_MESSAGE
        assert result['data'] == exception.data

    def test_to_json_without_data(self):
        exception = rpc.BaseJSONRPCError()
        exception.ERROR_CODE = -32604
        exception.ERROR_MESSAGE = 'Test error'

        result = exception.to_json()
        assert result['code'] == exception.ERROR_CODE
        assert result['message'] == exception.ERROR_MESSAGE
        assert 'data' not in result
