@@ -160,6 +160,45 @@ async def test_is_valid_account(binance_exchange):
160
160
_get_api_key_rights_mock .assert_not_called ()
161
161
162
162
163
+ # futures trading
164
+ exchange ._exchange .exchange_manager .is_future = True
165
+ with mock .patch .object (
166
+ exchange , "_get_api_key_rights" , mock .AsyncMock (return_value = [
167
+ trading_backend .enums .APIKeyRights .FUTURES_TRADING , trading_backend .enums .APIKeyRights .WITHDRAWALS
168
+ ])
169
+ ) as _get_api_key_rights_mock :
170
+ with mock .patch .object (exchange ._exchange .connector .client , "sapi_get_apireferral_ifnewuser" ,
171
+ mock .AsyncMock (return_value = {"rebateWorking" : True , "ifNewUser" : True })) \
172
+ as sapi_get_apireferral_ifnewuser_mock :
173
+ with mock .patch .object (exchange , "_allow_withdrawal_right" , mock .Mock (return_value = True )) as \
174
+ _allow_withdrawal_right_mock :
175
+ assert (await exchange .is_valid_account ()) == (True , None )
176
+ sapi_get_apireferral_ifnewuser_mock .assert_not_called ()
177
+ _get_api_key_rights_mock .assert_called_once ()
178
+ _allow_withdrawal_right_mock .assert_called_once ()
179
+ with mock .patch .object (exchange , "_allow_withdrawal_right" , mock .Mock (return_value = False )) as \
180
+ _allow_withdrawal_right_mock :
181
+ with pytest .raises (trading_backend .errors .APIKeyPermissionsError ):
182
+ assert (await exchange .is_valid_account ()) == (True , None )
183
+ _allow_withdrawal_right_mock .assert_called_once ()
184
+ with mock .patch .object (
185
+ exchange , "_get_api_key_rights" , mock .AsyncMock (return_value = [
186
+ trading_backend .enums .APIKeyRights .SPOT_TRADING , trading_backend .enums .APIKeyRights .WITHDRAWALS
187
+ ])
188
+ ) as _get_api_key_rights_mock :
189
+ with mock .patch .object (exchange ._exchange .connector .client , "sapi_get_apireferral_ifnewuser" ,
190
+ mock .AsyncMock (return_value = {"rebateWorking" : True , "ifNewUser" : True })) \
191
+ as sapi_get_apireferral_ifnewuser_mock :
192
+ with mock .patch .object (exchange , "_allow_withdrawal_right" , mock .Mock (return_value = True )) as \
193
+ _allow_withdrawal_right_mock :
194
+ with pytest .raises (trading_backend .errors .APIKeyPermissionsError ):
195
+ # futures trading permissions are required
196
+ assert (await exchange .is_valid_account ()) == (True , None )
197
+ sapi_get_apireferral_ifnewuser_mock .assert_not_called ()
198
+ _get_api_key_rights_mock .assert_called_once ()
199
+ _allow_withdrawal_right_mock .assert_not_called ()
200
+
201
+
163
202
@pytest .mark .asyncio
164
203
async def test_ensure_broker_status (binance_exchange ):
165
204
exchange = exchanges .Binance (binance_exchange )
0 commit comments