mirror of
https://github.com/hydrosquall/tiingo-python.git
synced 2025-12-18 04:14:20 +01:00
Fix #44: Raise explicit error when API Key is missing
This commit is contained in:
committed by
Cameron Yick
parent
e80b3f6dfd
commit
9dbfbcbdbb
@@ -25,6 +25,17 @@ def test_client_repr():
|
|||||||
assert repr(client) == "<TiingoClient(url=\"{}\")>".format(base_url)
|
assert repr(client) == "<TiingoClient(url=\"{}\")>".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
|
# PRICES ENDPOINTS
|
||||||
class TestTickerPrices(TestCase):
|
class TestTickerPrices(TestCase):
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,10 @@ class TiingoClient(RestClient):
|
|||||||
api_key = self._config['api_key']
|
api_key = self._config['api_key']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
api_key = os.environ.get('TIINGO_API_KEY')
|
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 = {
|
self._headers = {
|
||||||
'Authorization': "Token {}".format(api_key),
|
'Authorization': "Token {}".format(api_key),
|
||||||
|
|||||||
Reference in New Issue
Block a user