Skip to content

Add support for all streams #1408

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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
80e3344
model/api_types: Add data structures to support non-subscribed streams.
theViz343 May 31, 2023
82ed222
model: Add stream id accessor methods.
theViz343 Jun 6, 2023
d1a8eb7
refactor: model: Use get_stream_name instead of stream_dict.
theViz343 Jun 6, 2023
b51eae4
refactor: model/views: Use get_stream_subscribers instead of stream_d…
theViz343 Jun 6, 2023
80e0d5a
refactor: model: Use stream_date_created (get/set)ter methods.
theViz343 Jun 6, 2023
b6ab397
refactor: model: Use is_stream_web_public instead of stream_dict.
theViz343 Jun 6, 2023
55d8560
refactor: model: Use stream_message_retention_days (get/set)ter methods.
theViz343 Jun 6, 2023
023ea38
refactor: model: Use is_stream_invite_only instead of stream_dict.
theViz343 Jun 6, 2023
6282150
refactor: model/views: Use get_stream_post_policy accessor method.
theViz343 Jun 10, 2023
71d5bd0
refactor: model/views: Use is_stream_announcement_only accessor method.
theViz343 Jun 10, 2023
6a67577
refactor: model/views: Use is_stream_history_public_to_subscribers me…
theViz343 Jun 10, 2023
f451244
refactor: model/views: Use get_stream_weekly_traffic method.
theViz343 Jun 10, 2023
8d6e057
refactor: model/views: Use get_stream_rendered_description method.
theViz343 Jun 10, 2023
5e5bd20
model: Add get_all_subscription_ids accessor method.
theViz343 Jun 6, 2023
dee7e2b
refactor: model: Use get_subscription_color instead of stream_dict.
theViz343 Jun 6, 2023
e39bbe3
refactor: model/views: Use get_subscription_email instead of stream_d…
theViz343 Jun 10, 2023
5ca5ee6
refactor: model: Improve stream_dict typing.
theViz343 Jun 15, 2023
308fa13
refactor: model: Rename stream_dict to _subscribed_streams.
theViz343 Jun 15, 2023
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
117 changes: 103 additions & 14 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pytest_mock import MockerFixture
from urwid import Widget

