Skip to content

Commit 8fccae1

Browse files
model/test_model/conftest: Notify use of alert-word.
Tests added.
1 parent bef2a8f commit 8fccae1

File tree

3 files changed

+105
-2
lines changed

3 files changed

+105
-2
lines changed

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,11 @@ def stream_msg_template() -> Message:
467467
return msg_template
468468

469469

470+
@pytest.fixture(params=["stream_msg_template"])
471+
def stream_msg_fixture(request: Any) -> Message:
472+
return request.getfixturevalue(request.param)
473+
474+
470475
@pytest.fixture
471476
def extra_stream_msg_template() -> Message:
472477
msg_template = msg_template_factory(

tests/model/test_model.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,6 +2080,99 @@ def test_notify_users_hides_PM_content_based_on_user_setting(
20802080
f"Test Organization Name:\nFoo Foo (to you{others})", expected_content
20812081
)
20822082

2083+
@pytest.mark.parametrize(
2084+
[
2085+
"user_id",
2086+
"flags",
2087+
"visual_notification_status",
2088+
"display_recipient",
2089+
"subject",
2090+
"is_stream_muted",
2091+
"is_topic_muted",
2092+
"no_of_times_notify_call_expected",
2093+
],
2094+
[
2095+
(
2096+
4444,
2097+
{"flags": ["has_alert_word"]},
2098+
True,
2099+
{"display_recipient": ["test_here"]},
2100+
{"subject": ["k1"]},
2101+
True,
2102+
True,
2103+
1,
2104+
),
2105+
(
2106+
4444,
2107+
{"flags": ["has_alert_word"]},
2108+
False,
2109+
{"display_recipient": ["test_here"]},
2110+
{"subject": ["k1"]},
2111+
True,
2112+
True,
2113+
0,
2114+
),
2115+
(
2116+
4444,
2117+
{"flags": ["has_alert_word"]},
2118+
False,
2119+
{"display_recipient": ["test_here"]},
2120+
{"subject": ["k1"]},
2121+
True,
2122+
False,
2123+
0,
2124+
),
2125+
(
2126+
4444,
2127+
{"flags": ["has_alert_word"]},
2128+
False,
2129+
{"display_recipient": ["test_here"]},
2130+
{"subject": ["k1"]},
2131+
False,
2132+
False,
2133+
1,
2134+
),
2135+
],
2136+
ids=[
2137+
"visual_notification is on -> no effect due to mute",
2138+
"visual_notification is off, and both topic and stream is muted",
2139+
"visual_notification is off, only topic is muted",
2140+
"visual_notification is off, neither topic or stream is muted",
2141+
],
2142+
)
2143+
def test_notify_user_with_alert_words(
2144+
self,
2145+
mocker,
2146+
model,
2147+
stream_msg_fixture,
2148+
user_id,
2149+
flags,
2150+
visual_notification_status,
2151+
display_recipient,
2152+
subject,
2153+
is_stream_muted,
2154+
is_topic_muted,
2155+
no_of_times_notify_call_expected,
2156+
):
2157+
stream_msg_fixture.update(flags)
2158+
self.controller.notify_enabled = True
2159+
stream_msg_fixture.update(display_recipient)
2160+
stream_msg_fixture.update(subject)
2161+
mocker.patch.object(
2162+
model,
2163+
"is_visual_notifications_enabled",
2164+
return_value=visual_notification_status,
2165+
)
2166+
mocker.patch.object(model, "is_muted_stream", return_value=is_stream_muted)
2167+
mocker.patch.object(model, "is_muted_topic", return_value=is_topic_muted)
2168+
notify = mocker.patch(MODULE + ".notify")
2169+
model.notify_user(stream_msg_fixture)
2170+
if no_of_times_notify_call_expected == 1:
2171+
assert notify.called
2172+
else:
2173+
assert not notify.called
2174+
# recipient = notify.call_args[0][0]
2175+
20832176
@pytest.mark.parametrize(
20842177
"event, initially_me_message,"
20852178
"expected_times_messages_rerendered, expected_index, topic_view_enabled",

zulipterminal/model.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,13 @@ def notify_user(self, message: Message) -> str:
14581458
set(message["flags"])
14591459
) or self.is_visual_notifications_enabled(stream_id):
14601460
recipient = "{display_recipient} -> {subject}".format(**message)
1461-
1461+
if "has_alert_word" in message["flags"]:
1462+
# Check if stream or topic is muted
1463+
topic = message.get("subject", "")
1464+
if not self.is_muted_stream(stream_id) and not self.is_muted_topic(
1465+
stream_id, topic
1466+
):
1467+
recipient = "{display_recipient} -> {subject}".format(**message)
14621468
if recipient:
14631469
if hidden_content:
14641470
text = content
@@ -1479,7 +1485,6 @@ def notify_user(self, message: Message) -> str:
14791485

14801486
spoiler_tag.unwrap()
14811487
text = soup.text
1482-
14831488
return notify(
14841489
f"{self.server_name}:\n"
14851490
f"{message['sender_full_name']} (to {recipient})",

0 commit comments

Comments
 (0)