mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 21:12:16 +00:00
* implement user and change is guest * replace User methods * move remaining functions to user * fix bug * portfolio test * fix tests * fix tests * uncomment skip * ruff * start credentials model implementation * change deault structure * refacto quandl * change default struct and file names * bug * start using global user * add comments * move update flair * change cfg references in keys model * reddit & fmp * refactore additional keys * remaing config keys * remove unsude imports and fix hub keys * ruff * fix line too long * unblock unittests * fix keys model tests * remove os patch * fix account controller tests * fix account controller tests * fix account model * account fixed * fix user tests * User Model * User Model * User Model * Move session folder * User Model : grouping the models * User Model : fix bugs * Config Plot + bug fix * User Model : Refactoring plots * Feature flags * Remove dup * clean comments a fix some vars * fix feature flags controller * refactor obbff from settings controller * refactor a bunch of obbff variables * fix bug blocking terminal * fix integration tests * refactor controllers with obbff * refactor remaining ffs * remove comments * log not started * mispelled variable * set current user on local model * User Model : moving files + updating * User Preferences * User : Refactor is_guest function + bug fix * User : refactor is_guest function * Fix conftest.py * remove lost obbffs * typo on fileoverwrite * Plot config: move variables and start plot dpi * User : tests * refactor plot dpi references * remove plot dpi imports * refactor some config terminal leftover * /account/sync : fix bug * remove configs reload * start path refactor * installation paths vs user paths * remove cfg_plot * Tests : User Refactoring * user prefix only for preferences * user prefix only for preferences * move user paths * remove comment * update apply remote configs * fix tz not updating * save some copys * small fix * create interface for credentials and preferences * wrong docstrings fixed * ruff core * fix some pref setting * login is better * ruff * ruff * remove Literal * add small comment * Tests : User Refactoring * Credentials Model : add DataBento * Fix helper_funcs * Fixing code * Tests : fixing * User Model : freezing the models * Fixed Income + Databento * Tests : fixing keys * black * ruff * Tests : user model * Tests : user model * Fix linting * Fix linting * Linting * Linting * Fixing code and tests * Fix tests * mypy * SDK * Clean ruff cache * Fix syntax issue * Update fred_view * Black * Linting * Update code * Update tests * Linting * Linting * Tests * Black * Linting * Linting * Mock os.listdir to avoid looking for file that doesnt exist * Mock options paths * lint * Tests : fix * Code : update * Tests + Linting * Tests * Ruff * Code : update * Tests * Code : update * Fix workflow * Code : update --------- Co-authored-by: Chavithra PARANA <chavithra@gmail.com> Co-authored-by: luqazino@gmail.com <luqazino@gmail.com> Co-authored-by: James Maslek <jmaslek11@gmail.com>
166 lines
5.4 KiB
Python
166 lines
5.4 KiB
Python
# IMPORTATION STANDARD
|
|
|
|
# IMPORTATION THIRDPARTY
|
|
import json
|
|
|
|
import pytest
|
|
from requests import Response
|
|
|
|
# IMPORTATION INTERNAL
|
|
from openbb_terminal.core.session import session_model
|
|
|
|
TEST_SESSION = {
|
|
"access_token": "test_token",
|
|
"token_type": "bearer",
|
|
"uuid": "test_uuid",
|
|
}
|
|
|
|
CONFIGS = {
|
|
"features_settings": {
|
|
"USE_WATERMARK": "False",
|
|
"TIMEZONE": "Europe/London",
|
|
"PLOT_DPI": "95",
|
|
"PLOT_HEIGHT_PERCENTAGE": "50.5",
|
|
"USER_DATA_DIRECTORY": "some/path/to/user/data",
|
|
},
|
|
"features_keys": {
|
|
"API_KEY_ALPHAVANTAGE": "test_av",
|
|
"API_FRED_KEY": "test_fred",
|
|
},
|
|
}
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"email, password, save",
|
|
[
|
|
(
|
|
"test_email",
|
|
"test_pass",
|
|
False,
|
|
),
|
|
(
|
|
"test_email",
|
|
"test_pass",
|
|
True,
|
|
),
|
|
],
|
|
)
|
|
def test_create_session(mocker, email, password, save):
|
|
path = "openbb_terminal.core.session.session_model."
|
|
mock_get_session = mocker.patch(path + "Hub.get_session")
|
|
mock_save_session = mocker.patch(path + "Local.save_session")
|
|
|
|
mock_get_session.return_value = TEST_SESSION
|
|
session = session_model.create_session(email, password, save)
|
|
|
|
assert session == TEST_SESSION
|
|
|
|
mock_get_session.assert_called_once_with(email, password)
|
|
if save and session:
|
|
mock_save_session.assert_called_once_with(session)
|
|
|
|
|
|
@pytest.mark.skip("Not working?")
|
|
def test_login_no_response(mocker):
|
|
path = "openbb_terminal.core.session.session_model."
|
|
mock_clear_openbb_env_vars = mocker.patch(path + "clear_openbb_env_vars")
|
|
mock_reload_openbb_config_modules = mocker.patch(
|
|
path + "reload_openbb_config_modules"
|
|
)
|
|
mock_fetch_user_configs = mocker.patch(path + "Hub.fetch_user_configs")
|
|
mock_apply_configs = mocker.patch(path + "Local.apply_configs")
|
|
mock_update_flair = mocker.patch(path + "update_flair")
|
|
|
|
mock_fetch_user_configs.return_value = None
|
|
|
|
assert session_model.login(TEST_SESSION) == session_model.LoginStatus.NO_RESPONSE
|
|
|
|
mock_clear_openbb_env_vars.assert_called_once()
|
|
mock_reload_openbb_config_modules.assert_called_once()
|
|
mock_fetch_user_configs.assert_called_once_with(TEST_SESSION)
|
|
mock_apply_configs.assert_not_called()
|
|
mock_update_flair.assert_not_called()
|
|
|
|
|
|
@pytest.mark.skip("Not working?")
|
|
def test_login_fail_response(mocker):
|
|
path = "openbb_terminal.core.session.session_model."
|
|
mock_clear_openbb_env_vars = mocker.patch(path + "clear_openbb_env_vars")
|
|
mock_reload_openbb_config_modules = mocker.patch(
|
|
path + "reload_openbb_config_modules"
|
|
)
|
|
mock_fetch_user_configs = mocker.patch(path + "Hub.fetch_user_configs")
|
|
mock_apply_configs = mocker.patch(path + "Local.apply_configs")
|
|
mock_update_flair = mocker.patch(path + "update_flair")
|
|
|
|
response = Response()
|
|
response.status_code = 400
|
|
mock_fetch_user_configs.return_value = response
|
|
|
|
assert session_model.login(TEST_SESSION) == session_model.LoginStatus.FAILED
|
|
|
|
mock_clear_openbb_env_vars.assert_called_once()
|
|
mock_reload_openbb_config_modules.assert_called_once()
|
|
mock_fetch_user_configs.assert_called_once_with(TEST_SESSION)
|
|
mock_apply_configs.assert_not_called()
|
|
mock_update_flair.assert_not_called()
|
|
|
|
|
|
@pytest.mark.skip("Not working?")
|
|
def test_login_success_response(mocker):
|
|
path = "openbb_terminal.core.session.session_model."
|
|
mock_clear_openbb_env_vars = mocker.patch(path + "clear_openbb_env_vars")
|
|
mock_reload_openbb_config_modules = mocker.patch(
|
|
path + "reload_openbb_config_modules"
|
|
)
|
|
mock_fetch_user_configs = mocker.patch(path + "Hub.fetch_user_configs")
|
|
mock_apply_configs = mocker.patch(path + "Local.apply_configs")
|
|
mock_update_flair = mocker.patch(path + "update_flair")
|
|
|
|
response = Response()
|
|
response.status_code = 200
|
|
response._content = json.dumps(CONFIGS).encode( # pylint: disable=protected-access
|
|
"utf-8"
|
|
)
|
|
mock_fetch_user_configs.return_value = response
|
|
|
|
assert session_model.login(TEST_SESSION) == session_model.LoginStatus.SUCCESS
|
|
|
|
mock_clear_openbb_env_vars.assert_called_once()
|
|
mock_reload_openbb_config_modules.assert_called_once()
|
|
mock_fetch_user_configs.assert_called_once_with(TEST_SESSION)
|
|
mock_apply_configs.assert_called_once()
|
|
mock_update_flair.assert_called_once()
|
|
|
|
|
|
@pytest.mark.skip("Not working?")
|
|
@pytest.mark.parametrize(
|
|
"guest",
|
|
[
|
|
False,
|
|
True,
|
|
],
|
|
)
|
|
def test_logout_user(mocker, guest):
|
|
path = "openbb_terminal.core.session.session_model."
|
|
mock_delete_session = mocker.patch(path + "Hub.delete_session")
|
|
mock_remove_session_file = mocker.patch(path + "Local.remove_session_file")
|
|
mock_remove_cli_history_file = mocker.patch(path + "Local.remove_cli_history_file")
|
|
mock_reload_openbb_config_modules = mocker.patch(
|
|
path + "reload_openbb_config_modules"
|
|
)
|
|
mock_clear_openbb_env_vars = mocker.patch(path + "clear_openbb_env_vars")
|
|
mock_plt_close = mocker.patch(path + "plt.close")
|
|
|
|
auth_header = "Bearer test_token"
|
|
token = "test_token"
|
|
session_model.logout(auth_header, token, guest)
|
|
|
|
if not guest:
|
|
mock_delete_session.assert_called_once_with(auth_header, token)
|
|
mock_remove_session_file.assert_called_once()
|
|
mock_clear_openbb_env_vars.assert_called_once()
|
|
mock_reload_openbb_config_modules.assert_called_once()
|
|
mock_remove_cli_history_file.assert_called_once()
|
|
mock_plt_close.assert_called_once()
|