Skip to content

Commit e39bbe3

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 dee7e2b commit e39bbe3

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

tests/model/test_model.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,6 +2294,45 @@ def test_get_subscription_color(
22942294
model.stream_dict = stream_dict
22952295
assert model.get_subscription_color(stream_id) == expected_value
22962296

2297+
@pytest.mark.parametrize(
2298+
"stream_id, expected_value",
2299+
[
2300+
case(
2301+
1000,
2302+
2303+
),
2304+
case(
2305+
3,
2306+
2307+
),
2308+
],
2309+
)
2310+
def test_get_subscription_email(
2311+
self,
2312+
model,
2313+
stream_dict,
2314+
unsubscribed_streams_fixture,
2315+
stream_id,
2316+
expected_value,
2317+
):
2318+
model.stream_dict = stream_dict
2319+
model._unsubscribed_streams = unsubscribed_streams_fixture
2320+
assert model.get_subscription_email(stream_id) == expected_value
2321+
2322+
def test_get_subscription_email_not_subscribed(
2323+
self,
2324+
model,
2325+
stream_dict,
2326+
unsubscribed_streams_fixture,
2327+
stream_id=5,
2328+
):
2329+
model.stream_dict = stream_dict
2330+
model._unsubscribed_streams = unsubscribed_streams_fixture
2331+
with pytest.raises(
2332+
RuntimeError, match=f"Stream with id {stream_id} is not subscribed to!"
2333+
):
2334+
model.get_subscription_email(stream_id)
2335+
22972336
def test_get_all_subscription_ids(
22982337
self,
22992338
model,

zulipterminal/model.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,14 @@ 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+
else:
1252+
raise RuntimeError(f"Stream with id {stream_id} is not subscribed to!")
1253+
12461254
def _subscribe_to_streams(self, subscriptions: List[Subscription]) -> None:
12471255
def make_reduced_stream_data(stream: Subscription) -> StreamData:
12481256
# 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)