Skip to content

Define and use Stream data fixture from conftest #1115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 41 additions & 33 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,45 +192,52 @@ def logged_on_user():
}


general_stream = {
"name": "Some general stream",
"invite_only": False,
"color": "#b0a5fd", # Color in '#xxxxxx' format
"pin_to_top": False,
"stream_id": 1000,
"in_home_view": True,
"audible_notifications": False,
"description": "General Stream",
"is_old_stream": True,
"desktop_notifications": False,
"stream_weekly_traffic": 0,
"push_notifications": False,
"email_address": "[email protected]",
"subscribers": [1001, 11, 12],
}
@pytest.fixture
def general_stream():
return {
"name": "Some general stream",
"invite_only": False,
"color": "#b0a5fd", # Color in '#xxxxxx' format
"pin_to_top": False,
"stream_id": 1000,
"in_home_view": True,
"audible_notifications": False,
"description": "General Stream",
"rendered_description": "General Stream",
"is_old_stream": True,
"desktop_notifications": False,
"stream_weekly_traffic": 0,
"push_notifications": False,
"email_address": "[email protected]",
"subscribers": [1001, 11, 12],
}


# This is a private stream;
# only description/stream_id/invite_only/name/color vary from above
secret_stream = {
"description": "Some private stream",
"stream_id": 99,
"pin_to_top": False,
"invite_only": True,
"name": "Secret stream",
"email_address": "[email protected]",
"color": "#ccc", # Color in '#xxx' format
"in_home_view": True,
"audible_notifications": False,
"is_old_stream": True,
"desktop_notifications": False,
"stream_weekly_traffic": 0,
"push_notifications": False,
"subscribers": [1001, 11],
}
@pytest.fixture
def secret_stream():
return {
"description": "Some private stream",
"stream_id": 99,
"pin_to_top": False,
"invite_only": True,
"name": "Secret stream",
"email_address": "[email protected]",
"rendered_description": "Some private stream",
"color": "#ccc", # Color in '#xxx' format
"in_home_view": True,
"audible_notifications": False,
"is_old_stream": True,
"desktop_notifications": False,
"stream_weekly_traffic": 0,
"push_notifications": False,
"subscribers": [1001, 11],
}


@pytest.fixture
def streams_fixture():
def streams_fixture(general_stream, secret_stream):
streams = [general_stream, secret_stream]
for i in range(1, 3):
streams.append(
Expand All @@ -243,6 +250,7 @@ def streams_fixture():
"in_home_view": True,
"audible_notifications": False,
"description": f"A description of stream {i}",
"rendered_description": f"A description of stream {i}",
"is_old_stream": True,
"desktop_notifications": False,
"stream_weekly_traffic": 0,
Expand Down
33 changes: 8 additions & 25 deletions tests/ui_tools/test_popups.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ def test_keypress_navigation(

class TestStreamInfoView:
@pytest.fixture(autouse=True)
def mock_external_classes(self, mocker, monkeypatch):
def mock_external_classes(self, mocker, general_stream):
self.controller = mocker.Mock()
mocker.patch.object(
self.controller, "maximum_popup_dimensions", return_value=(64, 64)
Expand All @@ -1123,16 +1123,8 @@ def mock_external_classes(self, mocker, monkeypatch):
self.controller.model.is_pinned_stream.return_value = False
self.controller.model.is_visual_notifications_enabled.return_value = False
mocker.patch(LISTWALKER, return_value=[])
self.stream_id = 10
self.controller.model.stream_dict = {
self.stream_id: {
"name": "books",
"invite_only": False,
"rendered_description": "<p>Hey</p>",
"subscribers": [],
"stream_weekly_traffic": 123,
}
}
self.stream_id = general_stream["stream_id"]
self.controller.model.stream_dict = {self.stream_id: general_stream}
self.stream_info_view = StreamInfoView(self.controller, self.stream_id)

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

@pytest.mark.parametrize("key", keys_for_command("STREAM_MEMBERS"))
def test_keypress_stream_members(self, mocker, key, widget_size):
def test_keypress_stream_members(self, key, widget_size):
size = widget_size(self.stream_info_view)
self.stream_info_view.keypress(size, key)
self.controller.show_stream_members.assert_called_once_with(
Expand Down Expand Up @@ -1174,20 +1166,11 @@ def test_keypress_stream_members(self, mocker, key, widget_size):
),
],
)
def test_markup_descrption(
self, rendered_description, expected_markup, stream_id=10
):
self.controller.model.stream_dict = {
stream_id: {
"name": "ZT",
"invite_only": False,
"subscribers": [],
"stream_weekly_traffic": 123,
"rendered_description": rendered_description,
}
}
def test_markup_descrption(self, rendered_description, expected_markup):
model = self.controller.model
model.stream_dict[self.stream_id]["rendered_description"] = rendered_description

stream_info_view = StreamInfoView(self.controller, stream_id)
stream_info_view = StreamInfoView(self.controller, self.stream_id)

assert stream_info_view.markup_desc == expected_markup

Expand Down