diff --git a/openbb_terminal/account/account_controller.py b/openbb_terminal/account/account_controller.py index 6d8bc01fa15b..ac4bcbe58690 100644 --- a/openbb_terminal/account/account_controller.py +++ b/openbb_terminal/account/account_controller.py @@ -5,8 +5,6 @@ from pathlib import Path from typing import Dict, List, Optional -from prompt_toolkit.completion import NestedCompleter - from openbb_terminal import ( keys_model, ) @@ -19,6 +17,7 @@ from openbb_terminal.core.session.current_user import get_current_user, is_local from openbb_terminal.core.session.preferences_handler import set_preference from openbb_terminal.core.session.session_model import logout +from openbb_terminal.custom_prompt_toolkit import NestedCompleter from openbb_terminal.decorators import log_start_end from openbb_terminal.helper_funcs import check_positive from openbb_terminal.menu import session @@ -46,26 +45,29 @@ class AccountController(BaseController): ] PATH = "/account/" + CHOICES_GENERATION = True def __init__(self, queue: Optional[List[str]] = None): + """Constructor""" super().__init__(queue) self.ROUTINE_FILES: Dict[str, Path] = {} self.REMOTE_CHOICES: List[str] = [] - self.update_runtime_choices() + if session and get_current_user().preferences.USE_PROMPT_TOOLKIT: + self.choices: dict = self.choices_default + self.completer = NestedCompleter.from_nested_dict(self.choices) def update_runtime_choices(self): """Update runtime choices""" self.ROUTINE_FILES = self.get_routines() if session and get_current_user().preferences.USE_PROMPT_TOOLKIT: - choices: dict = {c: {} for c in self.controller_choices} # type: ignore - choices["sync"] = {"--on": {}, "--off": {}} - choices["upload"]["--file"] = {c: {} for c in self.ROUTINE_FILES} - choices["upload"]["-f"] = choices["upload"]["--file"] - choices["download"]["--name"] = {c: {} for c in self.REMOTE_CHOICES} - choices["download"]["-n"] = choices["download"]["--name"] - choices["delete"]["--name"] = {c: {} for c in self.REMOTE_CHOICES} - choices["delete"]["-n"] = choices["delete"]["--name"] - self.completer = NestedCompleter.from_nested_dict(choices) + self.choices["upload"]["--file"].update({c: {} for c in self.ROUTINE_FILES}) + self.choices["download"]["--name"].update( + {c: {} for c in self.REMOTE_CHOICES} + ) + self.choices["delete"]["--name"].update( + {c: {} for c in self.REMOTE_CHOICES} + ) + self.completer = NestedCompleter.from_nested_dict(self.choices) def get_routines(self): """Get routines""" @@ -88,7 +90,6 @@ def get_routines(self): def print_help(self): """Print help""" - mt = MenuText("account/", 100) mt.add_info("_info_") mt.add_cmd("sync") @@ -109,6 +110,7 @@ def print_help(self): mt.add_info("_authentication_") mt.add_cmd("logout") console.print(text=mt.menu_text, menu="Account") + self.update_runtime_choices() @log_start_end(log=logger) def call_logout(self, other_args: List[str]) -> None: @@ -154,15 +156,16 @@ def call_sync(self, other_args: List[str]): ns_parser = self.parse_known_args_and_warn(parser, other_args) if ns_parser: + current_user = get_current_user() if ns_parser.sync is None: - sync = get_current_user().preferences.SYNC_ENABLED + sync = "ON" if current_user.preferences.SYNC_ENABLED is True else "OFF" console.print(f"sync is {sync}, use --on or --off to change.") else: set_preference( name="OPENBB_SYNC_ENABLED", value=ns_parser.sync, ) - sync = get_current_user().preferences.SYNC_ENABLED + sync = "ON" if current_user.preferences.SYNC_ENABLED is True else "OFF" console.print(f"[info]sync:[/info] {sync}") @log_start_end(log=logger) @@ -250,7 +253,7 @@ def call_list(self, other_args: List[str]): ) df, page, pages = get_routines_info(response) if not df.empty: - self.REMOTE_CHOICES = list(df["name"]) + self.REMOTE_CHOICES += list(df["name"]) self.update_runtime_choices() display_routines_list(df, page, pages) else: diff --git a/openbb_terminal/core/session/hub_model.py b/openbb_terminal/core/session/hub_model.py index 572820f2d6ef..e1fc818e57db 100644 --- a/openbb_terminal/core/session/hub_model.py +++ b/openbb_terminal/core/session/hub_model.py @@ -104,7 +104,7 @@ def delete_session( The response from the logout request. """ try: - response = requests.post( + response = requests.get( url=base_url + "logout", headers={"Authorization": auth_header}, json={"token": token}, @@ -320,9 +320,9 @@ def clear_user_configs( timeout=timeout, ) if response.status_code == 200: - console.print("[green]Cleared configurations.[/green]") + console.print("[green]Cleared data.[/green]") else: - console.print("[red]Failed to clear configurations.[/red]") + console.print("[red]Failed to clear data.[/red]") return response except requests.exceptions.ConnectionError: console.print(f"\n{CONNECTION_ERROR_MSG}") @@ -331,7 +331,7 @@ def clear_user_configs( console.print(f"\n{CONNECTION_TIMEOUT_MSG}") return None except Exception: - console.print("[red]Failed to clear configurations.[/red]") + console.print("[red]Failed to clear data.[/red]") return None diff --git a/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args0-False].txt b/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args0-False].txt index d2624cdd039f..3992f63030eb 100644 --- a/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args0-False].txt +++ b/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args0-False].txt @@ -1,2 +1,2 @@ -[info]sync:[/info] True +[info]sync:[/info] OFF ['--on'] diff --git a/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args1-True].txt b/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args1-True].txt index a02421955aa4..e2401bc93e0c 100644 --- a/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args1-True].txt +++ b/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args1-True].txt @@ -1,2 +1,2 @@ -[info]sync:[/info] False +[info]sync:[/info] ON ['--off'] diff --git a/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args2-True].txt b/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args2-True].txt index d2624cdd039f..939d5a1cd391 100644 --- a/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args2-True].txt +++ b/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args2-True].txt @@ -1,2 +1,2 @@ -[info]sync:[/info] True +[info]sync:[/info] ON ['--on'] diff --git a/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args3-False].txt b/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args3-False].txt index a02421955aa4..72602083de84 100644 --- a/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args3-False].txt +++ b/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args3-False].txt @@ -1,2 +1,2 @@ -[info]sync:[/info] False +[info]sync:[/info] OFF ['--off'] diff --git a/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args4-True].txt b/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args4-True].txt index f4f1eef4b7d6..82f1693fb92c 100644 --- a/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args4-True].txt +++ b/tests/openbb_terminal/account/txt/test_account_controller/test_call_sync[other_args4-True].txt @@ -1,2 +1,2 @@ -sync is True, use --on or --off to change. +sync is ON, use --on or --off to change. [] diff --git a/tests/openbb_terminal/session/test_hub_model.py b/tests/openbb_terminal/session/test_hub_model.py index 7b9c9d15d9f3..3f94c22c3471 100644 --- a/tests/openbb_terminal/session/test_hub_model.py +++ b/tests/openbb_terminal/session/test_hub_model.py @@ -102,7 +102,7 @@ def test_create_session_from_token_exception(token): @pytest.mark.parametrize("auth_header, token", TEST_HEADER_TOKEN) def test_delete_session_success(auth_header, token): - with patch("requests.post") as mock_post: + with patch("requests.get") as mock_post: mock_post.return_value.status_code = 200 response = hub_model.delete_session(auth_header, token) assert response.status_code == 200 @@ -117,7 +117,7 @@ def test_delete_session_success(auth_header, token): @pytest.mark.parametrize("auth_header, token", TEST_HEADER_TOKEN) def test_delete_session_connection_error(auth_header, token): - with patch("requests.post") as mock_post: + with patch("requests.get") as mock_post: mock_post.side_effect = requests.exceptions.ConnectionError response = hub_model.delete_session(auth_header, token) assert response is None @@ -125,7 +125,7 @@ def test_delete_session_connection_error(auth_header, token): @pytest.mark.parametrize("auth_header, token", TEST_HEADER_TOKEN) def test_delete_session_timeout(auth_header, token): - with patch("requests.post") as mock_post: + with patch("requests.get") as mock_post: mock_post.side_effect = requests.exceptions.Timeout response = hub_model.delete_session(auth_header, token) assert response is None @@ -133,7 +133,7 @@ def test_delete_session_timeout(auth_header, token): @pytest.mark.parametrize("auth_header, token", TEST_HEADER_TOKEN) def test_delete_session_exception(auth_header, token): - with patch("requests.post") as mock_post: + with patch("requests.get") as mock_post: mock_post.side_effect = Exception response = hub_model.delete_session(auth_header, token) assert response is None