mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-29 05:21:48 +00:00
Terminal/hub QA (#4678)
* move update flair * sort repr * remove packaged sys model var * update decorator for check api key * ruff * change if stat * ruff * no need for new var * pylint
This commit is contained in:
@@ -11,7 +11,7 @@ class BaseModel:
|
||||
def __repr__(self) -> str:
|
||||
"""Return string representation of model."""
|
||||
dataclass_repr = ""
|
||||
for key, value in self.__dict__.items():
|
||||
for key, value in sorted(self.__dict__.items()):
|
||||
if key.startswith("_"):
|
||||
continue
|
||||
dataclass_repr += f" {key}='{value}', \n"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import platform
|
||||
import sys
|
||||
from typing import Literal
|
||||
|
||||
from pydantic.dataclasses import dataclass
|
||||
@@ -28,7 +27,6 @@ class SystemModel(BaseModel):
|
||||
|
||||
# OpenBB section
|
||||
VERSION = "3.0.0rc1"
|
||||
PACKAGED: bool = getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS")
|
||||
|
||||
# Logging section
|
||||
LOGGING_APP_NAME: str = "gst"
|
||||
|
||||
@@ -10,6 +10,7 @@ from openbb_terminal.core.config.paths import (
|
||||
)
|
||||
from openbb_terminal.core.session.current_user import (
|
||||
get_current_user,
|
||||
get_env_dict,
|
||||
set_credential,
|
||||
set_preference,
|
||||
set_sources,
|
||||
@@ -113,6 +114,14 @@ def remove_cli_history_file(file_path: Path = HIST_FILE_PATH) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def update_flair():
|
||||
"""Update the flair."""
|
||||
if "FLAIR" not in get_env_dict():
|
||||
MAX_FLAIR_LEN = 20
|
||||
flair = "[" + get_current_user().profile.username[:MAX_FLAIR_LEN] + "]" + " 🦋"
|
||||
set_preference("FLAIR", flair)
|
||||
|
||||
|
||||
def apply_configs(configs: dict):
|
||||
"""Apply configurations.
|
||||
|
||||
|
||||
@@ -49,10 +49,7 @@ def get_user_input() -> Tuple[str, str, bool]:
|
||||
message="> Password: ",
|
||||
is_password=True,
|
||||
)
|
||||
save_str = s.prompt(message="> Remember me? (y/n): ", is_password=False).lower()
|
||||
save = False
|
||||
if save_str == "y":
|
||||
save = True
|
||||
save = s.prompt(message="> Remember me? (y/n): ", is_password=False).lower() == "y"
|
||||
|
||||
return email, password, save
|
||||
|
||||
|
||||
@@ -16,10 +16,8 @@ from openbb_terminal.core.models.user_model import (
|
||||
)
|
||||
from openbb_terminal.core.session.current_user import (
|
||||
get_current_user,
|
||||
get_env_dict,
|
||||
set_current_user,
|
||||
set_default_user,
|
||||
set_preference,
|
||||
)
|
||||
from openbb_terminal.helper_funcs import system_clear
|
||||
from openbb_terminal.loggers import setup_logging
|
||||
@@ -94,10 +92,7 @@ def login(session: dict) -> LoginStatus:
|
||||
hub_user.profile.load_user_info(session, email)
|
||||
set_current_user(hub_user)
|
||||
Local.apply_configs(configs=configs)
|
||||
if "FLAIR" not in get_env_dict():
|
||||
MAX_FLAIR_LEN = 20
|
||||
flair = "[" + hub_user.profile.username[:MAX_FLAIR_LEN] + "]" + " 🦋"
|
||||
set_preference("FLAIR", flair)
|
||||
Local.update_flair()
|
||||
return LoginStatus.SUCCESS
|
||||
if response.status_code == 401:
|
||||
return LoginStatus.UNAUTHORIZED
|
||||
|
||||
@@ -137,7 +137,7 @@ def check_api_key(api_keys):
|
||||
undefined_apis_name = ", ".join(undefined_apis)
|
||||
console.print(
|
||||
f"[red]{undefined_apis_name} not defined. "
|
||||
"Set API Keys in ~/.openbb_terminal/.env or under keys menu.[/red]"
|
||||
"Set the API key under keys menu.[/red]"
|
||||
) # pragma: allowlist secret
|
||||
return None
|
||||
return func(*args, **kwargs)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
"""Main helper."""
|
||||
__docformat__ = "numpy"
|
||||
|
||||
# pylint: disable=unsupported-assignment-operation,too-many-lines
|
||||
# pylint: disable=no-member,too-many-branches,too-many-arguments
|
||||
# pylint: disable=unsupported-assignment-operation, too-many-lines
|
||||
# pylint: disable=no-member, too-many-branches, too-many-arguments
|
||||
# pylint: disable=inconsistent-return-statements
|
||||
# pylint: disable=consider-using-dict-items
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ def test_login_no_response(mocker):
|
||||
path = "openbb_terminal.core.session.session_model."
|
||||
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 + "Local.update_flair")
|
||||
|
||||
mock_fetch_user_configs.return_value = None
|
||||
|
||||
@@ -71,12 +72,14 @@ def test_login_no_response(mocker):
|
||||
|
||||
mock_fetch_user_configs.assert_called_once_with(TEST_SESSION)
|
||||
mock_apply_configs.assert_not_called()
|
||||
mock_update_flair.assert_not_called()
|
||||
|
||||
|
||||
def test_login_fail_response(mocker):
|
||||
path = "openbb_terminal.core.session.session_model."
|
||||
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 + "Local.update_flair")
|
||||
|
||||
response = Response()
|
||||
response.status_code = 400
|
||||
@@ -86,12 +89,14 @@ def test_login_fail_response(mocker):
|
||||
|
||||
mock_fetch_user_configs.assert_called_once_with(TEST_SESSION)
|
||||
mock_apply_configs.assert_not_called()
|
||||
mock_update_flair.assert_not_called()
|
||||
|
||||
|
||||
def test_login_success_response(mocker):
|
||||
path = "openbb_terminal.core.session.session_model."
|
||||
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 + "Local.update_flair")
|
||||
|
||||
response = Response()
|
||||
response.status_code = 200
|
||||
@@ -104,6 +109,7 @@ def test_login_success_response(mocker):
|
||||
|
||||
mock_fetch_user_configs.assert_called_once_with(TEST_SESSION)
|
||||
mock_apply_configs.assert_called_once()
|
||||
mock_update_flair.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
Reference in New Issue
Block a user