"""
Binance Crypto Loan REST API

OpenAPI Specification for the Binance Crypto Loan REST API
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""

import json
import pytest
import requests

from unittest.mock import MagicMock, patch
from urllib.parse import parse_qs

from binance_common.configuration import ConfigurationRestAPI
from binance_common.errors import RequiredError
from binance_common.utils import normalize_query_values, is_one_of_model, snake_to_camel

from binance_sdk_crypto_loan.rest_api.api import StableRateApi
from binance_sdk_crypto_loan.rest_api.models import (
    CheckCollateralRepayRateStableRateResponse,
)
from binance_sdk_crypto_loan.rest_api.models import GetCryptoLoansIncomeHistoryResponse
from binance_sdk_crypto_loan.rest_api.models import GetLoanBorrowHistoryResponse
from binance_sdk_crypto_loan.rest_api.models import GetLoanLtvAdjustmentHistoryResponse
from binance_sdk_crypto_loan.rest_api.models import GetLoanRepaymentHistoryResponse


class TestStableRateApi:
    @pytest.fixture(autouse=True)
    def setup_client(self):
        """Setup a client instance with mocked session before each test method."""
        self.mock_session = MagicMock(spec=requests.Session)
        config = ConfigurationRestAPI(
            api_key="test-api-key",
            api_secret="test-api-secret",
        )
        self.client = StableRateApi(configuration=config, session=self.mock_session)

    def set_mock_response(self, data: dict = {}, status_code=200, headers=None):
        """Helper method to setup mock response for the client's session request."""
        if headers is None:
            headers = {}

        mock_response = MagicMock()
        mock_response.status_code = status_code
        mock_response.json.return_value = data
        mock_response.text = json.dumps(data)
        mock_response.headers = headers

        self.mock_session.request.return_value = mock_response

    @patch("binance_common.utils.get_signature")
    def test_check_collateral_repay_rate_stable_rate_success(self, mock_get_signature):
        """Test check_collateral_repay_rate_stable_rate() successfully with required parameters only."""

        params = {
            "loan_coin": "loan_coin_example",
            "collateral_coin": "collateral_coin_example",
            "repay_amount": 1.0,
        }

        expected_response = {
            "loanlCoin": "BUSD",
            "collateralCoin": "BNB",
            "repayAmount": "1000",
            "rate": "300.36781234",
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.check_collateral_repay_rate_stable_rate(**params)

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs
        parsed_params = parse_qs(request_kwargs["params"])
        camel_case_params = {snake_to_camel(k): v for k, v in params.items()}
        normalized = normalize_query_values(parsed_params, camel_case_params)

        self.mock_session.request.assert_called_once()
        mock_get_signature.assert_called_once()

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/sapi/v1/loan/repay/collateral/rate" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"
        assert normalized["loanCoin"] == "loan_coin_example"
        assert normalized["collateralCoin"] == "collateral_coin_example"
        assert normalized["repayAmount"] == 1.0

        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(CheckCollateralRepayRateStableRateResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif (
            is_oneof
            or is_list
            or hasattr(CheckCollateralRepayRateStableRateResponse, "from_dict")
        ):
            expected = CheckCollateralRepayRateStableRateResponse.from_dict(
                expected_response
            )
        else:
            expected = CheckCollateralRepayRateStableRateResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    @patch("binance_common.utils.get_signature")
    def test_check_collateral_repay_rate_stable_rate_success_with_optional_params(
        self, mock_get_signature
    ):
        """Test check_collateral_repay_rate_stable_rate() successfully with optional parameters."""

        params = {
            "loan_coin": "loan_coin_example",
            "collateral_coin": "collateral_coin_example",
            "repay_amount": 1.0,
            "recv_window": 5000,
        }

        expected_response = {
            "loanlCoin": "BUSD",
            "collateralCoin": "BNB",
            "repayAmount": "1000",
            "rate": "300.36781234",
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.check_collateral_repay_rate_stable_rate(**params)

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/sapi/v1/loan/repay/collateral/rate" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"

        self.mock_session.request.assert_called_once()
        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(CheckCollateralRepayRateStableRateResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif (
            is_oneof
            or is_list
            or hasattr(CheckCollateralRepayRateStableRateResponse, "from_dict")
        ):
            expected = CheckCollateralRepayRateStableRateResponse.from_dict(
                expected_response
            )
        else:
            expected = CheckCollateralRepayRateStableRateResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    def test_check_collateral_repay_rate_stable_rate_missing_required_param_loan_coin(
        self,
    ):
        """Test that check_collateral_repay_rate_stable_rate() raises RequiredError when 'loan_coin' is missing."""
        params = {
            "loan_coin": "loan_coin_example",
            "collateral_coin": "collateral_coin_example",
            "repay_amount": 1.0,
        }
        params["loan_coin"] = None

        with pytest.raises(
            RequiredError, match="Missing required parameter 'loan_coin'"
        ):
            self.client.check_collateral_repay_rate_stable_rate(**params)

    def test_check_collateral_repay_rate_stable_rate_missing_required_param_collateral_coin(
        self,
    ):
        """Test that check_collateral_repay_rate_stable_rate() raises RequiredError when 'collateral_coin' is missing."""
        params = {
            "loan_coin": "loan_coin_example",
            "collateral_coin": "collateral_coin_example",
            "repay_amount": 1.0,
        }
        params["collateral_coin"] = None

        with pytest.raises(
            RequiredError, match="Missing required parameter 'collateral_coin'"
        ):
            self.client.check_collateral_repay_rate_stable_rate(**params)

    def test_check_collateral_repay_rate_stable_rate_missing_required_param_repay_amount(
        self,
    ):
        """Test that check_collateral_repay_rate_stable_rate() raises RequiredError when 'repay_amount' is missing."""
        params = {
            "loan_coin": "loan_coin_example",
            "collateral_coin": "collateral_coin_example",
            "repay_amount": 1.0,
        }
        params["repay_amount"] = None

        with pytest.raises(
            RequiredError, match="Missing required parameter 'repay_amount'"
        ):
            self.client.check_collateral_repay_rate_stable_rate(**params)

    def test_check_collateral_repay_rate_stable_rate_server_error(self):
        """Test that check_collateral_repay_rate_stable_rate() raises an error when the server returns an error."""

        params = {
            "loan_coin": "loan_coin_example",
            "collateral_coin": "collateral_coin_example",
            "repay_amount": 1.0,
        }

        mock_error = Exception("ResponseError")
        self.client.check_collateral_repay_rate_stable_rate = MagicMock(
            side_effect=mock_error
        )

        with pytest.raises(Exception, match="ResponseError"):
            self.client.check_collateral_repay_rate_stable_rate(**params)

    @patch("binance_common.utils.get_signature")
    def test_get_crypto_loans_income_history_success(self, mock_get_signature):
        """Test get_crypto_loans_income_history() successfully with required parameters only."""

        expected_response = [
            {
                "asset": "BUSD",
                "type": "borrowIn",
                "amount": "100",
                "timestamp": 1633771139847,
                "tranId": "80423589583",
            },
            {
                "asset": "BUSD",
                "type": "borrowIn",
                "amount": "100",
                "timestamp": 1634638371496,
                "tranId": "81685123491",
            },
        ]
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_crypto_loans_income_history()

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        self.mock_session.request.assert_called_once()
        mock_get_signature.assert_called_once()

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/sapi/v1/loan/income" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"

        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(GetCryptoLoansIncomeHistoryResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif (
            is_oneof
            or is_list
            or hasattr(GetCryptoLoansIncomeHistoryResponse, "from_dict")
        ):
            expected = GetCryptoLoansIncomeHistoryResponse.from_dict(expected_response)
        else:
            expected = GetCryptoLoansIncomeHistoryResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    @patch("binance_common.utils.get_signature")
    def test_get_crypto_loans_income_history_success_with_optional_params(
        self, mock_get_signature
    ):
        """Test get_crypto_loans_income_history() successfully with optional parameters."""

        params = {
            "asset": "asset_example",
            "type": "0",
            "start_time": 1623319461670,
            "end_time": 1641782889000,
            "limit": 10,
            "recv_window": 5000,
        }

        expected_response = [
            {
                "asset": "BUSD",
                "type": "borrowIn",
                "amount": "100",
                "timestamp": 1633771139847,
                "tranId": "80423589583",
            },
            {
                "asset": "BUSD",
                "type": "borrowIn",
                "amount": "100",
                "timestamp": 1634638371496,
                "tranId": "81685123491",
            },
        ]
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_crypto_loans_income_history(**params)

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/sapi/v1/loan/income" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"

        self.mock_session.request.assert_called_once()
        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(GetCryptoLoansIncomeHistoryResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif (
            is_oneof
            or is_list
            or hasattr(GetCryptoLoansIncomeHistoryResponse, "from_dict")
        ):
            expected = GetCryptoLoansIncomeHistoryResponse.from_dict(expected_response)
        else:
            expected = GetCryptoLoansIncomeHistoryResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    def test_get_crypto_loans_income_history_server_error(self):
        """Test that get_crypto_loans_income_history() raises an error when the server returns an error."""

        mock_error = Exception("ResponseError")
        self.client.get_crypto_loans_income_history = MagicMock(side_effect=mock_error)

        with pytest.raises(Exception, match="ResponseError"):
            self.client.get_crypto_loans_income_history()

    @patch("binance_common.utils.get_signature")
    def test_get_loan_borrow_history_success(self, mock_get_signature):
        """Test get_loan_borrow_history() successfully with required parameters only."""

        expected_response = {
            "rows": [
                {
                    "orderId": 100000001,
                    "loanCoin": "BUSD",
                    "initialLoanAmount": "10000",
                    "hourlyInterestRate": "0.000057",
                    "loanTerm": "7",
                    "collateralCoin": "BNB",
                    "initialCollateralAmount": "49.27565492",
                    "borrowTime": 1575018510000,
                    "status": "Repaid",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_loan_borrow_history()

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        self.mock_session.request.assert_called_once()
        mock_get_signature.assert_called_once()

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/sapi/v1/loan/borrow/history" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"

        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(GetLoanBorrowHistoryResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif is_oneof or is_list or hasattr(GetLoanBorrowHistoryResponse, "from_dict"):
            expected = GetLoanBorrowHistoryResponse.from_dict(expected_response)
        else:
            expected = GetLoanBorrowHistoryResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    @patch("binance_common.utils.get_signature")
    def test_get_loan_borrow_history_success_with_optional_params(
        self, mock_get_signature
    ):
        """Test get_loan_borrow_history() successfully with optional parameters."""

        params = {
            "order_id": 1,
            "loan_coin": "loan_coin_example",
            "collateral_coin": "collateral_coin_example",
            "start_time": 1623319461670,
            "end_time": 1641782889000,
            "current": 1,
            "limit": 10,
            "recv_window": 5000,
        }

        expected_response = {
            "rows": [
                {
                    "orderId": 100000001,
                    "loanCoin": "BUSD",
                    "initialLoanAmount": "10000",
                    "hourlyInterestRate": "0.000057",
                    "loanTerm": "7",
                    "collateralCoin": "BNB",
                    "initialCollateralAmount": "49.27565492",
                    "borrowTime": 1575018510000,
                    "status": "Repaid",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_loan_borrow_history(**params)

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/sapi/v1/loan/borrow/history" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"

        self.mock_session.request.assert_called_once()
        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(GetLoanBorrowHistoryResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif is_oneof or is_list or hasattr(GetLoanBorrowHistoryResponse, "from_dict"):
            expected = GetLoanBorrowHistoryResponse.from_dict(expected_response)
        else:
            expected = GetLoanBorrowHistoryResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    def test_get_loan_borrow_history_server_error(self):
        """Test that get_loan_borrow_history() raises an error when the server returns an error."""

        mock_error = Exception("ResponseError")
        self.client.get_loan_borrow_history = MagicMock(side_effect=mock_error)

        with pytest.raises(Exception, match="ResponseError"):
            self.client.get_loan_borrow_history()

    @patch("binance_common.utils.get_signature")
    def test_get_loan_ltv_adjustment_history_success(self, mock_get_signature):
        """Test get_loan_ltv_adjustment_history() successfully with required parameters only."""

        expected_response = {
            "rows": [
                {
                    "loanCoin": "BUSD",
                    "collateralCoin": "BNB",
                    "direction": "ADDITIONAL",
                    "amount": "5.235",
                    "preLTV": "0.78",
                    "afterLTV": "0.56",
                    "adjustTime": 1575018510000,
                    "orderId": 756783308056935400,
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_loan_ltv_adjustment_history()

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        self.mock_session.request.assert_called_once()
        mock_get_signature.assert_called_once()

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/sapi/v1/loan/ltv/adjustment/history" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"

        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(GetLoanLtvAdjustmentHistoryResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif (
            is_oneof
            or is_list
            or hasattr(GetLoanLtvAdjustmentHistoryResponse, "from_dict")
        ):
            expected = GetLoanLtvAdjustmentHistoryResponse.from_dict(expected_response)
        else:
            expected = GetLoanLtvAdjustmentHistoryResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    @patch("binance_common.utils.get_signature")
    def test_get_loan_ltv_adjustment_history_success_with_optional_params(
        self, mock_get_signature
    ):
        """Test get_loan_ltv_adjustment_history() successfully with optional parameters."""

        params = {
            "order_id": 1,
            "loan_coin": "loan_coin_example",
            "collateral_coin": "collateral_coin_example",
            "start_time": 1623319461670,
            "end_time": 1641782889000,
            "current": 1,
            "limit": 10,
            "recv_window": 5000,
        }

        expected_response = {
            "rows": [
                {
                    "loanCoin": "BUSD",
                    "collateralCoin": "BNB",
                    "direction": "ADDITIONAL",
                    "amount": "5.235",
                    "preLTV": "0.78",
                    "afterLTV": "0.56",
                    "adjustTime": 1575018510000,
                    "orderId": 756783308056935400,
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_loan_ltv_adjustment_history(**params)

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/sapi/v1/loan/ltv/adjustment/history" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"

        self.mock_session.request.assert_called_once()
        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(GetLoanLtvAdjustmentHistoryResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif (
            is_oneof
            or is_list
            or hasattr(GetLoanLtvAdjustmentHistoryResponse, "from_dict")
        ):
            expected = GetLoanLtvAdjustmentHistoryResponse.from_dict(expected_response)
        else:
            expected = GetLoanLtvAdjustmentHistoryResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    def test_get_loan_ltv_adjustment_history_server_error(self):
        """Test that get_loan_ltv_adjustment_history() raises an error when the server returns an error."""

        mock_error = Exception("ResponseError")
        self.client.get_loan_ltv_adjustment_history = MagicMock(side_effect=mock_error)

        with pytest.raises(Exception, match="ResponseError"):
            self.client.get_loan_ltv_adjustment_history()

    @patch("binance_common.utils.get_signature")
    def test_get_loan_repayment_history_success(self, mock_get_signature):
        """Test get_loan_repayment_history() successfully with required parameters only."""

        expected_response = {
            "rows": [
                {
                    "loanCoin": "BUSD",
                    "repayAmount": "10000",
                    "collateralCoin": "BNB",
                    "collateralUsed": "0",
                    "collateralReturn": "49.27565492",
                    "repayType": "1",
                    "repayStatus": "Repaid",
                    "repayTime": 1575018510000,
                    "orderId": 756783308056935400,
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_loan_repayment_history()

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        self.mock_session.request.assert_called_once()
        mock_get_signature.assert_called_once()

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/sapi/v1/loan/repay/history" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"

        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(GetLoanRepaymentHistoryResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif (
            is_oneof or is_list or hasattr(GetLoanRepaymentHistoryResponse, "from_dict")
        ):
            expected = GetLoanRepaymentHistoryResponse.from_dict(expected_response)
        else:
            expected = GetLoanRepaymentHistoryResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    @patch("binance_common.utils.get_signature")
    def test_get_loan_repayment_history_success_with_optional_params(
        self, mock_get_signature
    ):
        """Test get_loan_repayment_history() successfully with optional parameters."""

        params = {
            "order_id": 1,
            "loan_coin": "loan_coin_example",
            "collateral_coin": "collateral_coin_example",
            "start_time": 1623319461670,
            "end_time": 1641782889000,
            "current": 1,
            "limit": 10,
            "recv_window": 5000,
        }

        expected_response = {
            "rows": [
                {
                    "loanCoin": "BUSD",
                    "repayAmount": "10000",
                    "collateralCoin": "BNB",
                    "collateralUsed": "0",
                    "collateralReturn": "49.27565492",
                    "repayType": "1",
                    "repayStatus": "Repaid",
                    "repayTime": 1575018510000,
                    "orderId": 756783308056935400,
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_loan_repayment_history(**params)

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/sapi/v1/loan/repay/history" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"

        self.mock_session.request.assert_called_once()
        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(GetLoanRepaymentHistoryResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif (
            is_oneof or is_list or hasattr(GetLoanRepaymentHistoryResponse, "from_dict")
        ):
            expected = GetLoanRepaymentHistoryResponse.from_dict(expected_response)
        else:
            expected = GetLoanRepaymentHistoryResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    def test_get_loan_repayment_history_server_error(self):
        """Test that get_loan_repayment_history() raises an error when the server returns an error."""

        mock_error = Exception("ResponseError")
        self.client.get_loan_repayment_history = MagicMock(side_effect=mock_error)

        with pytest.raises(Exception, match="ResponseError"):
            self.client.get_loan_repayment_history()
