Skip to content

Commit 1190b33

Browse files
committed
model: Improve typing of stream_dict.
With the revamp of the Subscription TypedDict in an earlier commit, we use it to improve the typing of stream_dict in this commit. Tests and fixtures updated to support the new typing.
1 parent 32d6fcb commit 1190b33

File tree

3 files changed

+53
-33
lines changed

3 files changed

+53
-33
lines changed

tests/conftest.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def logged_on_user() -> Dict[str, Any]:
233233

234234

235235
@pytest.fixture
236-
def general_stream() -> Dict[str, Any]:
236+
def general_stream() -> Subscription:
237237
return {
238238
"name": "Some general stream",
239239
"date_created": 1472091253,
@@ -245,21 +245,25 @@ def general_stream() -> Dict[str, Any]:
245245
"audible_notifications": False,
246246
"description": "General Stream",
247247
"rendered_description": "General Stream",
248-
"is_old_stream": True,
249248
"desktop_notifications": False,
250249
"stream_weekly_traffic": 0,
251250
"push_notifications": False,
252251
"email_address": "[email protected]",
253252
"message_retention_days": 10,
254253
"subscribers": [1001, 11, 12],
255254
"history_public_to_subscribers": True,
255+
"is_announcement_only": False,
256+
"first_message_id": 1,
257+
"email_notifications": False,
258+
"wildcard_mentions_notify": False,
259+
"is_web_public": False,
256260
}
257261

258262

259263
# This is a private stream;
260264
# only description/stream_id/invite_only/name/color vary from above
261265
@pytest.fixture
262-
def secret_stream() -> Dict[str, Any]:
266+
def secret_stream() -> Subscription:
263267
return {
264268
"description": "Some private stream",
265269
"stream_id": 99,
@@ -272,19 +276,23 @@ def secret_stream() -> Dict[str, Any]:
272276
"color": "#ccc", # Color in '#xxx' format
273277
"is_muted": False,
274278
"audible_notifications": False,
275-
"is_old_stream": True,
276279
"desktop_notifications": False,
277280
"stream_weekly_traffic": 0,
278281
"message_retention_days": -1,
279282
"push_notifications": False,
280283
"subscribers": [1001, 11],
281284
"history_public_to_subscribers": False,
285+
"is_announcement_only": False,
286+
"first_message_id": 1,
287+
"email_notifications": False,
288+
"wildcard_mentions_notify": False,
289+
"is_web_public": False,
282290
}
283291

284292

285293
# Like public stream but with is_web_public=True
286294
@pytest.fixture
287-
def web_public_stream() -> Dict[str, Any]:
295+
def web_public_stream() -> Subscription:
288296
return {
289297
"description": "Some web public stream",
290298
"stream_id": 999,
@@ -297,23 +305,26 @@ def web_public_stream() -> Dict[str, Any]:
297305
"color": "#ddd", # Color in '#xxx' format
298306
"is_muted": False,
299307
"audible_notifications": False,
300-
"is_old_stream": True,
301308
"desktop_notifications": False,
302309
"stream_weekly_traffic": 0,
303310
"message_retention_days": -1,
304311
"push_notifications": False,
305312
"subscribers": [1001, 11],
306313
"history_public_to_subscribers": False,
307314
"is_web_public": True,
315+
"is_announcement_only": False,
316+
"first_message_id": 1,
317+
"email_notifications": False,
318+
"wildcard_mentions_notify": False,
308319
}
309320

310321

