From 3e535ce44b597aa135bfec7da312751bb2750244 Mon Sep 17 00:00:00 2001 From: Lockefox Date: Wed, 27 Sep 2017 11:30:38 -0700 Subject: [PATCH] adding OHLC tests --- tests/helpers.py | 9 ++++ tests/test_coins_prices.py | 90 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/tests/helpers.py b/tests/helpers.py index 04a3c8c..9e4f25c 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -100,6 +100,15 @@ def find_uniques( unique_test = list(set(test_list) - set(expected_list)) print('Unique test vals: {}'.format(unique_test)) + #unique_expected = list(expected_list) + #for key in test_list: + # try: + # unique_expected.remove(key) + # print('removed key: {}'.format(key)) + # except Exception: + # print('key not in expected: {}'.format(key)) + # pass + #print(unique_expected) unique_expected = list(set(expected_list) - set(test_list)) print('Unique expected vals: {}'.format(unique_expected)) diff --git a/tests/test_coins_prices.py b/tests/test_coins_prices.py index 6140762..c93a71d 100644 --- a/tests/test_coins_prices.py +++ b/tests/test_coins_prices.py @@ -189,6 +189,96 @@ def test_get_histo_day_cc_badcoin(self): 'BUTTS', self.limit ) + +class TestGetOHLCCC: + """validate behavior for get_ohlc_cc()""" + coin = 'BTC' + limit = 60 + max_limit = 2001 + expected_headers = [ + 'high', 'open', 'time', 'volumefrom', 'low', 'close', 'volumeto' + ] + + def test_get_ohlc_cc_happypath(self): + """validate expected default behavor for endpoint""" + data = prices.get_ohlc_cc( + self.coin, + self.limit + ) + + assert isinstance(data, pandas.DataFrame) + + unique_values, unique_expected = helpers.find_uniques( + list(data.columns.values), + self.expected_headers + ) + assert unique_expected == [] + if unique_values: + pytest.xfail( + 'Unexpected values from get_ohlc_cc(): {}'.format(unique_values) + ) + + def test_get_ohlc_cc_maxrange(self): + """make sure expected failure for too much data requested""" + requested_limit = self.max_limit + 10 + data = prices.get_ohlc_cc( + self.coin, + requested_limit + ) + if data.shape[0] > self.max_limit: + pytest.xfail('Max limit unexpected. Expected={} Requested={} Returned={}'.format( + self.max_limit, requested_limit, data.shape[0] + )) + + def test_get_ohlc_cc_hours(self): + """request hours data""" + data = prices.get_ohlc_cc( + self.coin, + self.limit, + frequency='hour' + ) + + assert isinstance(data, pandas.DataFrame) + + unique_values, unique_expected = helpers.find_uniques( + list(data.columns.values), + self.expected_headers + ) + assert unique_expected == [] + if unique_values: + pytest.xfail( + 'Unexpected values from get_ohlc_cc(frequency=hour): {}'.format(unique_values) + ) + + def test_get_ohlc_cc_seconds(self): + """request minute data""" + data = prices.get_ohlc_cc( + self.coin, + self.limit, + frequency='minute' + ) + + assert isinstance(data, pandas.DataFrame) + + unique_values, unique_expected = helpers.find_uniques( + list(data.columns.values), + self.expected_headers + ) + assert unique_expected == [] + if unique_values: + pytest.xfail( + 'Unexpected values from get_ohlc_cc(frequency=minute): {}'.format(unique_values) + ) + + def test_get_ohlc_cc_badfreq(self): + """ask for bad frequency""" + with pytest.raises(ValueError): + data = prices.get_ohlc_cc( + self.coin, + self.limit, + frequency='eons' + ) + @flaky def test_get_ticker_single(): """validate get_ticker_hitbtc() returns valid schema"""