From c41baf3ecf4db95ea2a2e3a7bd510552ad280ebd Mon Sep 17 00:00:00 2001 From: mfiro <51599115+mfiro@users.noreply.github.com> Date: Fri, 18 Jun 2021 00:57:56 +0200 Subject: [PATCH] Initial commit for test_client.py: - Add 2 tests (test_get_all_tickers() and test_failed_get_all_tickers()) --- tests/test_client.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/test_client.py diff --git a/tests/test_client.py b/tests/test_client.py new file mode 100644 index 000000000..07eb47d29 --- /dev/null +++ b/tests/test_client.py @@ -0,0 +1,29 @@ +from binance.client import Client +from binance.exceptions import BinanceAPIException, BinanceRequestException +import pytest +import requests_mock + + +@pytest.fixture(scope='module') +def client(): + """setup""" + + client = Client('api_key', 'api_secret') + return client + + +@requests_mock.Mocker(kw='mock') +def test_get_all_tickers(client, **kwargs): + expected_response = [{'symbol': 'ETHBTC', 'price': '0.06675400'}, + {'symbol': 'LTCBTC', 'price': '0.00451500'}] + + kwargs['mock'].get('https://api.binance.com/api/v3/ticker/price', json=expected_response) + returned_value = client.get_all_tickers() + assert returned_value == expected_response + + +@requests_mock.Mocker(kw='mock') +def test_failed_get_all_tickers(client, **kwargs): + with pytest.raises(BinanceAPIException): + kwargs['mock'].get('https://api.binance.com/api/v3/ticker/price', status_code=400) + client.get_all_tickers()