From a9abc455f3576dfa0079e8bc0bdb2652868acce2 Mon Sep 17 00:00:00 2001 From: Shane Fontaine Date: Fri, 28 Dec 2018 20:10:46 -0800 Subject: [PATCH] Add get_books test --- test/test_public_client.py | 89 +++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/test/test_public_client.py b/test/test_public_client.py index 6ab9102..4e56a3a 100644 --- a/test/test_public_client.py +++ b/test/test_public_client.py @@ -16,16 +16,19 @@ class TestPublicClient(object): def teardown_method(): time.sleep(.5) # Avoid rate limit + @pytest.mark.skip def test_get_platform_status(self, client): r = client.get_platform_status() assert type(r) is list + @pytest.mark.skip @pytest.mark.parametrize('pair', ['tBTCUSD', 'tETHBTC']) def test_get_ticker(self, client, pair): r = client.get_ticker(pair) assert type(r) is list assert len(r) is 10 + @pytest.mark.skip @pytest.mark.parametrize('pair, limit, start, end, sort', [ ('tBTCUSD', 120, None, None, 0), ('tBTCUSD', 120, 1514764800000, 1514765700000, 0), @@ -55,49 +58,45 @@ def test_get_trades(self, client, pair, limit, start, end, sort): else: assert r[0][1] >= r[1][1] + @pytest.mark.parametrize('pair, precision, length', [ + ('tBTCUSD', 'P0', None), + ('tBTCUSD', 'P0', 25), + ('tBTCUSD', 'P0', 100), + ('tBTCUSD', 'P4', None), + ('tBTCUSD', 'P1', 25), + ('tBTCUSD', 'P2', 25), + pytest.param('tBTCUSD', 'P2', 5, + marks=pytest.mark.xfail), + pytest.param('tBTCUSD', None, 5, + marks=pytest.mark.xfail), + ]) + def test_get_books(self, client, pair, precision, length): + r = client.get_books(pair, precision, length) + + # Default length is 50. Returns double the amount + length = 50 if not length else length * 2 + + # Check length + assert len(r) == length - # if level is 1: - # ass - # pytest.fail('Fail: Level 1 should only return the best ask and bid') - # - # if level is 2 and (len(r['asks']) > 50 or len(r['bids']) > 50): - # pytest.fail('Fail: Level 2 should only return the top 50 asks and bids') - # - # if level is 3 and (len(r['asks']) < 50 or len(r['bids']) < 50): - # pytest.fail('Fail: Level 3 should return the full order book') - # def test_get_product_ticker(self, client): - # r = client.get_product_ticker('BTC-USD') - # assert type(r) is dict - # assert 'ask' in r - # assert 'trade_id' in r - # - # def test_get_product_trades(self, client): - # r = list(islice(client.get_product_trades('BTC-USD'), 200)) - # assert type(r) is list - # assert 'trade_id' in r[0] - # - # current_time = datetime.datetime.now() - # - # @pytest.mark.parametrize('start,end,granularity', - # [(current_time - relativedelta(months=1), - # current_time, 21600)]) - # def test_get_historic_rates(self, client, start, end, granularity): - # r = client.get_product_historic_rates('BTC-USD', start=start, end=end, granularity=granularity) - # assert type(r) is list - # for ticker in r: - # assert( all( [type(x) in (int, float) for x in ticker ] ) ) - # - # def test_get_product_24hr_stats(self, client): - # r = client.get_product_24hr_stats('BTC-USD') - # assert type(r) is dict - # assert 'volume_30day' in r - # - # def test_get_currencies(self, client): - # r = client.get_currencies() - # assert type(r) is list - # assert 'name' in r[0] - # - # def test_get_time(self, client): - # r = client.get_time() - # assert type(r) is dict - # assert 'iso' in r \ No newline at end of file + # Check Precision + price = str(r[0][0]) + if precision == 'P0': + digits = len(price.split(".")[1]) + assert digits == 1 + elif precision == 'P1': + assert len(price) == 4 + elif precision == 'P2': + assert len(price) == 4 + assert price[-1] == '0' + elif precision == 'P3': + assert len(price) == 4 + assert price[-1] == '0' + assert price[-2] == '0' + elif precision == 'P4': + assert len(price) == 4 + assert price[-1] == '0' + assert price[-2] == '0' + assert price[-3] == '0' + elif precision == 'R0': + assert len(price == 11)