Skip to content

core/run/views: Add --notify and --no-notify flags as a command-line argument for ZT #964

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
37 changes: 35 additions & 2 deletions tests/cli/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ def test_main_help(capsys, options):
'--no-autohide',
'-v, --version',
'-e, --explore',
'--color-depth'
'--color-depth',
'--notify',
'--no-notify',
}
optional_argument_lines = {line[2:] for line in lines
if len(line) > 2 and line[2] == '-'}
Expand Down Expand Up @@ -112,6 +114,7 @@ def test_valid_zuliprc_but_no_connection(capsys, mocker, minimal_zuliprc,
" autohide setting 'no_autohide' specified with no config.",
" maximum footlinks value '3' specified with no config.",
" color depth setting '256' specified with no config.",
" notify setting 'disabled' specified with no config.",
"\x1b[91m",
("Error connecting to Zulip server: "
f"{server_connection_error}.\x1b[0m"),
Expand Down Expand Up @@ -152,6 +155,7 @@ def test_warning_regarding_incomplete_theme(capsys, mocker, monkeypatch,
" autohide setting 'no_autohide' specified with no config.",
" maximum footlinks value '3' specified with no config.",
" color depth setting '256' specified with no config.",
" notify setting 'disabled' specified with no config.",
"\x1b[91m",
f"Error connecting to Zulip server: {server_connection_error}.\x1b[0m",
]
Expand Down Expand Up @@ -204,6 +208,34 @@ def test_main_multiple_autohide_options(capsys, options):
assert lines == expected


@pytest.mark.parametrize('option, notify_option', [
('--notify', 'enabled'),
('--no-notify', 'disabled'),
('--profile', None), # disabled by default
])
def test__parse_args_valid_notify_option(option, notify_option):
args = parse_args([option])
assert args.notify == notify_option


@pytest.mark.parametrize('options', [
['--notify', '--no-notify'],
['--no-notify', '--notify'],
])
def test_main_multiple_notify_options(capsys, options):
with pytest.raises(SystemExit) as e:
main(options)

assert str(e.value) == "2"

captured = capsys.readouterr()
lines = captured.err.strip('\n')
lines = lines.split("pytest: ", 1)[1]
expected = (f"error: argument {options[1]}: not allowed "
f"with argument {options[0]}")
assert lines == expected


# NOTE: Fixture is necessary to ensure unreadable dir is garbage-collected
# See pytest issue #7821
@pytest.fixture
Expand Down Expand Up @@ -310,7 +342,8 @@ def test_successful_main_function_with_config(
" theme 'zt_dark' specified in zuliprc file (by alias 'default').",
" autohide setting 'autohide' specified in zuliprc file.",
f" maximum footlinks value {footlinks_output}",
" color depth setting '256' specified in zuliprc file."
" color depth setting '256' specified in zuliprc file.",
" notify setting 'enabled' specified in zuliprc file."
]
assert lines == expected_lines

Expand Down
2 changes: 2 additions & 0 deletions tests/ui_tools/test_popups.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def mock_external_classes(self, mocker):
server_feature_level=server_feature_level,
theme_name='zt_dark',
color_depth=256,
notify_enabled=False,
autohide_enabled=False,
maximum_footlinks=3)

Expand Down Expand Up @@ -177,6 +178,7 @@ def test_feature_level_content(self, mocker, zulip_version):
server_feature_level=server_feature_level,
theme_name='zt_dark',
color_depth=256,
notify_enabled=False,
autohide_enabled=False,
maximum_footlinks=3)

Expand Down
13 changes: 13 additions & 0 deletions zulipterminal/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ def parse_args(argv: List[str]) -> argparse.Namespace:
choices=['1', '16', '256'],
help="Force the color depth "
f"(default {DEFAULT_SETTINGS['color-depth']}).")
notify_group = parser.add_mutually_exclusive_group()
notify_group.add_argument('--notify', dest='notify', default=None,
action='store_const', const='enabled',
help='Enable desktop notifications.')
notify_group.add_argument('--no-notify', dest='notify', default=None,
action='store_const', const='disabled',
help='Disable desktop notifications.')
# debug mode
parser.add_argument("-d",
"--debug",
Expand Down Expand Up @@ -383,6 +390,9 @@ def main(options: Optional[List[str]]=None) -> None:

color_depth = int(zterm['color-depth'][0])

if args.notify:
zterm['notify'] = (args.notify, 'on command line')

print("Loading with:")
print(" theme '{}' specified {}.".format(*theme_to_use))
complete, incomplete = complete_and_incomplete_themes()
Expand All @@ -404,6 +414,9 @@ def main(options: Optional[List[str]]=None) -> None:
.format(*zterm['maximum-footlinks']))
print(" color depth setting '{}' specified {}."
.format(*zterm['color-depth']))
print(" notify setting '{}' specified {}."
.format(*zterm['notify']))

# For binary settings
# Specify setting in order True, False
valid_settings = {
Expand Down
7 changes: 5 additions & 2 deletions zulipterminal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,13 @@ def popup_with_message(self, text: str, width: int) -> None:

def show_about(self) -> None:
self.show_pop_up(
AboutView(self, 'About', zt_version=ZT_VERSION,
AboutView(self, 'About',
zt_version=ZT_VERSION,
server_version=self.model.server_version,
server_feature_level=self.model.server_feature_level,
theme_name=self.theme_name, color_depth=self.color_depth,
theme_name=self.theme_name,
color_depth=self.color_depth,
notify_enabled=self.notify_enabled,
autohide_enabled=self.autohide,
maximum_footlinks=self.maximum_footlinks),
'area:help'
Expand Down
7 changes: 5 additions & 2 deletions zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,8 @@ def __init__(self, controller: Any, title: str, *, zt_version: str,
server_version: str,
server_feature_level: Optional[int],
theme_name: str, color_depth: int,
autohide_enabled: bool, maximum_footlinks: int) -> None:
autohide_enabled: bool, maximum_footlinks: int,
notify_enabled: bool) -> None:
self.feature_level_content = (
[('Feature level', str(server_feature_level))]
if server_feature_level else []
Expand All @@ -1030,7 +1031,9 @@ def __init__(self, controller: Any, title: str, *, zt_version: str,
('Theme', theme_name),
('Autohide', 'enabled' if autohide_enabled else 'disabled'),
('Maximum footlinks', str(maximum_footlinks)),
('Color depth', str(color_depth))])
('Color depth', str(color_depth)),
('Notifications',
'enabled' if notify_enabled else 'disabled'), ])
]

popup_width, column_widths = self.calculate_table_widths(contents,
Expand Down