Files
OpenBB/tests/openbb_terminal/test_keys_controller.py
DidierRLopes f1a824a179 Add tweet news in terminal toolbar (#3757)
* Add tweet news in terminal toolbar

* allow to store tweet news settings

* update dependencies

* Add tweet news in terminal toolbar

* lint

* dependencies

* 5s timeout for twitter api

* poetry update for resolve

* reqs

* set news to false by default

* update tweepy

* update reqs

* update reqs again?

* update setuptools

* small improv

* Add tweet news in terminal toolbar

* update packages

* black linting

* black formatting

* ruff fixes

* fix settings controller

* Reqs

* fix tz issue

* add keywords selection

* linting

* helper funcs mypy

* pylint fixes

* Checkout poetry.lock + pyproject.toml

* Update dependencies

* Remove integration test file

* News Toolbar : Fix bugs

* Tests : News Toolbar

* Update dependencies

* Tests : change variable name

* Remove unused keys

* Remove unecessary global variable

* Fix linting

* Lighter API call

* Ruff

* Linting + Remove keys

* Linting

* Dotenv loading issue.

* Ruff

* Revert "Dotenv loading issue."

This reverts commit 4493f1a3e7.

* Tests : fix

* Tests : fix test_settings_controller.py

* Twitter Toolbar : avoid checking API when not enabled

* Tests : news toolbar

---------

Co-authored-by: James Maslek <jmaslek11@gmail.com>
Co-authored-by: Chavithra PARANA <chavithra@gmail.com>
2023-02-23 13:22:22 +01:00

252 lines
7.6 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_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_MESSARI_KEY = kwargs.get("MESSARI", None)
self.API_SANTIMENT_KEY = kwargs.get("SANTIMENT", None)
self.API_TOKENTERMINAL_KEY = kwargs.get("TOKENTERMINAL", None)
self.API_SHROOM_KEY = kwargs.get("SHROOM", None)
@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", [[], ["-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", "-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"], ["1234"]])
def test_call_santiment(other):
controller.call_santiment(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", "-t", "456"]])
def test_call_tokenterminal(other):
controller.call_tokenterminal(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234", "-t", "456"]])
def test_call_shroom(other):
controller.call_shroom(other)
@pytest.mark.vcr
@pytest.mark.parametrize("other", [[], ["-k", "1234", "-t", "456"]])
def test_call_openbb(mocker, other):
# MOCK GET
attrs = {
"status_code": 200,
"json.return_value": {"token": "MOCK_TOKEN"},
}
mock_response = mocker.Mock(**attrs)
mocker.patch(
target="openbb_terminal.keys_model.request",
new=mocker.Mock(return_value=mock_response),
)
controller.call_openbb(other)