@@ -436,6 +436,122 @@ def test_zero_idxVol_is_included(self, mock_request):
436436 mock_request .assert_called_once_with (c .POST , c .POSITION_BUILDER , expected_params )
437437
438438
439+ class TestAccountAPISetAutoEarn (unittest .TestCase ):
440+ """Unit tests for the set_auto_earn method"""
441+
442+ def setUp (self ):
443+ """Set up test fixtures"""
444+ self .account_api = AccountAPI (
445+ api_key = 'test_key' ,
446+ api_secret_key = 'test_secret' ,
447+ passphrase = 'test_pass' ,
448+ flag = '0'
449+ )
450+
451+ @patch .object (AccountAPI , '_request_with_params' )
452+ def test_set_auto_earn_with_all_params (self , mock_request ):
453+ """Test set_auto_earn with all parameters provided"""
454+ # Arrange
455+ mock_response = {'code' : '0' , 'msg' : '' , 'data' : []}
456+ mock_request .return_value = mock_response
457+
458+ # Act
459+ result = self .account_api .set_auto_earn (
460+ ccy = 'USDT' ,
461+ action = 'turn_on' ,
462+ earnType = '0'
463+ )
464+
465+ # Assert
466+ expected_params = {
467+ 'ccy' : 'USDT' ,
468+ 'action' : 'turn_on' ,
469+ 'earnType' : '0'
470+ }
471+ mock_request .assert_called_once_with (c .POST , c .SET_AUTO_EARN , expected_params )
472+ self .assertEqual (result , mock_response )
473+
474+ @patch .object (AccountAPI , '_request_with_params' )
475+ def test_set_auto_earn_turn_on_action (self , mock_request ):
476+ """Test set_auto_earn with turn_on action"""
477+ # Arrange
478+ mock_response = {'code' : '0' , 'msg' : '' , 'data' : []}
479+ mock_request .return_value = mock_response
480+
481+ # Act
482+ result = self .account_api .set_auto_earn (
483+ ccy = 'BTC' ,
484+ action = 'turn_on' ,
485+ earnType = '0'
486+ )
487+
488+ # Assert
489+ expected_params = {
490+ 'ccy' : 'BTC' ,
491+ 'action' : 'turn_on' ,
492+ 'earnType' : '0'
493+ }
494+ mock_request .assert_called_once_with (c .POST , c .SET_AUTO_EARN , expected_params )
495+
496+ @patch .object (AccountAPI , '_request_with_params' )
497+ def test_set_auto_earn_turn_off_action (self , mock_request ):
498+ """Test set_auto_earn with turn_off action"""
499+ # Arrange
500+ mock_response = {'code' : '0' , 'msg' : '' , 'data' : []}
501+ mock_request .return_value = mock_response
502+
503+ # Act
504+ result = self .account_api .set_auto_earn (
505+ ccy = 'ETH' ,
506+ action = 'turn_off' ,
507+ earnType = '0'
508+ )
509+
510+ # Assert
511+ expected_params = {
512+ 'ccy' : 'ETH' ,
513+ 'action' : 'turn_off' ,
514+ 'earnType' : '0'
515+ }
516+ mock_request .assert_called_once_with (c .POST , c .SET_AUTO_EARN , expected_params )
517+
518+ @patch .object (AccountAPI , '_request_with_params' )
519+ def test_set_auto_earn_with_required_params_only (self , mock_request ):
520+ """Test set_auto_earn with required parameters only (ccy, action)"""
521+ # Arrange
522+ mock_response = {'code' : '0' , 'msg' : '' , 'data' : []}
523+ mock_request .return_value = mock_response
524+
525+ # Act
526+ result = self .account_api .set_auto_earn (ccy = 'USDT' , action = 'turn_on' )
527+
528+ # Assert
529+ expected_params = {
530+ 'ccy' : 'USDT' ,
531+ 'action' : 'turn_on'
532+ }
533+ mock_request .assert_called_once_with (c .POST , c .SET_AUTO_EARN , expected_params )
534+
535+ @patch .object (AccountAPI , '_request_with_params' )
536+ def test_set_auto_earn_different_currencies (self , mock_request ):
537+ """Test set_auto_earn with different currencies"""
538+ mock_response = {'code' : '0' , 'msg' : '' , 'data' : []}
539+ mock_request .return_value = mock_response
540+
541+ currencies = ['USDT' , 'BTC' , 'ETH' , 'USDC' ]
542+
543+ for ccy in currencies :
544+ mock_request .reset_mock ()
545+ result = self .account_api .set_auto_earn (
546+ ccy = ccy ,
547+ action = 'turn_on' ,
548+ earnType = '0'
549+ )
550+
551+ call_args = mock_request .call_args [0 ][2 ]
552+ self .assertEqual (call_args ['ccy' ], ccy )
553+
554+
439555if __name__ == '__main__' :
440556 unittest .main ()
441557
0 commit comments