Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
46 changes: 31 additions & 15 deletions tests/conftest.py
Original file line number Diff line number Diff line change
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 @@ -220,21 +220,25 @@ def general_stream() -> Dict[str, Any]:
"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 @@ -248,19 +252,23 @@ def secret_stream() -> Dict[str, Any]:
"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 @@ -273,24 +281,28 @@ 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,
stream_dict: Dict[int, Any],
stream_dict: Dict[int, Subscription],
unsubscribed_streams_fixture: Dict[int, Subscription],
never_subscribed_streams_fixture: Dict[int, Stream],
) -> Union[Subscription, Stream, Any]:
) -> Union[Subscription, Stream]:
if stream_id in stream_dict:
return stream_dict[stream_id]
elif stream_id in unsubscribed_streams_fixture:
Expand All @@ -301,10 +313,10 @@ def get_stream_from_id_fixture(

@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 @@ -319,7 +331,6 @@ 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,
Expand All @@ -328,6 +339,11 @@ def streams_fixture(
"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 @@ -648,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 @@ -1262,7 +1278,7 @@ def never_subscribed_streams_fixture() -> Dict[int, Stream]:


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


Expand Down
51 changes: 39 additions & 12 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,22 @@ 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: {
stream_id: general_stream,
}
controller.model.stream_dict[stream_id].update(
{
"color": "#ffffff",
"name": stream_name,
}
}
)
controller.model._unsubscribed_streams = {}
controller.model._never_subscribed_streams = {}
controller.model.muted_streams = set()
Expand Down Expand Up @@ -173,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 @@ -186,11 +192,14 @@ def test_narrow_to_topic(
controller.model.stream_id = initial_stream_id
controller.view.message_view = mocker.patch("urwid.ListBox")
controller.model.stream_dict = {
stream_id: {
stream_id: general_stream,
}
controller.model.stream_dict[stream_id].update(
{
"color": "#ffffff",
"name": stream_name,
}
}
)
controller.model._unsubscribed_streams = {}
controller.model._never_subscribed_streams = {}
controller.model.muted_streams = set()
Expand Down Expand Up @@ -250,6 +259,7 @@ 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"]]
Expand All @@ -258,10 +268,13 @@ def test_narrow_to_all_messages(
controller.model.user_email = "some@email"
controller.model.user_id = 1
controller.model.stream_dict = {
205: {
205: general_stream,
}
controller.model.stream_dict[205].update(
{
"color": "#ffffff",
}
}
)
controller.model.muted_streams = set()
mocker.patch(MODEL + ".is_muted_topic", return_value=False)

Expand Down Expand Up @@ -297,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 @@ -307,10 +324,13 @@ def test_narrow_to_all_starred(
mocker.patch(MODEL + ".is_muted_topic", return_value=False)
controller.model.user_email = "some@email"
controller.model.stream_dict = {
205: {
205: general_stream,
}
controller.model.stream_dict[205].update(
{
"color": "#ffffff",
}
}
)
controller.view.message_view = mocker.patch("urwid.ListBox")

controller.narrow_to_all_starred() # FIXME: Add id narrowing test
Expand All @@ -324,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 @@ -334,10 +358,13 @@ def test_narrow_to_all_mentions(
controller.model.user_email = "some@email"
controller.model.user_id = 1
controller.model.stream_dict = {
205: {
205: general_stream,
}
controller.model.stream_dict[205].update(
{
"color": "#ffffff",
}
}
)
controller.view.message_view = mocker.patch("urwid.ListBox")

controller.narrow_to_all_mentions() # FIXME: Add id narrowing test
Expand Down
4 changes: 2 additions & 2 deletions tests/helper/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pytest import param as case
from pytest_mock import MockerFixture

from zulipterminal.api_types import Composition
from zulipterminal.api_types import Composition, Subscription
from zulipterminal.config.keys import primary_key_for_command
from zulipterminal.helper import (
Index,
Expand Down Expand Up @@ -278,7 +278,7 @@ def test_powerset(
def test_classify_unread_counts(
mocker: MockerFixture,
initial_data: Dict[str, Any],
stream_dict: Dict[int, Dict[str, Any]],
stream_dict: Dict[int, Subscription],
classified_unread_counts: Dict[str, Any],
muted_topics: List[List[str]],
muted_streams: Set[int],
Expand Down
18 changes: 13 additions & 5 deletions tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1680,14 +1680,18 @@ def test_get_all_users(self, mocker, initial_data, user_list, user_dict, user_id
"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": None,
"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,
},
),
case(
Expand Down Expand Up @@ -2096,8 +2100,10 @@ def test_is_stream_invite_only(
[
case(
1000,
{},
None,
{
"stream_post_policy": 0,
},
0,
),
case(
3,
Expand Down Expand Up @@ -2136,8 +2142,10 @@ def test_get_stream_post_policy(
[
case(
1000,
{},
None,
{
"is_announcement_only": True,
},
True,
),
case(
3,
Expand Down
9 changes: 5 additions & 4 deletions tests/ui_tools/test_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pytest_mock import MockerFixture
from urwid import Widget

from zulipterminal.api_types import Subscription
from zulipterminal.config.keys import keys_for_command, primary_key_for_command
from zulipterminal.config.symbols import (
INVALID_MARKER,
Expand Down Expand Up @@ -153,7 +154,7 @@ def test_generic_autocomplete_stream_and_topic(
is_valid_stream: bool,
required_typeahead: Optional[str],
topics: List[str],
stream_dict: Dict[int, Dict[str, Any]],
stream_dict: Dict[int, Subscription],
) -> None:
write_box.model.topics_in_stream.return_value = topics
write_box.model.is_valid_stream.return_value = is_valid_stream
Expand Down Expand Up @@ -573,7 +574,7 @@ def test_generic_autocomplete_set_footer(
state: Optional[int],
footer_text: List[Any],
text: str,
stream_dict: Dict[int, Dict[str, Any]],
stream_dict: Dict[int, Subscription],
) -> None:
write_box.view.set_typeahead_footer = mocker.patch(
"zulipterminal.ui.View.set_typeahead_footer"
Expand Down Expand Up @@ -940,7 +941,7 @@ def test_generic_autocomplete_streams(
text: str,
state_and_required_typeahead: Dict[int, Optional[str]],
stream_categories: Dict[str, Any],
stream_dict: Dict[int, Dict[str, Any]],
stream_dict: Dict[int, Subscription],
) -> None:
streams_to_pin = (
[{"name": stream_name} for stream_name in stream_categories["pinned"]]
Expand Down Expand Up @@ -1279,7 +1280,7 @@ def test__set_stream_write_box_style_markers(
is_valid_stream: bool,
stream_access_type: StreamAccessType,
expected_marker: str,
stream_dict: Dict[int, Any],
stream_dict: Dict[int, Subscription],
expected_color: str,
) -> None:
# FIXME: Refactor when we have ~ Model.is_private_stream
Expand Down
Loading