From 637f271377394ed10b268e10805add741fd5fd70 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Mon, 13 Mar 2023 19:18:55 +0000 Subject: [PATCH 01/10] fix logout cmd --- openbb_terminal/core/session/hub_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbb_terminal/core/session/hub_model.py b/openbb_terminal/core/session/hub_model.py index 572820f2d6ef..4f7664c1960d 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}, From 86844d4a58e13916f182fa5159ade04491678de6 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Mon, 13 Mar 2023 19:49:05 +0000 Subject: [PATCH 02/10] fix sync flag --- openbb_terminal/account/account_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbb_terminal/account/account_controller.py b/openbb_terminal/account/account_controller.py index 6d8bc01fa15b..37aaa4c1e06d 100644 --- a/openbb_terminal/account/account_controller.py +++ b/openbb_terminal/account/account_controller.py @@ -162,7 +162,7 @@ def call_sync(self, other_args: List[str]): name="OPENBB_SYNC_ENABLED", value=ns_parser.sync, ) - sync = get_current_user().preferences.SYNC_ENABLED + sync = "ON" if get_current_user().preferences.SYNC_ENABLED is True else "OFF" console.print(f"[info]sync:[/info] {sync}") @log_start_end(log=logger) From c9ac766cbc3c4a7b9c90b281f458d98ea571ddf5 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Mon, 13 Mar 2023 19:55:20 +0000 Subject: [PATCH 03/10] change msg --- openbb_terminal/core/session/hub_model.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openbb_terminal/core/session/hub_model.py b/openbb_terminal/core/session/hub_model.py index 4f7664c1960d..e1fc818e57db 100644 --- a/openbb_terminal/core/session/hub_model.py +++ b/openbb_terminal/core/session/hub_model.py @@ -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 From 318c7ff853983ed8d8a278c6e3007b90daa3e036 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Mon, 13 Mar 2023 19:55:35 +0000 Subject: [PATCH 04/10] update request test for delete session --- tests/openbb_terminal/session/test_hub_model.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 From 0a027f13e380a801e117f53a43ceadd7bce14fae Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Mon, 13 Mar 2023 20:15:26 +0000 Subject: [PATCH 05/10] fix autocompletion for routines upload --- openbb_terminal/account/account_controller.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/openbb_terminal/account/account_controller.py b/openbb_terminal/account/account_controller.py index 37aaa4c1e06d..99d5c2fc95c3 100644 --- a/openbb_terminal/account/account_controller.py +++ b/openbb_terminal/account/account_controller.py @@ -51,7 +51,6 @@ def __init__(self, queue: Optional[List[str]] = None): super().__init__(queue) self.ROUTINE_FILES: Dict[str, Path] = {} self.REMOTE_CHOICES: List[str] = [] - self.update_runtime_choices() def update_runtime_choices(self): """Update runtime choices""" @@ -88,7 +87,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 +107,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: @@ -162,7 +161,11 @@ def call_sync(self, other_args: List[str]): name="OPENBB_SYNC_ENABLED", value=ns_parser.sync, ) - sync = "ON" if get_current_user().preferences.SYNC_ENABLED is True else "OFF" + sync = ( + "ON" + if get_current_user().preferences.SYNC_ENABLED is True + else "OFF" + ) console.print(f"[info]sync:[/info] {sync}") @log_start_end(log=logger) From c0ec916ddb835d2908f7ab22bd63235f7a2645c1 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Mon, 13 Mar 2023 21:10:59 +0000 Subject: [PATCH 06/10] append to list of choices --- openbb_terminal/account/account_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbb_terminal/account/account_controller.py b/openbb_terminal/account/account_controller.py index 99d5c2fc95c3..1535bc358ab3 100644 --- a/openbb_terminal/account/account_controller.py +++ b/openbb_terminal/account/account_controller.py @@ -253,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: From 0682018789b1134e34d19c76c34f8d11828d32cb Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Tue, 14 Mar 2023 10:11:03 +0000 Subject: [PATCH 07/10] fix autocompletioin --- openbb_terminal/account/account_controller.py | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/openbb_terminal/account/account_controller.py b/openbb_terminal/account/account_controller.py index 1535bc358ab3..18684fd48269 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,25 +45,25 @@ 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] = [] + 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""" From 564e2eb4941d71dd35dd1d2052489d550f742956 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Tue, 14 Mar 2023 10:15:22 +0000 Subject: [PATCH 08/10] black --- openbb_terminal/account/account_controller.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/openbb_terminal/account/account_controller.py b/openbb_terminal/account/account_controller.py index 18684fd48269..dcd9a0d3c8a2 100644 --- a/openbb_terminal/account/account_controller.py +++ b/openbb_terminal/account/account_controller.py @@ -61,8 +61,12 @@ def update_runtime_choices(self): self.ROUTINE_FILES = self.get_routines() if session and get_current_user().preferences.USE_PROMPT_TOOLKIT: 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.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): From f038a07975137b6755ade2687aa519d689680369 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Tue, 14 Mar 2023 12:28:14 +0000 Subject: [PATCH 09/10] mypy --- openbb_terminal/account/account_controller.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/openbb_terminal/account/account_controller.py b/openbb_terminal/account/account_controller.py index dcd9a0d3c8a2..ac4bcbe58690 100644 --- a/openbb_terminal/account/account_controller.py +++ b/openbb_terminal/account/account_controller.py @@ -156,19 +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 = ( - "ON" - if get_current_user().preferences.SYNC_ENABLED is True - else "OFF" - ) + sync = "ON" if current_user.preferences.SYNC_ENABLED is True else "OFF" console.print(f"[info]sync:[/info] {sync}") @log_start_end(log=logger) From 7db37bf30750a9d8601f4baa6d81c26a24a61c11 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Tue, 14 Mar 2023 12:29:35 +0000 Subject: [PATCH 10/10] rewrite tests --- .../test_call_sync[other_args0-False].txt | 2 +- .../test_call_sync[other_args1-True].txt | 2 +- .../test_call_sync[other_args2-True].txt | 2 +- .../test_call_sync[other_args3-False].txt | 2 +- .../test_call_sync[other_args4-True].txt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) 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. []