Skip to content

Commit f03632e

Browse files
committed
refactor: Reduce the direct usage of stream dict in tests.
This commit removes the direct use of stream dicts in most of the tests and if necessary, patches the stream accessor methods created in a previous commit.
1 parent 5957c60 commit f03632e

File tree

4 files changed

+9
-36
lines changed

4 files changed

+9
-36
lines changed

tests/core/test_core.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,9 @@ def test_narrow_to_stream(
134134
controller.model.narrow = []
135135
controller.model.index = index_stream
136136
controller.view.message_view = mocker.patch("urwid.ListBox")
137-
controller.model.stream_dict = {
138-
stream_id: general_stream,
139-
}
140-
controller.model.stream_dict[stream_id]["name"] = stream_name
137+
mocker.patch(MODEL + ".stream_name_from_id", return_value=stream_name)
138+
mocker.patch(MODEL + ".stream_id_from_name", return_value=stream_id)
139+
mocker.patch(MODEL + ".is_user_subscribed_to_stream", return_value=True)
141140
controller.model.muted_streams = set()
142141
mocker.patch(MODEL + ".is_muted_topic", return_value=False)
143142

@@ -186,10 +185,9 @@ def test_narrow_to_topic(
186185
controller.model.index = index_multiple_topic_msg
187186
controller.model.stream_id = initial_stream_id
188187
controller.view.message_view = mocker.patch("urwid.ListBox")
189-
controller.model.stream_dict = {
190-
stream_id: general_stream,
191-
}
192-
controller.model.stream_dict[stream_id]["name"] = stream_name
188+
mocker.patch(MODEL + ".stream_name_from_id", return_value=stream_name)
189+
mocker.patch(MODEL + ".stream_id_from_name", return_value=stream_id)
190+
mocker.patch(MODEL + ".is_user_subscribed_to_stream", return_value=True)
193191
controller.model.muted_streams = set()
194192
mocker.patch(MODEL + ".is_muted_topic", return_value=False)
195193

@@ -263,9 +261,7 @@ def test_narrow_to_all_messages(
263261
controller.view.message_view = mocker.patch("urwid.ListBox")
264262
controller.model.user_email = "some@email"
265263
controller.model.user_id = 1
266-
controller.model.stream_dict = {
267-
stream_id: general_stream,
268-
}
264+
mocker.patch(MODEL + ".is_user_subscribed_to_stream", return_value=True)
269265
controller.model.muted_streams = set()
270266
mocker.patch(MODEL + ".is_muted_topic", return_value=False)
271267

@@ -315,9 +311,7 @@ def test_narrow_to_all_starred(
315311
# FIXME: Expand upon is_muted_topic().
316312
mocker.patch(MODEL + ".is_muted_topic", return_value=False)
317313
controller.model.user_email = "some@email"
318-
controller.model.stream_dict = {
319-
stream_id: general_stream,
320-
}
314+
mocker.patch(MODEL + ".is_user_subscribed_to_stream", return_value=True)
321315
controller.view.message_view = mocker.patch("urwid.ListBox")
322316

323317
controller.narrow_to_all_starred() # FIXME: Add id narrowing test
@@ -345,9 +339,7 @@ def test_narrow_to_all_mentions(
345339
mocker.patch(MODEL + ".is_muted_topic", return_value=False)
346340
controller.model.user_email = "some@email"
347341
controller.model.user_id = 1
348-
controller.model.stream_dict = {
349-
stream_id: general_stream,
350-
}
342+
mocker.patch(MODEL + ".is_user_subscribed_to_stream", return_value=True)
351343
controller.view.message_view = mocker.patch("urwid.ListBox")
352344

353345
controller.narrow_to_all_mentions() # FIXME: Add id narrowing test

tests/ui/test_ui_tools.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,6 @@ def test_update_topics_list(
695695
):
696696
mocker.patch(SUBDIR + ".buttons.TopButton.__init__", return_value=None)
697697
set_focus_valign = mocker.patch(VIEWS + ".urwid.ListBox.set_focus_valign")
698-
topic_view.view.controller.model.stream_dict = {86: {"name": "PTEST"}}
699698
topic_view.view.controller.model.is_muted_topic = mocker.Mock(
700699
return_value=False
701700
)

tests/ui_tools/test_buttons.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,6 @@ def test_init_calls_top_button(
434434
is_resolved: bool,
435435
) -> None:
436436
controller = mocker.Mock()
437-
controller.model.stream_dict = {
438-
205: {"name": "PTEST"},
439-
86: {"name": "Django"},
440-
14: {"name": "GSoC"},
441-
}
442437
controller.model.is_muted_topic = mocker.Mock(return_value=False)
443438
view = mocker.Mock()
444439
top_button = mocker.patch(MODULE + ".TopButton.__init__")
@@ -488,7 +483,6 @@ def test_init_calls_mark_muted(
488483
controller.model.is_muted_topic = mocker.Mock(
489484
return_value=is_muted_topic_return_value
490485
)
491-
controller.model.stream_dict = {205: {"name": stream_name}}
492486
view = mocker.Mock()
493487
TopicButton(
494488
stream_id=205,
@@ -899,14 +893,12 @@ def test__parse_narrow_link(
899893
)
900894
def test__validate_narrow_link(
901895
self,
902-
stream_dict: Dict[int, Any],
903896
parsed_link: ParsedNarrowLink,
904897
is_user_subscribed_to_stream: Optional[bool],
905898
is_valid_stream: Optional[bool],
906899
topics_in_stream: Optional[List[str]],
907900
expected_error: str,
908901
) -> None:
909-
self.controller.model.stream_dict = stream_dict
910902
self.controller.model.is_user_subscribed_to_stream.return_value = (
911903
is_user_subscribed_to_stream
912904
)

tests/ui_tools/test_messages.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -746,11 +746,6 @@ def test_soup2markup(self, content, expected_markup, mocker):
746746
],
747747
)
748748
def test_main_view(self, mocker, message, last_message):
749-
self.model.stream_dict = {
750-
5: {
751-
"color": "#bd6",
752-
},
753-
}
754749
MessageBox(message, self.model, last_message)
755750

756751
@pytest.mark.parametrize(
@@ -825,11 +820,6 @@ def test_main_view_renders_slash_me(self, mocker, message, content, is_me_messag
825820
def test_main_view_generates_stream_header(
826821
self, mocker, message, to_vary_in_last_message
827822
):
828-
self.model.stream_dict = {
829-
5: {
830-
"color": "#bd6",
831-
},
832-
}
833823
last_message = dict(message, **to_vary_in_last_message)
834824
msg_box = MessageBox(message, self.model, last_message)
835825
view_components = msg_box.main_view()

0 commit comments

Comments
 (0)