Skip to content

Commit 005402a

Browse files
rsashankneiljp
authored andcommitted
refactor: model/views: Add method in model to access stream email.
Introduced a new method in the model to retrieve the stream email address from the stream data, updating popups code to use it. Tests added & updated.
1 parent 28d5f6a commit 005402a

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

tests/model/test_model.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import json
33
from collections import OrderedDict
44
from copy import deepcopy
5-
from typing import Any, List, Optional, Tuple
5+
from typing import Any, Dict, List, Optional, Tuple
66

77
import pytest
88
from pytest import param as case
@@ -563,6 +563,28 @@ def test_topics_in_stream(self, mocker, model, topics_index, fetched, stream_id=
563563
assert model.index["topics"][stream_id] == return_value
564564
assert model.index["topics"][stream_id] is not return_value
565565

566+
@pytest.mark.parametrize(
567+
"email_address_stream_dict, expected_return_value",
568+
[
569+
({"email_address": "[email protected]"}, "[email protected]"),
570+
({}, None),
571+
],
572+
ids=[
573+
"email_present_in_dict:ZFL<226",
574+
"email_absent_from_dict:ZFL>=226",
575+
],
576+
)
577+
def test_get_stream_email_address(
578+
self,
579+
model: Any,
580+
email_address_stream_dict: Dict[str, str],
581+
expected_return_value: Optional[str],
582+
stream_id: int = 1,
583+
) -> None:
584+
model.stream_dict[stream_id] = email_address_stream_dict
585+
result = model.get_stream_email_address(stream_id)
586+
assert result == expected_return_value
587+
566588
# pre server v3 provide user_id or id as a property within user key
567589
# post server v3 provide user_id as a property outside the user key
568590
@pytest.mark.parametrize("user_key", ["user_id", "id", None])

tests/ui_tools/test_popups.py

+1
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,7 @@ def test_stream_info_content__email_copy_text(
14361436
) -> None:
14371437
if not stream_email_present:
14381438
del general_stream["email_address"]
1439+
self.controller.model.get_stream_email_address.return_value = None
14391440

14401441
model = self.controller.model
14411442
stream_id = general_stream["stream_id"]

zulipterminal/model.py

+12
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,18 @@ def topics_in_stream(self, stream_id: int) -> List[str]:
906906

907907
return list(self.index["topics"][stream_id])
908908

909+
def get_stream_email_address(self, stream_id: int) -> Optional[str]:
910+
"""
911+
Returns the stream email address, or None if it is unavailable.
912+
"""
913+
if stream_id not in self.stream_dict:
914+
raise RuntimeError("Invalid stream id.")
915+
stream = self.stream_dict[stream_id]
916+
# FIXME: This field was removed from the subscription data in Zulip 7.5 / ZFL226
917+
# We should use the new /streams/{stream_id}/email_address endpoint instead
918+
stream_email = stream.get("email_address", None)
919+
return stream_email
920+
909921
@staticmethod
910922
def exception_safe_result(future: "Future[str]") -> str:
911923
try:

zulipterminal/ui_tools/views.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1405,9 +1405,7 @@ def __init__(self, controller: Any, stream_id: int) -> None:
14051405
)
14061406
member_keys = ", ".join(map(repr, display_keys_for_command("STREAM_MEMBERS")))
14071407

1408-
# FIXME: This field was removed from the subscription data in Zulip 7.5 / ZFL226
1409-
# We should use the new /streams/{stream_id}/email_address endpoint instead
1410-
self._stream_email = stream.get("email_address", None)
1408+
self._stream_email = controller.model.get_stream_email_address(stream_id)
14111409
if self._stream_email is None:
14121410
stream_copy_text = "< Stream email is unavailable >"
14131411
else:

0 commit comments

Comments
 (0)