
from binance.client import Client
from binance.exceptions import BinanceAPIException, BinanceRequestException
import pytest
import requests_mock


client = Client('api_key', 'api_secret')


def test_invalid_json():
    """Test Invalid response Exception"""

    with pytest.raises(BinanceRequestException):
        with requests_mock.mock() as m:
            m.get('https://www.binance.com/exchange/public/product', text='<head></html>')
            client.get_products()


def test_api_exception():
    """Test API response Exception"""

    with pytest.raises(BinanceAPIException):
        with requests_mock.mock() as m:
            json_obj = {"code": 1002, "msg": "Invalid API call"}
            m.get('https://www.binance.com/api/v1/time', json=json_obj, status_code=400)
            client.get_server_time()


from binance.client import Client
from binance.exceptions import BinanceAPIException, BinanceRequestException, BinanceWithdrawException
import pytest
import requests_mock


client = Client('api_key', 'api_secret')


def test_invalid_json():
    """Test Invalid response Exception"""

    with pytest.raises(BinanceRequestException):
        with requests_mock.mock() as m:
            m.get('https://www.binance.com/exchange/public/product', text='<head></html>')
            client.get_products()


def test_api_exception():
    """Test API response Exception"""

    with pytest.raises(BinanceAPIException):
        with requests_mock.mock() as m:
            json_obj = {"code": 1002, "msg": "Invalid API call"}
            m.get('https://www.binance.com/api/v1/time', json=json_obj, status_code=400)
            client.get_server_time()


def test_withdraw_api_exception():
    """Test Withdraw API response Exception"""

    with pytest.raises(BinanceWithdrawException):

        with requests_mock.mock() as m:
            json_obj = {"success": False, "msg": "Insufficient funds"}
            m.register_uri('POST', requests_mock.ANY, json=json_obj, status_code=200)
            client.withdraw(asset='BTC', address='BTCADDRESS', amount=100)

Add test for withdraw exception response
Add test for withdraw exception response

  
  from binance.client import Client
- from binance.exceptions import BinanceAPIException, BinanceRequestException
+ from binance.exceptions import BinanceAPIException, BinanceRequestException, BinanceWithdrawException
  import pytest
  import requests_mock
  
  
  client = Client('api_key', 'api_secret')
  
  
  def test_invalid_json():
      """Test Invalid response Exception"""
  
      with pytest.raises(BinanceRequestException):
          with requests_mock.mock() as m:
              m.get('https://www.binance.com/exchange/public/product', text='<head></html>')
              client.get_products()
  
  
  def test_api_exception():
      """Test API response Exception"""
  
      with pytest.raises(BinanceAPIException):
          with requests_mock.mock() as m:
              json_obj = {"code": 1002, "msg": "Invalid API call"}
              m.get('https://www.binance.com/api/v1/time', json=json_obj, status_code=400)
              client.get_server_time()
  
+ 
+ def test_withdraw_api_exception():
+     """Test Withdraw API response Exception"""
+ 
+     with pytest.raises(BinanceWithdrawException):
+ 
+         with requests_mock.mock() as m:
+             json_obj = {"success": False, "msg": "Insufficient funds"}
+             m.register_uri('POST', requests_mock.ANY, json=json_obj, status_code=200)
+             client.withdraw(asset='BTC', address='BTCADDRESS', amount=100)
+ 
Add test for withdraw exception response
## Code Before:

from binance.client import Client
from binance.exceptions import BinanceAPIException, BinanceRequestException
import pytest
import requests_mock


client = Client('api_key', 'api_secret')


def test_invalid_json():
    """Test Invalid response Exception"""

    with pytest.raises(BinanceRequestException):
        with requests_mock.mock() as m:
            m.get('https://www.binance.com/exchange/public/product', text='<head></html>')
            client.get_products()


def test_api_exception():
    """Test API response Exception"""

    with pytest.raises(BinanceAPIException):
        with requests_mock.mock() as m:
            json_obj = {"code": 1002, "msg": "Invalid API call"}
            m.get('https://www.binance.com/api/v1/time', json=json_obj, status_code=400)
            client.get_server_time()

## Instruction:
Add test for withdraw exception response
## Code After:

from binance.client import Client
from binance.exceptions import BinanceAPIException, BinanceRequestException, BinanceWithdrawException
import pytest
import requests_mock


client = Client('api_key', 'api_secret')


def test_invalid_json():
    """Test Invalid response Exception"""

    with pytest.raises(BinanceRequestException):
        with requests_mock.mock() as m:
            m.get('https://www.binance.com/exchange/public/product', text='<head></html>')
            client.get_products()


def test_api_exception():
    """Test API response Exception"""

    with pytest.raises(BinanceAPIException):
        with requests_mock.mock() as m:
            json_obj = {"code": 1002, "msg": "Invalid API call"}
            m.get('https://www.binance.com/api/v1/time', json=json_obj, status_code=400)
            client.get_server_time()


def test_withdraw_api_exception():
    """Test Withdraw API response Exception"""

    with pytest.raises(BinanceWithdrawException):

        with requests_mock.mock() as m:
            json_obj = {"success": False, "msg": "Insufficient funds"}
            m.register_uri('POST', requests_mock.ANY, json=json_obj, status_code=200)
            client.withdraw(asset='BTC', address='BTCADDRESS', amount=100)
