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

add public routines flag #5236

Merged
merged 5 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions openbb_terminal/account/account_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="Wether 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()
Expand Down Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions openbb_terminal/core/session/hub_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,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]:
Expand All @@ -420,6 +421,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
Expand All @@ -430,15 +433,14 @@ def upload_routine(
Optional[requests.Response]
The response from the post request.
"""

data = {
"name": name,
"description": description,
"script": routine,
"override": override,
"tags": tags,
"version": get_current_system().VERSION,
"public": False,
"public": public,
}

try:
Expand Down
14 changes: 14 additions & 0 deletions openbb_terminal/parent_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -910,6 +913,14 @@ def call_record(self, other_args) -> None:
default="",
nargs="+",
)
parser.add_argument(
"-p",
"--public",
dest="public",
action="store_true",
help="Wether 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)
Expand All @@ -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
Expand All @@ -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."
Expand Down Expand Up @@ -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:
Expand Down
41 changes: 37 additions & 4 deletions tests/openbb_terminal/session/test_hub_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down