"""
Binance Derivatives Trading Options REST API

OpenAPI Specification for the Binance Derivatives Trading Options 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_derivatives_trading_options.rest_api.api import AccountApi
from binance_sdk_derivatives_trading_options.rest_api.models import (
    AccountFundingFlowResponse,
)
from binance_sdk_derivatives_trading_options.rest_api.models import (
    GetDownloadIdForOptionTransactionHistoryResponse,
)
from binance_sdk_derivatives_trading_options.rest_api.models import (
    GetOptionTransactionHistoryDownloadLinkByIdResponse,
)
from binance_sdk_derivatives_trading_options.rest_api.models import (
    OptionAccountInformationResponse,
)
from binance_sdk_derivatives_trading_options.rest_api.models import (
    OptionMarginAccountInformationResponse,
)


class TestAccountApi:
    @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 = AccountApi(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_account_funding_flow_success(self, mock_get_signature):
        """Test account_funding_flow() successfully with required parameters only."""

        params = {
            "currency": "currency_example",
        }

        expected_response = [
            {
                "id": 1125899906842624000,
                "asset": "USDT",
                "amount": "-0.552",
                "type": "FEE",
                "createDate": 1592449456000,
            },
            {
                "id": 1125899906842624000,
                "asset": "USDT",
                "amount": "100",
                "type": "CONTRACT",
                "createDate": 1592449456000,
            },
            {
                "id": 1125899906842624000,
                "asset": "USDT",
                "amount": "10000",
                "type": "TRANSFER",
                "createDate": 1592448410000,
            },
        ]
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.account_funding_flow(**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 "/eapi/v1/bill" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"
        assert normalized["currency"] == "currency_example"

        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(AccountFundingFlowResponse)

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

        assert response.data() == expected

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

        params = {
            "currency": "currency_example",
            "record_id": 1,
            "start_time": 1623319461670,
            "end_time": 1641782889000,
            "limit": 100,
            "recv_window": 5000,
        }

        expected_response = [
            {
                "id": 1125899906842624000,
                "asset": "USDT",
                "amount": "-0.552",
                "type": "FEE",
                "createDate": 1592449456000,
            },
            {
                "id": 1125899906842624000,
                "asset": "USDT",
                "amount": "100",
                "type": "CONTRACT",
                "createDate": 1592449456000,
            },
            {
                "id": 1125899906842624000,
                "asset": "USDT",
                "amount": "10000",
                "type": "TRANSFER",
                "createDate": 1592448410000,
            },
        ]
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.account_funding_flow(**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 "/eapi/v1/bill" 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(AccountFundingFlowResponse)

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

        assert response.data() == expected

    def test_account_funding_flow_missing_required_param_currency(self):
        """Test that account_funding_flow() raises RequiredError when 'currency' is missing."""
        params = {
            "currency": "currency_example",
        }
        params["currency"] = None

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

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

        params = {
            "currency": "currency_example",
        }

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

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

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

        params = {
            "start_time": 1623319461670,
            "end_time": 1641782889000,
        }

        expected_response = {
            "avgCostTimestampOfLast30d": 7241837,
            "downloadId": "546975389218332672",
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_download_id_for_option_transaction_history(**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 "/eapi/v1/income/asyn" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"
        assert normalized["startTime"] == 1623319461670
        assert normalized["endTime"] == 1641782889000

        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(GetDownloadIdForOptionTransactionHistoryResponse)

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

        assert response.data() == expected

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

        params = {
            "start_time": 1623319461670,
            "end_time": 1641782889000,
            "recv_window": 5000,
        }

        expected_response = {
            "avgCostTimestampOfLast30d": 7241837,
            "downloadId": "546975389218332672",
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_download_id_for_option_transaction_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 "/eapi/v1/income/asyn" 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(GetDownloadIdForOptionTransactionHistoryResponse)

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

        assert response.data() == expected

    def test_get_download_id_for_option_transaction_history_missing_required_param_start_time(
        self,
    ):
        """Test that get_download_id_for_option_transaction_history() raises RequiredError when 'start_time' is missing."""
        params = {
            "start_time": 1623319461670,
            "end_time": 1641782889000,
        }
        params["start_time"] = None

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

    def test_get_download_id_for_option_transaction_history_missing_required_param_end_time(
        self,
    ):
        """Test that get_download_id_for_option_transaction_history() raises RequiredError when 'end_time' is missing."""
        params = {
            "start_time": 1623319461670,
            "end_time": 1641782889000,
        }
        params["end_time"] = None

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

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

        params = {
            "start_time": 1623319461670,
            "end_time": 1641782889000,
        }

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

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

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

        params = {
            "download_id": "1",
        }

        expected_response = {
            "downloadId": "545923594199212032",
            "status": "processing",
            "url": "",
            "notified": False,
            "expirationTimestamp": -1,
            "isExpired": None,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_option_transaction_history_download_link_by_id(
            **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 "/eapi/v1/income/asyn/id" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"
        assert normalized["downloadId"] == "1"

        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(GetOptionTransactionHistoryDownloadLinkByIdResponse)

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

        assert response.data() == expected

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

        params = {"download_id": "1", "recv_window": 5000}

        expected_response = {
            "downloadId": "545923594199212032",
            "status": "processing",
            "url": "",
            "notified": False,
            "expirationTimestamp": -1,
            "isExpired": None,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_option_transaction_history_download_link_by_id(
            **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 "/eapi/v1/income/asyn/id" 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(GetOptionTransactionHistoryDownloadLinkByIdResponse)

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

        assert response.data() == expected

    def test_get_option_transaction_history_download_link_by_id_missing_required_param_download_id(
        self,
    ):
        """Test that get_option_transaction_history_download_link_by_id() raises RequiredError when 'download_id' is missing."""
        params = {
            "download_id": "1",
        }
        params["download_id"] = None

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

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

        params = {
            "download_id": "1",
        }

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

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

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

        expected_response = {
            "asset": [
                {
                    "asset": "USDT",
                    "marginBalance": "1877.52214415",
                    "equity": "617.77711415",
                    "available": "0",
                    "locked": "2898.92389933",
                    "unrealizedPNL": "222.23697000",
                }
            ],
            "greek": [
                {
                    "underlying": "BTCUSDT",
                    "delta": "-0.05",
                    "gamma": "-0.002",
                    "theta": "-0.05",
                    "vega": "-0.002",
                }
            ],
            "time": 1592449455993,
            "riskLevel": "NORMAL",
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.option_account_information()

        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 "/eapi/v1/account" 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(OptionAccountInformationResponse)

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

        assert response.data() == expected

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

        params = {"recv_window": 5000}

        expected_response = {
            "asset": [
                {
                    "asset": "USDT",
                    "marginBalance": "1877.52214415",
                    "equity": "617.77711415",
                    "available": "0",
                    "locked": "2898.92389933",
                    "unrealizedPNL": "222.23697000",
                }
            ],
            "greek": [
                {
                    "underlying": "BTCUSDT",
                    "delta": "-0.05",
                    "gamma": "-0.002",
                    "theta": "-0.05",
                    "vega": "-0.002",
                }
            ],
            "time": 1592449455993,
            "riskLevel": "NORMAL",
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.option_account_information(**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 "/eapi/v1/account" 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(OptionAccountInformationResponse)

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

        assert response.data() == expected

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

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

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

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

        expected_response = {
            "asset": [
                {
                    "asset": "USDT",
                    "marginBalance": "10099.448",
                    "equity": "10094.44662",
                    "available": "8725.92524",
                    "initialMargin": "1084.52138",
                    "maintMargin": "151.00138",
                    "unrealizedPNL": "-5.00138",
                    "adjustedEquity": "34.13282285",
                }
            ],
            "greek": [
                {
                    "underlying": "BTCUSDT",
                    "delta": "-0.05",
                    "gamma": "-0.002",
                    "theta": "-0.05",
                    "vega": "-0.002",
                }
            ],
            "time": 1592449455993,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.option_margin_account_information()

        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 "/eapi/v1/marginAccount" 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(OptionMarginAccountInformationResponse)

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

        assert response.data() == expected

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

        params = {"recv_window": 5000}

        expected_response = {
            "asset": [
                {
                    "asset": "USDT",
                    "marginBalance": "10099.448",
                    "equity": "10094.44662",
                    "available": "8725.92524",
                    "initialMargin": "1084.52138",
                    "maintMargin": "151.00138",
                    "unrealizedPNL": "-5.00138",
                    "adjustedEquity": "34.13282285",
                }
            ],
            "greek": [
                {
                    "underlying": "BTCUSDT",
                    "delta": "-0.05",
                    "gamma": "-0.002",
                    "theta": "-0.05",
                    "vega": "-0.002",
                }
            ],
            "time": 1592449455993,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.option_margin_account_information(**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 "/eapi/v1/marginAccount" 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(OptionMarginAccountInformationResponse)

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

        assert response.data() == expected

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

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

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