Files
OpenBB/tests/openbb_terminal/test_keys_controller.py
montezdesousa 732a614937 Allow users to change api keys through OpenBB SDK (#2642)
* set fred keys through api

* linting

* doc change

* expose api keys dict

* allow optional persistency of api key change

* black

* place decorators

* add keys paths

* av and fmp keys

* some fixes

* rewrite av, fmp, fred cassettes

* quandl key

* polygon key

* rewrite polygon cassette

* news and tradier

* cmc key

* change some docstring

* change some docstring

* filtered keys dict on mykeys

* simplify mykeys collection

* revert arg to persist

* finnhub

* iex key

* reddit key

* reddit docstring

* check for prefix before removing

* glassnode key

* glassnode virtual path

* bitquery keys

* twitter key

* robinhood key

* degiro keys

* oanda key

* binance keys

* si key

* coinbase key

* refactor btcrb dates and logic

* walert key

* coinglass key

* regenerate cassettes

* cpanic keys

* ethplorer keys

* replace ouput status failed msg

* smartstake keys

* gitub keys

* messari keys

* eodhd keys

* santiment keys

* remove unused imports

* typo formatting test

* remove forbidden arg

* fix btcrb test

* fix test import

* revert cassette changes

* fix more tests

* fix last failing

* black

* try to change status to int code

* change status to int

* first try at keys controller refactoring

* fix some tests accordingly

* display msg on set

* change some vars

* remove elifs

* add progress bar and remove duplicate key check

* add mykeys and refresh to menu

* remove unused import

* change mykeys output to df

* remove check keys from keys ctrl tests

* update test split to new structure

* reduce duplicate code

* upper case

* change var name

* rename mykeys df cols

* add keys integrations tests

* add mykeys test to keys controller

* fix mykeys

* fix wrong eodhd var name

* pylint

* test_set_key

* black

* patch dotenv kinda

* fix mypy

* remove refresh

* filter mykeys df

* filter mykeys df

* update integration tests

* first unit test for set api key

* add 2 more test cases to fred

* add persist test to fred unittest

* add av unittest

* add polygon unittest

* generate av cassettes

* add unittests av, fmp, quandl, polygon, fred

* change si token to key

* forgot controller func

* unittest: news, tradier, cmc, finnhub, iex, bitquery

* add si unittest

* update eodhd key name

* add unittest: walert, glassnode, coinglass, cpanic, ethplorer, github, messari, eodhd, santiment

* black

* add reddit unittest

* refactor unittests to handle multi args

* regenerate cassettes

* add more unittests

* add degiro, oanda and rh unittest

* generate oanda records

* fix rh and degiro unittest

* fix oanda unittest

* black

* flake8

* fix si controller test

* move tmp

* pylint

* fix av test

* fix fmp key check

* rewrite fmp

* rewrite oanda output

* fix quandl check

* rewrite expected

* supress logger exception

* fix iex cloud key

* remove iex warning

* fix coinglass check key

* cpanic fix

* regenerate cpanic cassettes

* flake8

* fix smartstake keys check

* regenerate expected output

* fix eodhd

* try at binance

* black

* fix controller tests

* pylint

* disable warning

* flake

* add option to show keys

* add Enum to model

* regenerate test output

* update contributing

* flake

* fix type hint

* remove status msg dict

* pylint

* regenerate and remove unecessary cassettes

* remove duplicate return

* supress traceback

* remove unused imports

* update some docstrings

* add todo

* add export option to mykeys

* minor change

* refactor color scheme

* update contributing

* update contributing

* regenerate cassettes

* fix check output

* small msg change

* small details

* rewrite some tests

Co-authored-by: hjoaquim <h.joaquim@campus.fct.unl.pt>
Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com>
2022-10-08 12:30:23 +02:00

239 lines
7.2 KiB
Python

import pytest
from openbb_terminal.keys_controller import KeysController
controller = KeysController(menu_usage=False)
# pylint: disable=R0902,R0903,W1404
@pytest.fixture(autouse=True)
def no_change_env(mocker):
mocker.patch("openbb_terminal.keys_model.dotenv.set_key")
class MockCFG:
def __init__(self, **kwargs):
self.API_GITHUB_KEY = kwargs.get("GITHUB", None)
self.API_KEY_ALPHAVANTAGE = kwargs.get("AV", None)
self.API_KEY_FINANCIALMODELINGPREP = kwargs.get("FMP", None)
self.API_KEY_QUANDL = kwargs.get("QUANDL", None)
self.API_POLYGON_KEY = kwargs.get("POLYGON", None)
self.API_FRED_KEY = kwargs.get("FRED", None)
self.API_NEWS_TOKEN = kwargs.get("NEWS", None)
self.API_TRADIER_TOKEN = kwargs.get("TRADIER", None)
self.API_CMC_KEY = kwargs.get("CMC", None)
self.API_FINNHUB_KEY = kwargs.get("FINNHUB", None)
self.API_IEX_TOKEN = kwargs.get("IEX", None)
self.API_REDDIT_CLIENT_ID = kwargs.get("REDDIT_CLIENT", None)
self.API_REDDIT_CLIENT_SECRET = kwargs.get("REDDIT_SECRET", None)
self.API_REDDIT_USERNAME = kwargs.get("REDDIT_USERNAME", None)
self.API_REDDIT_PASSWORD = kwargs.get("REDDIT_PASSWORD", None)
self.API_REDDIT_USER_AGENT = kwargs.get("REDDIT_USER", None)
self.API_TWITTER_KEY = kwargs.get("TWITTER", None)
self.API_TWITTER_SECRET_KEY = kwargs.get("TWITTER", None)
self.API_TWITTER_BEARER_TOKEN = kwargs.get("TWITTER", None)
self.RH_USERNAME = kwargs.get("RH", None)
self.RH_PASSWORD = kwargs.get("RH", None)
self.DG_USERNAME = kwargs.get("DEGIRO", None)
self.DG_PASSWORD = kwargs.get("DEGIRO", None)
self.DG_TOTP_SECRET = kwargs.get("DEGIRO", None)
self.OANDA_TOKEN = kwargs.get("OANDA", None)
self.OANDA_ACCOUNT = kwargs.get("OANDA", None)
self.API_BINANCE_KEY = kwargs.get("BINANCE", None)
self.API_BINANCE_SECRET = kwargs.get("BINANCE", None)
self.API_BITQUERY_KEY = kwargs.get("BITQUERY", None)
self.API_SENTIMENTINVESTOR_TOKEN = kwargs.get("SI", None)
self.API_COINBASE_KEY = kwargs.get("COINBASE", None)
self.API_COINBASE_SECRET = kwargs.get("COINBASE", None)
self.API_COINBASE_PASS_PHRASE = kwargs.get("COINBASE", None)
self.API_WHALE_ALERT_KEY = kwargs.get("WALERT", None)
self.API_GLASSNODE_KEY = kwargs.get("GLASSNODE", None)
self.API_COINGLASS_KEY = kwargs.get("COINGLASS", None)
self.API_CRYPTO_PANIC_KEY = kwargs.get("CPANIC", None)
self.API_ETHPLORER_KEY = kwargs.get("ETHPLOR", None)
self.API_SMARTSTAKE_TOKEN = kwargs.get("SMARTSTAKE", None)
self.API_SMARTSTAKE_KEY = kwargs.get("SMARTSTAKE", None)
self.API_SANTIMENT_KEY = kwargs.get("SANTIMENT", None)
self.API_MESSARI_KEY = kwargs.get("MESSARI", None)
# TODO: add mykeys test to assert df
# TODO: add refresh test
@pytest.mark.skip
def test_print_help(mocker):
mocker.patch("openbb_terminal.keys_controller.KeysController.check_keys_status")
controller.print_help()
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234"], ["1234"]])
def test_call_av(other):
controller.call_av(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234"], ["1234"]])
def test_call_fmp(other):
controller.call_fmp(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234"], ["1234"]])
def test_call_quandl(other):
controller.call_quandl(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234"], ["1234"]])
def test_call_polygon(other):
controller.call_polygon(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234"], ["1234"]])
def test_call_fred(other):
controller.call_fred(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234"], ["1234"]])
def test_call_news(other):
controller.call_news(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234"], ["1234"]])
def test_call_tradier(other):
controller.call_tradier(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234"], ["1234"]])
def test_call_cmc(other):
controller.call_cmc(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234"]])
def test_call_finnhub(other):
controller.call_finnhub(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234"], ["1234"]])
def test_call_iex(other):
controller.call_iex(other)
@pytest.mark.vcr
@pytest.mark.parametrize(
"other", [[], ["-i", "1234", "-s", "4", "-u", "5", "-p", "6", "-a", "7"]]
)
def test_call_reddit(other):
controller.call_reddit(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234", "-s", "4567", "-t", "890"]])
def test_call_twitter(other):
controller.call_twitter(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-u", "1234", "-p", "4567"]])
def test_call_rh(other):
controller.call_rh(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-u", "1234", "-p" "4567", "-s" "890"]])
def test_call_degiro(other):
controller.call_degiro(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-a", "1234", "-t", "4567", "-at", "practice"]])
def test_call_oanda(other):
controller.call_oanda(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234", "-s", "4567"]])
def test_call_binance(other):
controller.call_binance(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234"], ["1234"]])
def test_call_bitquery(other):
controller.call_bitquery(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234"], ["1234"]])
def test_call_si(other):
controller.call_si(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234", "-s", "4567", "-p" "890"]])
def test_call_coinbase(other):
controller.call_coinbase(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234"], ["1234"]])
def test_call_walert(other):
controller.call_walert(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234"], ["1234"]])
def test_call_glassnode(other):
controller.call_glassnode(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234"], ["1234"]])
def test_call_coinglass(other):
controller.call_coinglass(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234"], ["1234"]])
def test_call_cpanic(other):
controller.call_cpanic(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234"], ["1234"]])
def test_call_ethplorer(other):
controller.call_ethplorer(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234", "-t", "456"]])
def test_call_smartstake(other):
controller.call_smartstake(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234"], ["1234"]])
def test_call_github(other):
controller.call_github(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234", "-t", "456"]])
def test_call_messari(other):
controller.call_messari(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234"], ["1234"]])
def test_call_santiment(other):
controller.call_santiment(other)