From 9dbfbcbdbb0d78ced80f38f060c1003963fd874f Mon Sep 17 00:00:00 2001 From: Cameron Yick Date: Sun, 24 Dec 2017 13:19:03 -0500 Subject: [PATCH] Fix #44: Raise explicit error when API Key is missing --- tests/test_tiingo.py | 11 +++++++++++ tiingo/api.py | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/test_tiingo.py b/tests/test_tiingo.py index 26977e5..a2c91f2 100644 --- a/tests/test_tiingo.py +++ b/tests/test_tiingo.py @@ -25,6 +25,17 @@ def test_client_repr(): assert repr(client) == "".format(base_url) +class TestClient(TestCase): + + def test_api_key_missing_error(self): + config = { + 'api_key': "" + } + with self.assertRaises(RuntimeError): + client = TiingoClient(config=config) + assert client + + # PRICES ENDPOINTS class TestTickerPrices(TestCase): diff --git a/tiingo/api.py b/tiingo/api.py index 2a63e0c..2e2f200 100644 --- a/tiingo/api.py +++ b/tiingo/api.py @@ -60,7 +60,10 @@ class TiingoClient(RestClient): api_key = self._config['api_key'] except KeyError: api_key = os.environ.get('TIINGO_API_KEY') - assert(api_key) + + if not(api_key): + raise RuntimeError("Tiingo API Key not provided. Please provide" + " via environment variable or config argument.") self._headers = { 'Authorization': "Token {}".format(api_key),