diff --git a/openbb_terminal/account/account_controller.py b/openbb_terminal/account/account_controller.py index 1400affd9140..459675080ecd 100644 --- a/openbb_terminal/account/account_controller.py +++ b/openbb_terminal/account/account_controller.py @@ -314,6 +314,14 @@ def call_upload(self, other_args: List[str]): default="", nargs="+", ) + parser.add_argument( + "-p", + "--public", + dest="public", + action="store_true", + help="Whether the routine should be public or not", + default=False, + ) ns_parser = self.parse_known_args_and_warn(parser, other_args) if is_local() and "-h" not in other_args and "--help" not in other_args: print_guest_block_msg() @@ -341,6 +349,7 @@ def call_upload(self, other_args: List[str]): "description": description, "routine": routine, "tags": tags, + "public": ns_parser.public, } response = Hub.upload_routine(**kwargs) # type: ignore diff --git a/openbb_terminal/core/session/hub_model.py b/openbb_terminal/core/session/hub_model.py index 84e36213baad..f3de9d62566e 100644 --- a/openbb_terminal/core/session/hub_model.py +++ b/openbb_terminal/core/session/hub_model.py @@ -396,6 +396,7 @@ def upload_config( return None +# pylint: disable=too-many-arguments def upload_routine( auth_header: str, name: str = "", @@ -403,6 +404,7 @@ def upload_routine( routine: str = "", override: bool = False, tags: str = "", + public: bool = False, base_url: str = BASE_URL, timeout: int = TIMEOUT, ) -> Optional[requests.Response]: @@ -420,6 +422,8 @@ def upload_routine( Whether to override the routine if it already exists. tags : str The tags of the routine. + public : bool + Whether to make the routine public or not. base_url : str The base url, by default BASE_URL timeout : int @@ -430,7 +434,6 @@ def upload_routine( Optional[requests.Response] The response from the post request. """ - data = { "name": name, "description": description, @@ -438,7 +441,7 @@ def upload_routine( "override": override, "tags": tags, "version": get_current_system().VERSION, - "public": False, + "public": public, } try: diff --git a/openbb_terminal/parent_classes.py b/openbb_terminal/parent_classes.py index d64200eb7ddc..7de223ec76be 100644 --- a/openbb_terminal/parent_classes.py +++ b/openbb_terminal/parent_classes.py @@ -82,11 +82,14 @@ SUPPORT_TYPE = ["bug", "suggestion", "question", "generic"] + +# TODO: We should try to avoid these global variables RECORD_SESSION = False SESSION_RECORDED = list() SESSION_RECORDED_NAME = "" SESSION_RECORDED_DESCRIPTION = "" SESSION_RECORDED_TAGS = "" +SESSION_RECORDED_PUBLIC = False class BaseController(metaclass=ABCMeta): @@ -910,6 +913,14 @@ def call_record(self, other_args) -> None: default="", nargs="+", ) + parser.add_argument( + "-p", + "--public", + dest="public", + action="store_true", + help="Whether the routine should be public or not", + default=False, + ) if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-n") ns_parser = self.parse_simple_args(parser, other_args) @@ -919,6 +930,7 @@ def call_record(self, other_args) -> None: global SESSION_RECORDED_NAME global SESSION_RECORDED_DESCRIPTION global SESSION_RECORDED_TAGS + global SESSION_RECORDED_PUBLIC SESSION_RECORDED_NAME = ( ns_parser.name @@ -928,6 +940,7 @@ def call_record(self, other_args) -> None: SESSION_RECORDED_DESCRIPTION = " ".join(ns_parser.description) SESSION_RECORDED_TAGS = " ".join(ns_parser.tags) if ns_parser.tags else "" + SESSION_RECORDED_PUBLIC = ns_parser.public console.print( "[green]The session is successfully being recorded." @@ -980,6 +993,7 @@ def call_stop(self, _) -> None: "description": SESSION_RECORDED_DESCRIPTION, "routine": routine, "tags": SESSION_RECORDED_TAGS, + "public": SESSION_RECORDED_PUBLIC, } response = Hub.upload_routine(**kwargs) # type: ignore if response is not None and response.status_code == 409: diff --git a/tests/openbb_terminal/account/test_account_controller.py b/tests/openbb_terminal/account/test_account_controller.py index 652ddd316f6f..fcc1d7b9d748 100644 --- a/tests/openbb_terminal/account/test_account_controller.py +++ b/tests/openbb_terminal/account/test_account_controller.py @@ -442,6 +442,7 @@ def test_call_upload(mocker, test_user): description="abc", routine="do something", tags="stocks", + public=False, ) diff --git a/tests/openbb_terminal/portfolio/csv/test_portfolio_model/test_tracking_error.csv b/tests/openbb_terminal/portfolio/csv/test_portfolio_model/test_tracking_error.csv index 580c0d6a5391..a45e0a4b2710 100644 --- a/tests/openbb_terminal/portfolio/csv/test_portfolio_model/test_tracking_error.csv +++ b/tests/openbb_terminal/portfolio/csv/test_portfolio_model/test_tracking_error.csv @@ -4,9 +4,7 @@ qtd,- ytd,- 3m,- 6m,- -1y,"Adj Close NaN -Total NaN -dtype: float64" +1y,- 3y,"Adj Close NaN Total NaN dtype: float64" diff --git a/tests/openbb_terminal/session/test_hub_model.py b/tests/openbb_terminal/session/test_hub_model.py index ee8bbf524a83..a028a592156d 100644 --- a/tests/openbb_terminal/session/test_hub_model.py +++ b/tests/openbb_terminal/session/test_hub_model.py @@ -534,14 +534,45 @@ def test_clear_user_configs_exception(): @pytest.mark.parametrize( - "auth_header, name, description, routine, override, base_url, timeout, status_code", + "auth_header, name, description, routine, override, tags, public, base_url, timeout, status_code", [ - ("auth_header", "name", "description", "routine", True, "base_url", 10, 200), - ("auth_header", "name", "description", "routine", False, "base_url", 10, 400), + ( + "auth_header", + "name", + "description", + "routine", + True, + "TEST_TAG", + True, + "base_url", + 10, + 200, + ), + ( + "auth_header", + "name", + "description", + "routine", + False, + "TEST_TAG", + False, + "base_url", + 10, + 400, + ), ], ) def test_upload_routine( - auth_header, name, description, routine, override, base_url, timeout, status_code + auth_header, + name, + description, + routine, + override, + tags, + public, + base_url, + timeout, + status_code, ): mock_response = MagicMock(spec=requests.Response) mock_response.status_code = status_code @@ -555,6 +586,8 @@ def test_upload_routine( name=name, description=description, routine=routine, + tags=tags, + public=public, override=override, base_url=base_url, timeout=timeout,