Skip to content

Commit ec9f1d8

Browse files
committed
refactor: model/views: Use get_subscription_email instead of stream_dict.
This commit replaces the usage of directly indexing stream_dict for "email_address" data with the new stream property accessor method "get_subscription_email". Test added.
1 parent 5a40f47 commit ec9f1d8

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

tests/model/test_model.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,6 +2291,35 @@ def test_get_subscription_color(
22912291
model.stream_dict = stream_dict
22922292
assert model.get_subscription_color(stream_id) == expected_value
22932293

2294+
@pytest.mark.parametrize(
2295+
"stream_id, expected_value",
2296+
[
2297+
case(
2298+
1000,
2299+
2300+
),
2301+
case(
2302+
3,
2303+
2304+
),
2305+
case(
2306+
5,
2307+
None,
2308+
),
2309+
],
2310+
)
2311+
def test_get_subscription_email(
2312+
self,
2313+
model,
2314+
stream_dict,
2315+
unsubscribed_streams_fixture,
2316+
stream_id,
2317+
expected_value,
2318+
):
2319+
model.stream_dict = stream_dict
2320+
model._unsubscribed_streams = unsubscribed_streams_fixture
2321+
assert model.get_subscription_email(stream_id) == expected_value
2322+
22942323
def test_get_all_subscription_ids(
22952324
self,
22962325
model,

zulipterminal/model.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,13 @@ def get_subscription_color(self, stream_id: int) -> Optional[str]:
12431243
return self._unsubscribed_streams[stream_id]["color"]
12441244
return None
12451245

1246+
def get_subscription_email(self, stream_id: int) -> Optional[str]:
1247+
if stream_id in self.stream_dict:
1248+
return self.stream_dict[stream_id]["email_address"]
1249+
elif stream_id in self._unsubscribed_streams:
1250+
return self._unsubscribed_streams[stream_id]["email_address"]
1251+
return None
1252+
12461253
def _subscribe_to_streams(self, subscriptions: List[Subscription]) -> None:
12471254
def make_reduced_stream_data(stream: Subscription) -> StreamData:
12481255
# stream_id has been changed to id.

zulipterminal/ui_tools/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ def __init__(self, controller: Any, stream_id: int) -> None:
13141314
else "Not Public to Users"
13151315
)
13161316
member_keys = ", ".join(map(repr, keys_for_command("STREAM_MEMBERS")))
1317-
self.stream_email = stream["email_address"]
1317+
self.stream_email = controller.model.get_subscription_email(self.stream_id)
13181318
email_keys = ", ".join(map(repr, keys_for_command("COPY_STREAM_EMAIL")))
13191319

13201320
weekly_traffic = controller.model.get_stream_weekly_traffic(self.stream_id)

0 commit comments

Comments
 (0)