from zulipterminal.api_types import Message, MessageType
from zulipterminal.api_types import Message, MessageType, Stream, Subscription
from zulipterminal.config.keys import (
ZT_TO_URWID_CMD_MAPPING,
keys_for_command,
Expand Down Expand Up @@ -207,7 +207,7 @@ def logged_on_user() -> Dict[str, Any]:


@pytest.fixture
def general_stream() -> Dict[str, Any]:
def general_stream() -> Subscription:
return {
"name": "Some general stream",
"date_created": 1472091253,
Expand All @@ -216,24 +216,29 @@ def general_stream() -> Dict[str, Any]:
"pin_to_top": False,
"stream_id": 1000,
"is_muted": False,
"is_web_public": False,
"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]",
"message_retention_days": 10,
"subscribers": [1001, 11, 12],
"history_public_to_subscribers": True,
"is_announcement_only": False,
"stream_post_policy": 0,
"first_message_id": 1,
"email_notifications": False,
"wildcard_mentions_notify": False,
}


# This is a private stream;
# only description/stream_id/invite_only/name/color vary from above
@pytest.fixture
def secret_stream() -> Dict[str, Any]:
def secret_stream() -> Subscription:
return {
"description": "Some private stream",
"stream_id": 99,
Expand All @@ -245,20 +250,25 @@ def secret_stream() -> Dict[str, Any]:
"rendered_description": "Some private stream",
"color": "#ccc", # Color in '#xxx' format
"is_muted": False,
"is_web_public": False,
"audible_notifications": False,
"is_old_stream": True,
"desktop_notifications": False,
"stream_weekly_traffic": 0,
"message_retention_days": -1,
"push_notifications": False,
"subscribers": [1001, 11],
"history_public_to_subscribers": False,
"is_announcement_only": False,
"stream_post_policy": 0,
"first_message_id": 1,
"email_notifications": False,
"wildcard_mentions_notify": False,
}


# Like public stream but with is_web_public=True
@pytest.fixture
def web_public_stream() -> Dict[str, Any]:
def web_public_stream() -> Subscription:
return {
"description": "Some web public stream",
"stream_id": 999,
Expand All @@ -271,23 +281,42 @@ def web_public_stream() -> Dict[str, Any]:
"color": "#ddd", # Color in '#xxx' format
"is_muted": False,
"audible_notifications": False,
"is_old_stream": True,
"desktop_notifications": False,
"stream_weekly_traffic": 0,
"message_retention_days": -1,
"push_notifications": False,
"subscribers": [1001, 11],
"history_public_to_subscribers": False,
"is_web_public": True,
"is_announcement_only": False,
"stream_post_policy": 0,
"first_message_id": 1,
"email_notifications": False,
"wildcard_mentions_notify": False,
}


@pytest.fixture
def get_stream_from_id_fixture(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this belong in the next commit?

I also have two concerns about this fixture, if we keep it:

  • what is stream id? how is it used via the fixture?
  • the body is very similar to the function itself

stream_id: int,
_subscribed_streams: Dict[int, Subscription],
unsubscribed_streams_fixture: Dict[int, Subscription],
never_subscribed_streams_fixture: Dict[int, Stream],
) -> Union[Subscription, Stream]:
if stream_id in _subscribed_streams:
return _subscribed_streams[stream_id]
elif stream_id in unsubscribed_streams_fixture:
return unsubscribed_streams_fixture[stream_id]
else:
return never_subscribed_streams_fixture[stream_id]


@pytest.fixture
def streams_fixture(
general_stream: Dict[str, Any],
secret_stream: Dict[str, Any],
web_public_stream: Dict[str, Any],
) -> List[Dict[str, Any]]:
general_stream: Subscription,
secret_stream: Subscription,
web_public_stream: Subscription,
) -> List[Subscription]:
streams = [general_stream, secret_stream, web_public_stream]
for i in range(1, 3):
streams.append(
Expand All @@ -302,14 +331,19 @@ def streams_fixture(
"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,
"push_notifications": False,
"message_retention_days": i + 30,
"email_address": f"stream{i}@example.com",
"subscribers": [1001, 11, 12],
"history_public_to_subscribers": True,
"is_web_public": False,
"is_announcement_only": False,
"stream_post_policy": 0,
"first_message_id": 1,
"email_notifications": False,
"wildcard_mentions_notify": False,
}
)
return deepcopy(streams)
Expand Down Expand Up @@ -630,7 +664,7 @@ def mentioned_messages_combination(request: Any) -> Tuple[Set[int], Set[int]]:
def initial_data(
logged_on_user: Dict[str, Any],
users_fixture: List[Dict[str, Any]],
streams_fixture: List[Dict[str, Any]],
streams_fixture: List[Dict[str, Subscription]],
realm_emojis: Dict[str, Dict[str, Any]],
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -1189,7 +1223,62 @@ def user_id(logged_on_user: Dict[str, Any]) -> int:


@pytest.fixture
def stream_dict(streams_fixture: List[Dict[str, Any]]) -> Dict[int, Any]:
def unsubscribed_streams_fixture() -> Dict[int, Subscription]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be easier to compare them if these were added near to the streams_fixture, which is currently much higher in the file :)

unsubscribed_streams: Dict[int, Subscription] = {}
for i in range(3, 5):
unsubscribed_streams[i] = {
"name": f"Stream {i}",
"date_created": 1472047124 + i,
"invite_only": False,
"color": "#b0a5fd",
"pin_to_top": False,
"stream_id": i,
"is_muted": False,
"audible_notifications": False,
"description": f"A description of stream {i}",
"rendered_description": f"A description of stream {i}",
"desktop_notifications": False,
"stream_weekly_traffic": 0,
"push_notifications": False,
"message_retention_days": i + 30,
"email_address": f"stream{i}@example.com",
"email_notifications": False,
"wildcard_mentions_notify": False,
"subscribers": [1001, 11, 12],
"history_public_to_subscribers": True,
"is_announcement_only": True,
"stream_post_policy": 0,
"is_web_public": True,
"first_message_id": None,
}
return deepcopy(unsubscribed_streams)


@pytest.fixture
def never_subscribed_streams_fixture() -> Dict[int, Stream]:
never_subscribed_streams: Dict[int, Stream] = {}
for i in range(5, 7):
never_subscribed_streams[i] = {
"name": f"Stream {i}",
"date_created": 1472047124 + i,
"invite_only": False,
"stream_id": i,
"description": f"A description of stream {i}",
"rendered_description": f"A description of stream {i}",
"stream_weekly_traffic": 0,
"message_retention_days": i + 30,
"subscribers": [1001, 11, 12],
"history_public_to_subscribers": True,
"is_announcement_only": True,
"stream_post_policy": 0,
"is_web_public": True,
"first_message_id": None,
}
return deepcopy(never_subscribed_streams)


@pytest.fixture
def _subscribed_streams(streams_fixture: List[Subscription]) -> Dict[int, Subscription]:
return {stream["stream_id"]: stream for stream in streams_fixture}


Expand Down
65 changes: 48 additions & 17 deletions tests/core/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pytest import param as case
from pytest_mock import MockerFixture

