| 13 | |
| 14 | @pytest.mark.usefixtures('client') |
| 15 | class TestPublicClient(object): |
| 16 | |
| 17 | @staticmethod |
| 18 | def teardown_method(): |
| 19 | time.sleep(.25) # Avoid rate limit |
| 20 | |
| 21 | def test_get_products(self, client): |
| 22 | r = client.get_products() |
| 23 | assert type(r) is list |
| 24 | |
| 25 | @pytest.mark.parametrize('level', [1, 2, 3, None]) |
| 26 | def test_get_product_order_book(self, client, level): |
| 27 | r = client.get_product_order_book('BTC-USD', level=level) |
| 28 | assert type(r) is dict |
| 29 | assert 'asks' in r |
| 30 | assert 'bids' in r |
| 31 | |
| 32 | if level in (1, None) and (len(r['asks']) > 1 or len(r['bids']) > 1): |
| 33 | pytest.fail('Fail: Level 1 should only return the best ask and bid') |
| 34 | |
| 35 | if level is 2 and (len(r['asks']) > 50 or len(r['bids']) > 50): |
| 36 | pytest.fail('Fail: Level 2 should only return the top 50 asks and bids') |
| 37 | |
| 38 | if level is 3 and (len(r['asks']) < 50 or len(r['bids']) < 50): |
| 39 | pytest.fail('Fail: Level 3 should return the full order book') |
| 40 | |
| 41 | def test_get_product_ticker(self, client): |
| 42 | r = client.get_product_ticker('BTC-USD') |
| 43 | assert type(r) is dict |
| 44 | assert 'ask' in r |
| 45 | assert 'trade_id' in r |
| 46 | |
| 47 | def test_get_product_trades(self, client): |
| 48 | r = list(islice(client.get_product_trades('BTC-USD'), 200)) |
| 49 | assert type(r) is list |
| 50 | assert 'trade_id' in r[0] |
| 51 | |
| 52 | current_time = datetime.datetime.now() |
| 53 | |
| 54 | @pytest.mark.parametrize('start,end,granularity', |
| 55 | [(current_time - relativedelta(months=1), |
| 56 | current_time, 21600)]) |
| 57 | def test_get_historic_rates(self, client, start, end, granularity): |
| 58 | r = client.get_product_historic_rates('BTC-USD', start=start, end=end, granularity=granularity) |
| 59 | assert type(r) is list |
| 60 | for ticker in r: |
| 61 | assert( all( [type(x) in (int, float) for x in ticker ] ) ) |
| 62 | |
| 63 | def test_get_product_24hr_stats(self, client): |
| 64 | r = client.get_product_24hr_stats('BTC-USD') |
| 65 | assert type(r) is dict |
| 66 | assert 'volume_30day' in r |
| 67 | |
| 68 | def test_get_currencies(self, client): |
| 69 | r = client.get_currencies() |
| 70 | assert type(r) is list |
| 71 | assert 'name' in r[0] |
| 72 |
nothing calls this directly
no outgoing calls
no test coverage detected