Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminal/hub QA #4678

Merged
merged 10 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openbb_terminal/core/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions openbb_terminal/core/models/system_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import platform
import sys
from typing import Literal

from pydantic.dataclasses import dataclass
Expand Down Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions openbb_terminal/core/session/local_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
)
from openbb_terminal.core.session.current_user import (
get_current_user,
get_env_dict,
set_credential,
set_preference,
set_sources,
Expand Down Expand Up @@ -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.

Expand Down
5 changes: 1 addition & 4 deletions openbb_terminal/core/session/session_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 1 addition & 6 deletions openbb_terminal/core/session/session_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
)
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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion openbb_terminal/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def wrapper_decorator(*args, **kwargs):
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)
Expand Down
4 changes: 2 additions & 2 deletions openbb_terminal/stocks/stocks_helper.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 6 additions & 0 deletions tests/openbb_terminal/session/test_session_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,22 @@ 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

assert session_model.login(TEST_SESSION) == session_model.LoginStatus.NO_RESPONSE

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
Expand All @@ -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
Expand All @@ -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(
Expand Down