from zulipterminal.api_types import Subscription
from zulipterminal.config.themes import generate_theme
from zulipterminal.core import Controller
from zulipterminal.helper import Index
Expand Down Expand Up @@ -124,18 +125,24 @@ def test_narrow_to_stream(
mocker: MockerFixture,
controller: Controller,
index_stream: Index,
general_stream: Subscription,
stream_id: int = 205,
stream_name: str = "PTEST",
) -> None:
controller.model.narrow = []
controller.model.index = index_stream
controller.view.message_view = mocker.patch("urwid.ListBox")
controller.model.stream_dict = {
stream_id: {
controller.model._subscribed_streams = {
stream_id: general_stream,
}
controller.model._subscribed_streams[stream_id].update(
{
"color": "#ffffff",
"name": stream_name,
}
}
)
controller.model._unsubscribed_streams = {}
controller.model._never_subscribed_streams = {}
controller.model.muted_streams = set()
mocker.patch(MODEL + ".is_muted_topic", return_value=False)

Expand Down Expand Up @@ -171,6 +178,7 @@ def test_narrow_to_topic(
initial_stream_id: Optional[int],
anchor: Optional[int],
expected_final_focus: int,
general_stream: Subscription,
stream_name: str = "PTEST",
topic_name: str = "Test",
stream_id: int = 205,
Expand All @@ -183,12 +191,17 @@ def test_narrow_to_topic(
controller.model.index = index_multiple_topic_msg
controller.model.stream_id = initial_stream_id
controller.view.message_view = mocker.patch("urwid.ListBox")
controller.model.stream_dict = {
stream_id: {
controller.model._subscribed_streams = {
stream_id: general_stream,
}
controller.model._subscribed_streams[stream_id].update(
{
"color": "#ffffff",
"name": stream_name,
}
}
)
controller.model._unsubscribed_streams = {}
controller.model._never_subscribed_streams = {}
controller.model.muted_streams = set()
mocker.patch(MODEL + ".is_muted_topic", return_value=False)

Expand Down Expand Up @@ -246,18 +259,22 @@ def test_narrow_to_all_messages(
controller: Controller,
index_all_messages: Index,
anchor: Optional[int],
general_stream: Subscription,
expected_final_focus_msg_id: int,
) -> None:
controller.model.narrow = [["stream", "PTEST"]]
controller.model.index = index_all_messages
controller.view.message_view = mocker.patch("urwid.ListBox")
controller.model.user_email = "some@email"
controller.model.user_id = 1
controller.model.stream_dict = {
205: {
controller.model._subscribed_streams = {
205: general_stream,
}
controller.model._subscribed_streams[205].update(
{
"color": "#ffffff",
}
}
)
controller.model.muted_streams = set()
mocker.patch(MODEL + ".is_muted_topic", return_value=False)

Expand Down Expand Up @@ -293,7 +310,11 @@ def test_narrow_to_all_pm(
assert msg_ids == id_list

def test_narrow_to_all_starred(
self, mocker: MockerFixture, controller: Controller, index_all_starred: Index
self,
mocker: MockerFixture,
controller: Controller,
index_all_starred: Index,
general_stream: Subscription,
) -> None:
controller.model.narrow = []
controller.model.index = index_all_starred
Expand All @@ -302,11 +323,14 @@ def test_narrow_to_all_starred(
# FIXME: Expand upon is_muted_topic().
mocker.patch(MODEL + ".is_muted_topic", return_value=False)
controller.model.user_email = "some@email"
controller.model.stream_dict = {
205: {
controller.model._subscribed_streams = {
205: general_stream,
}
controller.model._subscribed_streams[205].update(
{
"color": "#ffffff",
}
}
)
controller.view.message_view = mocker.patch("urwid.ListBox")

controller.narrow_to_all_starred() # FIXME: Add id narrowing test
Expand All @@ -320,7 +344,11 @@ def test_narrow_to_all_starred(
assert msg_ids == id_list

def test_narrow_to_all_mentions(
self, mocker: MockerFixture, controller: Controller, index_all_mentions: Index
self,
mocker: MockerFixture,
controller: Controller,
index_all_mentions: Index,
general_stream: Subscription,
) -> None:
controller.model.narrow = []
controller.model.index = index_all_mentions
Expand All @@ -329,11 +357,14 @@ def test_narrow_to_all_mentions(
mocker.patch(MODEL + ".is_muted_topic", return_value=False)
controller.model.user_email = "some@email"
controller.model.user_id = 1
controller.model.stream_dict = {
205: {
controller.model._subscribed_streams = {
205: general_stream,
}
controller.model._subscribed_streams[205].update(
{
"color": "#ffffff",
}
}
)
controller.view.message_view = mocker.patch("urwid.ListBox")

controller.narrow_to_all_mentions() # FIXME: Add id narrowing test
Expand Down
Loading