Skip to content

Commit 84316c3

Browse files
committed
tests: popups: Use fixtures instead of defining custom stream dict.
This commit refactors test functions within TestStreamInfo to use the general_stream fixture from conftest, instead of defining custom stream dictionaries inside the test body. This will be helpful when we add typing in test_popups.py, plus we get to re-use the defined fixtures which prevents code duplication. The commit also filters out a few unused parameters in the test functions.
1 parent 2c9b532 commit 84316c3

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

tests/ui_tools/test_popups.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ def test_keypress_navigation(
11141114

11151115
class TestStreamInfoView:
11161116
@pytest.fixture(autouse=True)
1117-
def mock_external_classes(self, mocker, monkeypatch):
1117+
def mock_external_classes(self, mocker, general_stream):
11181118
self.controller = mocker.Mock()
11191119
mocker.patch.object(
11201120
self.controller, "maximum_popup_dimensions", return_value=(64, 64)
@@ -1123,16 +1123,8 @@ def mock_external_classes(self, mocker, monkeypatch):
11231123
self.controller.model.is_pinned_stream.return_value = False
11241124
self.controller.model.is_visual_notifications_enabled.return_value = False
11251125
mocker.patch(LISTWALKER, return_value=[])
1126-
self.stream_id = 10
1127-
self.controller.model.stream_dict = {
1128-
self.stream_id: {
1129-
"name": "books",
1130-
"invite_only": False,
1131-
"rendered_description": "<p>Hey</p>",
1132-
"subscribers": [],
1133-
"stream_weekly_traffic": 123,
1134-
}
1135-
}
1126+
self.stream_id = general_stream["stream_id"]
1127+
self.controller.model.stream_dict = {self.stream_id: general_stream}
11361128
self.stream_info_view = StreamInfoView(self.controller, self.stream_id)
11371129

11381130
def test_keypress_any_key(self, widget_size):
@@ -1142,7 +1134,7 @@ def test_keypress_any_key(self, widget_size):
11421134
assert not self.controller.exit_popup.called
11431135

11441136
@pytest.mark.parametrize("key", keys_for_command("STREAM_MEMBERS"))
1145-
def test_keypress_stream_members(self, mocker, key, widget_size):
1137+
def test_keypress_stream_members(self, key, widget_size):
11461138
size = widget_size(self.stream_info_view)
11471139
self.stream_info_view.keypress(size, key)
11481140
self.controller.show_stream_members.assert_called_once_with(
@@ -1174,20 +1166,11 @@ def test_keypress_stream_members(self, mocker, key, widget_size):
11741166
),
11751167
],
11761168
)
1177-
def test_markup_descrption(
1178-
self, rendered_description, expected_markup, stream_id=10
1179-
):
1180-
self.controller.model.stream_dict = {
1181-
stream_id: {
1182-
"name": "ZT",
1183-
"invite_only": False,
1184-
"subscribers": [],
1185-
"stream_weekly_traffic": 123,
1186-
"rendered_description": rendered_description,
1187-
}
1188-
}
1169+
def test_markup_descrption(self, rendered_description, expected_markup):
1170+
model = self.controller.model
1171+
model.stream_dict[self.stream_id]["rendered_description"] = rendered_description
11891172

1190-
stream_info_view = StreamInfoView(self.controller, stream_id)
1173+
stream_info_view = StreamInfoView(self.controller, self.stream_id)
11911174

11921175
assert stream_info_view.markup_desc == expected_markup
11931176

0 commit comments

Comments
 (0)