FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-binance/tests/test_api_request.py at master · EncodingJerry/python-binance · GitHub
EncodingJerry
/
python-binance
Public
forked from
kbai/python-binance
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-binance
/
tests
/
test_api_request.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (34 loc) · 1.6 KB
Breadcrumbs
python-binance
/
tests
/
test_api_request.py
Copy path
File metadata and controls
50 lines (34 loc) · 1.6 KB
Raw
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
)
Back
|
FazBrowse Home
|
New Git URL