mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 13:01:38 +00:00
* fix show version * update login prompt and account * update set preference * fix account controller * block login/logout if not called from account * change conditions to start terminal * fix required args account model * add not to login command * pylint * accounte controller messages * set default user when logout * logout then show menu * remove unused functions * fix logging bug * ruff * fix account unittests * fix session unittests * refactor colors preference * no theme, no party * add colors sync * dynamic theme * add comment * add colors to settings * ruff * linting * update menu desc * adjust keys sync flag * write to dotenv sync flag * english * fix pull command * fix edge cases * handle some errors * small bug * change func name * pylint * no light * colors preview * ruff * fix login logout preferences * ruff * delete folder * pylint * default, custom, hub * fix clear * docstring * add preference exceptions * set only rich style * request theme only if hub * linting * change guest msg * add option to update chart style on the fly * apply style * rollback to old terminal style * fix console theme * remove print * remove hub rich style * ruff * mypy * black * Hub | Add sources sync (#4565) * Add sources model * adapt session model * fetch sources dict * rename local funcs * set sources inside current user * set sources inside current user * generate sources dict from hub * fix dict generator * send request to hub * fix conflict * revert datasources to develop head * fix docstring * avoid invalid patch types * add default option to sources * fix small bug on sources * ruff * black * remove ( * mypy failing only on git * ignore mypy * pylint * fix settings controller * Tests: fix keys model writing to .env * fix keys controller test writing to .env * ruff * Test: fix account controller * Test: fix account controller pull * Tests: fix launch terminal * Test: add sources to user object * Tests: fix clear cmd tests * ruff * revert core/sdk changes * TerminalStyle docstring * upload config docstring * remove comment * remove unecessary pylint disable * revert openbb_terminal/sdk changes * Terminal style docstring * docstring * remove unecessary changes * add TODO * add other todo * Tests: prevent sync from being written in .env * change clear msg * display sources source on menu * update settings controller * display keys source * black * sync not needed for pull * remove sync from apply configs * change func name for consistency * Update test_keys_model.py * save rich style in user folder * search recursively inside styles * set hub theme by default * remove debug print * allow any plot style * comment plotstyle sync for now * fix sources set terminal to hub * ruff * rewrite cassettes * remove repeated settings * rewrite expected
122 lines
4.2 KiB
Python
122 lines
4.2 KiB
Python
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from openbb_terminal import terminal_controller
|
|
from openbb_terminal.core.session import session_controller
|
|
|
|
|
|
@pytest.mark.record_stdout
|
|
def test_display_welcome_message():
|
|
session_controller.display_welcome_message()
|
|
|
|
|
|
@pytest.mark.record_stdout
|
|
@patch("openbb_terminal.core.session.session_controller.PromptSession")
|
|
def test_get_user_input(mock_prompt_session):
|
|
mock_prompt_session().prompt.side_effect = ["test@example.com", "password", "n"]
|
|
|
|
result = session_controller.get_user_input()
|
|
|
|
assert result == ("test@example.com", "password", False)
|
|
|
|
|
|
@pytest.mark.record_stdout
|
|
@patch("openbb_terminal.core.session.session_controller.PromptSession")
|
|
def test_get_user_input_with_save(mock_prompt_session):
|
|
mock_prompt_session().prompt.side_effect = ["test@example.com", "password", "y"]
|
|
|
|
result = session_controller.get_user_input()
|
|
|
|
assert result == ("test@example.com", "password", True)
|
|
|
|
|
|
def test_prompt():
|
|
with patch(
|
|
"openbb_terminal.core.session.session_controller.get_user_input",
|
|
return_value=("email", "password", False),
|
|
) as get_user_input_mock, patch(
|
|
"openbb_terminal.core.session.session_controller.create_session",
|
|
return_value={"session": "session"},
|
|
) as create_session_mock, patch(
|
|
"openbb_terminal.core.session.session_controller.login_and_launch",
|
|
return_value=True,
|
|
):
|
|
session_controller.prompt()
|
|
assert get_user_input_mock.call_count == 1
|
|
create_session_mock.assert_called_once_with("email", "password", False)
|
|
assert create_session_mock.call_count == 1
|
|
|
|
|
|
def test_launch_terminal(mocker):
|
|
parse_args_mock = mocker.patch.object(
|
|
target=terminal_controller,
|
|
attribute="parse_args_and_run",
|
|
new=MagicMock(),
|
|
)
|
|
session_controller.launch_terminal()
|
|
assert parse_args_mock.call_count == 1
|
|
|
|
|
|
def test_login_and_launch():
|
|
with patch(
|
|
"openbb_terminal.core.session.session_controller.login",
|
|
return_value=session_controller.LoginStatus.SUCCESS,
|
|
) as login_mock, patch(
|
|
"openbb_terminal.core.session.session_controller.launch_terminal",
|
|
return_value=True,
|
|
) as launch_terminal_mock:
|
|
session_controller.login_and_launch(session={})
|
|
assert login_mock.call_count == 1
|
|
assert launch_terminal_mock.call_count == 1
|
|
|
|
|
|
def test_login_and_launch_failed():
|
|
with patch(
|
|
"openbb_terminal.core.session.session_controller.login",
|
|
return_value=session_controller.LoginStatus.FAILED,
|
|
) as login_mock, patch(
|
|
"openbb_terminal.core.session.session_controller.prompt", return_value=True
|
|
) as prompt_mock:
|
|
session_controller.login_and_launch(session={})
|
|
assert login_mock.call_count == 1
|
|
assert prompt_mock.call_count == 1
|
|
|
|
|
|
@pytest.mark.skip(reason="To review")
|
|
def test_login_and_launch_no_response():
|
|
with patch(
|
|
"openbb_terminal.core.session.session_controller.login",
|
|
return_value=session_controller.LoginStatus.NO_RESPONSE,
|
|
) as login_mock, patch(
|
|
"openbb_terminal.core.session.session_controller.prompt", return_value=True
|
|
) as prompt_mock:
|
|
session_controller.login_and_launch(session={})
|
|
assert login_mock.call_count == 1
|
|
assert prompt_mock.call_count == 1
|
|
|
|
|
|
def test_main_local_session():
|
|
with patch(
|
|
"openbb_terminal.core.session.session_controller.prompt", return_value=True
|
|
) as prompt_mock, patch(
|
|
"openbb_terminal.core.session.session_controller.Local.get_session",
|
|
return_value=False,
|
|
) as get_session_mock:
|
|
session_controller.main()
|
|
assert prompt_mock.call_count == 1
|
|
assert get_session_mock.call_count == 1
|
|
|
|
|
|
def test_main_no_local_session():
|
|
with patch(
|
|
"openbb_terminal.core.session.session_controller.login_and_launch",
|
|
return_value=True,
|
|
) as login_and_launch_mock, patch(
|
|
"openbb_terminal.core.session.session_controller.Local.get_session",
|
|
return_value=True,
|
|
) as get_session_mock:
|
|
session_controller.main()
|
|
assert login_and_launch_mock.call_count == 1
|
|
assert get_session_mock.call_count == 1
|