Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
50 lines (34 loc) · 1.6 KB

File metadata and controls

50 lines (34 loc) · 1.6 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
# coding=utf-8
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://api.binance.com/api/v1/time', json=json_obj, status_code=400)
client.get_server_time()
def test_api_exception_invalid_json():
"""Test API response Exception"""
with pytest.raises(BinanceAPIException):
with requests_mock.mock() as m:
not_json_str = "<html><body>Error</body></html>"
m.get('https://api.binance.com/api/v1/time', text=not_json_str, 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.