311322
@pytest.fixture
312323
def streams_fixture(
313-
general_stream: Dict[str, Any],
314-
secret_stream: Dict[str, Any],
315-
web_public_stream: Dict[str, Any],
316-
) -> List[Dict[str, Any]]:
324+
general_stream: Subscription,
325+
secret_stream: Subscription,
326+
web_public_stream: Subscription,
327+
) -> List[Subscription]:
317328
streams = [general_stream, secret_stream, web_public_stream]
318329
for i in range(1, 3):
319330
streams.append(
@@ -328,14 +339,18 @@ def streams_fixture(
328339
"audible_notifications": False,
329340
"description": f"A description of stream {i}",
330341
"rendered_description": f"A description of stream {i}",
331-
"is_old_stream": True,
332342
"desktop_notifications": False,
333343
"stream_weekly_traffic": 0,
334344
"push_notifications": False,
335345
"message_retention_days": i + 30,
336346
"email_address": f"stream{i}@example.com",
337347
"subscribers": [1001, 11, 12],
338348
"history_public_to_subscribers": True,
349+
"is_announcement_only": False,
350+
"first_message_id": 1,
351+
"email_notifications": False,
352+
"wildcard_mentions_notify": False,
353+
"is_web_public": False,
339354
}
340355
)
341356
return deepcopy(streams)
@@ -933,7 +948,7 @@ def clean_custom_profile_data_fixture() -> List[CustomProfileData]:
933948
def initial_data(
934949
logged_on_user: Dict[str, Any],
935950
users_fixture: List[Dict[str, Any]],
936-
streams_fixture: List[Dict[str, Any]],
951+
streams_fixture: List[Subscription],
937952
unsubscribed_streams_fixture: List[Subscription],
938953
never_subscribed_streams_fixture: List[Stream],
939954
realm_emojis: Dict[str, Dict[str, Any]],
@@ -1462,7 +1477,7 @@ def user_id(logged_on_user: Dict[str, Any]) -> int:
14621477

14631478

14641479
@pytest.fixture
1465-
def stream_dict(streams_fixture: List[Dict[str, Any]]) -> Dict[int, Any]:
1480+
def stream_dict(streams_fixture: List[Subscription]) -> Dict[int, Subscription]:
14661481
return {stream["stream_id"]: stream for stream in streams_fixture}
14671482

14681483

tests/core/test_core.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pytest import param as case
1010
from pytest_mock import MockerFixture
1111

12+
from zulipterminal.api_types import Subscription
1213
from zulipterminal.config.themes import generate_theme
1314
from zulipterminal.core import Controller
1415
from zulipterminal.helper import Index
@@ -124,18 +125,17 @@ def test_narrow_to_stream(
124125
mocker: MockerFixture,
125126
controller: Controller,
126127
index_stream: Index,
128+
general_stream: Subscription,
127129
stream_id: int = 205,
128130
stream_name: str = "PTEST",
129131
) -> None:
130132
controller.model.narrow = []
131133
controller.model.index = index_stream
132134
controller.view.message_view = mocker.patch("urwid.ListBox")
133135
controller.model.stream_dict = {
134-
stream_id: {
135-
"color": "#ffffff",
136-
"name": stream_name,
137-
}
136+
stream_id: general_stream,
138137
}
138+
controller.model.stream_dict[stream_id]["name"] = stream_name
139139
controller.model.muted_streams = set()
140140
mocker.patch(MODEL + ".is_muted_topic", return_value=False)
141141

@@ -171,6 +171,7 @@ def test_narrow_to_topic(
171171
initial_stream_id: Optional[int],
172172
anchor: Optional[int],
173173
expected_final_focus: int,
174+
general_stream: Subscription,
174175
stream_name: str = "PTEST",
175176
topic_name: str = "Test",
176177
stream_id: int = 205,
@@ -184,11 +185,9 @@ def test_narrow_to_topic(
184185
controller.model.stream_id = initial_stream_id
185186
controller.view.message_view = mocker.patch("urwid.ListBox")
186187
controller.model.stream_dict = {
187-
stream_id: {
188-
"color": "#ffffff",
189-
"name": stream_name,
190-
}
188+
stream_id: general_stream,
191189
}
190+
controller.model.stream_dict[stream_id]["name"] = stream_name
192191
controller.model.muted_streams = set()
193192
mocker.patch(MODEL + ".is_muted_topic", return_value=False)
194193

@@ -253,17 +252,17 @@ def test_narrow_to_all_messages(
253252
controller: Controller,
254253
index_all_messages: Index,
255254
anchor: Optional[int],
255+
general_stream: Subscription,
256256
expected_final_focus_msg_id: int,
257+
stream_id: int = 205,
257258
) -> None:
258259
controller.model.narrow = [["stream", "PTEST"]]
259260
controller.model.index = index_all_messages
260261
controller.view.message_view = mocker.patch("urwid.ListBox")
261262
controller.model.user_email = "some@email"
262263
controller.model.user_id = 1
263264
controller.model.stream_dict = {
264-
205: {
265-
"color": "#ffffff",
266-
}
265+
stream_id: general_stream,
267266
}
268267
controller.model.muted_streams = set()
269268
mocker.patch(MODEL + ".is_muted_topic", return_value=False)
@@ -300,7 +299,12 @@ def test_narrow_to_all_pm(
300299
assert msg_ids == id_list
301300

302301
def test_narrow_to_all_starred(
303-
self, mocker: MockerFixture, controller: Controller, index_all_starred: Index
302+
self,
303+
mocker: MockerFixture,
304+
controller: Controller,
305+
index_all_starred: Index,
306+
general_stream: Subscription,
307+
stream_id: int = 205,
304308
) -> None:
305309
controller.model.narrow = []
306310
controller.model.index = index_all_starred
@@ -310,9 +314,7 @@ def test_narrow_to_all_starred(
310314
mocker.patch(MODEL + ".is_muted_topic", return_value=False)
311315
controller.model.user_email = "some@email"
312316
controller.model.stream_dict = {
313-
205: {
314-
"color": "#ffffff",
315-
}
317+
stream_id: general_stream,
316318
}
317319
controller.view.message_view = mocker.patch("urwid.ListBox")
318320

@@ -327,7 +329,12 @@ def test_narrow_to_all_starred(
327329
assert msg_ids == id_list
328330

329331
def test_narrow_to_all_mentions(
330-
self, mocker: MockerFixture, controller: Controller, index_all_mentions: Index
332+
self,
333+
mocker: MockerFixture,
334+
controller: Controller,
335+
index_all_mentions: Index,
336+
general_stream: Subscription,
337+
stream_id: int = 205,
331338
) -> None:
332339
controller.model.narrow = []
333340
controller.model.index = index_all_mentions
@@ -337,9 +344,7 @@ def test_narrow_to_all_mentions(
337344
controller.model.user_email = "some@email"
338345
controller.model.user_id = 1
339346
controller.model.stream_dict = {
340-
205: {
341-
"color": "#ffffff",
342-
}
347+
stream_id: general_stream,
343348
}
344349
controller.view.message_view = mocker.patch("urwid.ListBox")
345350

zulipterminal/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def __init__(self, controller: Any) -> None:
177177
self.users: List[MinimalUserData] = []
178178
self._update_users_data_from_initial_data()
179179

180-
self.stream_dict: Dict[int, Any] = {}
180+
self.stream_dict: Dict[int, Subscription] = {}
181181
self._unsubscribed_streams: Dict[int, Subscription] = {}
182182
self._never_subscribed_streams: Dict[int, Stream] = {}
183183
self.muted_streams: Set[int] = set()

0 commit comments

Comments
 (0)