Skip to content

Commit 62e7272

Browse files
committed
refactor: model: Use get_subscription_color instead of stream_dict.
This commit replaces the usage of directly indexing stream_dict for "color" data with the new stream property accessor method "get_subscription_color". Test added.
1 parent 9b829a4 commit 62e7272

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

tests/model/test_model.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,6 +2269,21 @@ def test_is_stream_invite_only(
22692269
assert model.is_stream_invite_only(stream_id) == expected_value
22702270
model._get_stream_from_id.assert_called_once()
22712271

2272+
@pytest.mark.parametrize(
2273+
"stream_id, expected_value",
2274+
[
2275+
case(
2276+
1,
2277+
"#baf",
2278+
),
2279+
],
2280+
)
2281+
def test_get_subscription_color(
2282+
self, model, stream_dict, stream_id, expected_value
2283+
):
2284+
model.stream_dict = stream_dict
2285+
assert model.get_subscription_color(stream_id) == expected_value
2286+
22722287
def test_get_all_subscription_ids(
22732288
self,
22742289
model,

tests/ui_tools/test_boxes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,7 @@ def test__set_stream_write_box_style_markers(
12791279
) -> None:
12801280
# FIXME: Refactor when we have ~ Model.is_private_stream
12811281
write_box.model.stream_dict = stream_dict
1282+
write_box.model.get_subscription_color.return_value = expected_color
12821283
write_box.model.is_valid_stream.return_value = is_valid_stream
12831284
write_box.model.stream_id_from_name.return_value = stream_id
12841285
write_box.model.stream_access_type.return_value = stream_access_type

tests/ui_tools/test_messages.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,13 +951,15 @@ def test_msg_generates_search_and_header_bar(
951951
msg_narrow,
952952
assert_header_bar,
953953
assert_search_bar,
954+
stream_color="#bd6",
954955
):
955956
self.model.stream_dict = {
956957
205: {
957-
"color": "#bd6",
958+
"color": stream_color,
958959
},
959960
}
960961
self.model.narrow = msg_narrow
962+
self.model.get_subscription_color.return_value = stream_color
961963
messages = messages_successful_response["messages"]
962964
current_message = messages[msg_type]
963965
msg_box = MessageBox(current_message, self.model, messages[0])

zulipterminal/model.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,9 @@ def set_stream_message_retention_days(
12211221
def is_stream_invite_only(self, stream_id: int) -> bool:
12221222
return self._get_stream_from_id(stream_id)["invite_only"]
12231223

1224+
def get_subscription_color(self, stream_id: int) -> str:
1225+
return self.stream_dict.get(stream_id)["color"]
1226+
12241227
def _subscribe_to_streams(self, subscriptions: List[Subscription]) -> None:
12251228
def make_reduced_stream_data(stream: Subscription) -> StreamData:
12261229
# stream_id has been changed to id.

zulipterminal/ui_tools/boxes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,7 @@ def _set_stream_write_box_style(self, widget: ReadlineEdit, new_text: str) -> No
412412
stream_id = self.model.stream_id_from_name(new_text)
413413
stream_access_type = self.model.stream_access_type(stream_id)
414414
stream_marker = STREAM_ACCESS_TYPE[stream_access_type]["icon"]
415-
stream = self.model.stream_dict[stream_id]
416-
color = stream["color"]
415+
color = self.model.get_subscription_color(stream_id)
417416
self.header_write_box[self.FOCUS_HEADER_PREFIX_STREAM].set_text(
418417
(color, stream_marker)
419418
)

zulipterminal/ui_tools/messages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def _is_private_message_to_self(self) -> bool:
150150

151151
def stream_header(self) -> Any:
152152
assert self.stream_id is not None
153-
color = self.model.stream_dict[self.stream_id]["color"]
153+
color = self.model.get_subscription_color(self.stream_id)
154154
bar_color = f"s{color}"
155155
stream_title_markup = (
156156
"bar",
@@ -211,7 +211,7 @@ def top_search_bar(self) -> Any:
211211
text_to_fill = "Mentions"
212212
elif self.message["type"] == "stream":
213213
assert self.stream_id is not None
214-
bar_color = self.model.stream_dict[self.stream_id]["color"]
214+
bar_color = self.model.get_subscription_color(self.stream_id)
215215
bar_color = f"s{bar_color}"
216216
if len(curr_narrow) == 2 and curr_narrow[1][0] == "topic":
217217
text_to_fill = (

0 commit comments

Comments
 (0)