"""
Binance Simple Earn REST API

OpenAPI Specification for the Binance Simple Earn 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_simple_earn.rest_api.api import RwusdApi
from binance_sdk_simple_earn.rest_api.models import GetRwusdAccountResponse
from binance_sdk_simple_earn.rest_api.models import GetRwusdQuotaDetailsResponse
from binance_sdk_simple_earn.rest_api.models import GetRwusdRateHistoryResponse
from binance_sdk_simple_earn.rest_api.models import GetRwusdRedemptionHistoryResponse
from binance_sdk_simple_earn.rest_api.models import GetRwusdRewardsHistoryResponse
from binance_sdk_simple_earn.rest_api.models import GetRwusdSubscriptionHistoryResponse
from binance_sdk_simple_earn.rest_api.models import RedeemRwusdResponse
from binance_sdk_simple_earn.rest_api.models import SubscribeRwusdResponse


class TestRwusdApi:
    @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 = RwusdApi(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_get_rwusd_account_success(self, mock_get_signature):
        """Test get_rwusd_account() successfully with required parameters only."""

        expected_response = {"rwusdAmount": "100", "totalProfit": "12.81"}
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_rwusd_account()

        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/rwusd/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(GetRwusdAccountResponse)

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

        assert response.data() == expected

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

        params = {"recv_window": 5000}

        expected_response = {"rwusdAmount": "100", "totalProfit": "12.81"}
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_rwusd_account(**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/rwusd/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(GetRwusdAccountResponse)

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

        assert response.data() == expected

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

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

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

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

        expected_response = {
            "subscriptionQuota": {
                "assets": ["USDT", "USDC"],
                "leftQuota": "1000",
                "minimum": "0.10000000",
            },
            "fastRedemptionQuota": {
                "leftQuota": "2",
                "minimum": "0.1",
                "fee": "0.0005",
                "freeQuota": "100",
            },
            "standardRedemptionQuota": {
                "leftQuota": "2",
                "minimum": "0.1",
                "fee": "0.001",
                "redeemPeriod": 3,
            },
            "subscribeEnable": True,
            "redeemEnable": True,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_rwusd_quota_details()

        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/rwusd/quota" 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(GetRwusdQuotaDetailsResponse)

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

        assert response.data() == expected

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

        params = {"recv_window": 5000}

        expected_response = {
            "subscriptionQuota": {
                "assets": ["USDT", "USDC"],
                "leftQuota": "1000",
                "minimum": "0.10000000",
            },
            "fastRedemptionQuota": {
                "leftQuota": "2",
                "minimum": "0.1",
                "fee": "0.0005",
                "freeQuota": "100",
            },
            "standardRedemptionQuota": {
                "leftQuota": "2",
                "minimum": "0.1",
                "fee": "0.001",
                "redeemPeriod": 3,
            },
            "subscribeEnable": True,
            "redeemEnable": True,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_rwusd_quota_details(**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/rwusd/quota" 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(GetRwusdQuotaDetailsResponse)

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

        assert response.data() == expected

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

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

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

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

        expected_response = {
            "rows": [{"annualPercentageRate": "0.0418", "time": 1577233578000}],
            "total": "1",
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_rwusd_rate_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/rwusd/history/rateHistory" 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(GetRwusdRateHistoryResponse)

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

        assert response.data() == expected

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

        params = {
            "start_time": 1623319461670,
            "end_time": 1641782889000,
            "current": 1,
            "size": 10,
            "recv_window": 5000,
        }

        expected_response = {
            "rows": [{"annualPercentageRate": "0.0418", "time": 1577233578000}],
            "total": "1",
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_rwusd_rate_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/rwusd/history/rateHistory" 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(GetRwusdRateHistoryResponse)

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

        assert response.data() == expected

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

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

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

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

        expected_response = {
            "rows": [
                {
                    "time": 1575018510000,
                    "asset": "RWUSD",
                    "amount": "51",
                    "receiveAsset": "USDC",
                    "receiveAmount": "50",
                    "fee": "1",
                    "arrivalTime": 1575018510000,
                    "status": "SUCCESS",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_rwusd_redemption_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/rwusd/history/redemptionHistory" 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(GetRwusdRedemptionHistoryResponse)

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

        assert response.data() == expected

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

        params = {
            "start_time": 1623319461670,
            "end_time": 1641782889000,
            "current": 1,
            "size": 10,
            "recv_window": 5000,
        }

        expected_response = {
            "rows": [
                {
                    "time": 1575018510000,
                    "asset": "RWUSD",
                    "amount": "51",
                    "receiveAsset": "USDC",
                    "receiveAmount": "50",
                    "fee": "1",
                    "arrivalTime": 1575018510000,
                    "status": "SUCCESS",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_rwusd_redemption_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/rwusd/history/redemptionHistory" 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(GetRwusdRedemptionHistoryResponse)

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

        assert response.data() == expected

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

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

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

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

        expected_response = {
            "rows": [
                {
                    "time": 1575018510000,
                    "rewardsAmount": "1",
                    "rwusdPosition": "100",
                    "annualPercentageRate": "0.0418",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_rwusd_rewards_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/rwusd/history/rewardsHistory" 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(GetRwusdRewardsHistoryResponse)

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

        assert response.data() == expected

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

        params = {
            "start_time": 1623319461670,
            "end_time": 1641782889000,
            "current": 1,
            "size": 10,
            "recv_window": 5000,
        }

        expected_response = {
            "rows": [
                {
                    "time": 1575018510000,
                    "rewardsAmount": "1",
                    "rwusdPosition": "100",
                    "annualPercentageRate": "0.0418",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_rwusd_rewards_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/rwusd/history/rewardsHistory" 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(GetRwusdRewardsHistoryResponse)

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

        assert response.data() == expected

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

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

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

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

        expected_response = {
            "rows": [
                {
                    "time": 1575018510000,
                    "asset": "USDC",
                    "amount": "100",
                    "receiveAsset": "RWUSD",
                    "receiveAmount": "100",
                    "status": "SUCCESS",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_rwusd_subscription_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/rwusd/history/subscriptionHistory" 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(GetRwusdSubscriptionHistoryResponse)

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

        assert response.data() == expected

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

        params = {
            "asset": "asset_example",
            "start_time": 1623319461670,
            "end_time": 1641782889000,
            "current": 1,
            "size": 10,
            "recv_window": 5000,
        }

        expected_response = {
            "rows": [
                {
                    "time": 1575018510000,
                    "asset": "USDC",
                    "amount": "100",
                    "receiveAsset": "RWUSD",
                    "receiveAmount": "100",
                    "status": "SUCCESS",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_rwusd_subscription_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/rwusd/history/subscriptionHistory" 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(GetRwusdSubscriptionHistoryResponse)

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

        assert response.data() == expected

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

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

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

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

        params = {
            "amount": 1.0,
            "type": "s",
        }

        expected_response = {
            "success": True,
            "receiveAmount": "0.23092091",
            "fee": "0.00000012",
            "arrivalTime": 1575018510000,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.redeem_rwusd(**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/rwusd/redeem" in request_kwargs["url"]
        assert request_kwargs["method"] == "POST"
        assert normalized["amount"] == 1.0
        assert normalized["type"] == "s"

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

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

        assert response.data() == expected

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

        params = {"amount": 1.0, "type": "s", "recv_window": 5000}

        expected_response = {
            "success": True,
            "receiveAmount": "0.23092091",
            "fee": "0.00000012",
            "arrivalTime": 1575018510000,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.redeem_rwusd(**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/rwusd/redeem" in request_kwargs["url"]
        assert request_kwargs["method"] == "POST"

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

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

        assert response.data() == expected

    def test_redeem_rwusd_missing_required_param_amount(self):
        """Test that redeem_rwusd() raises RequiredError when 'amount' is missing."""
        params = {
            "amount": 1.0,
            "type": "s",
        }
        params["amount"] = None

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

    def test_redeem_rwusd_missing_required_param_type(self):
