Skip to content
176 changes: 127 additions & 49 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
CustomProfileField,
Message,
MessageType,
Stream,
Subscription,
)
from zulipterminal.config.keys import (
ZT_TO_URWID_CMD_MAPPING,
Expand Down Expand Up @@ -231,7 +233,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 @@ -243,21 +245,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": "general@example.comm",
"message_retention_days": 10,
"subscribers": [1001, 11, 12],
"history_public_to_subscribers": True,
"is_announcement_only": False,
"first_message_id": 1,
"email_notifications": False,
"wildcard_mentions_notify": False,
"is_web_public": 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 @@ -270,19 +276,23 @@ def secret_stream() -> Dict[str, Any]:
"color": "#ccc", # 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_announcement_only": False,
"first_message_id": 1,
"email_notifications": False,
"wildcard_mentions_notify": False,
"is_web_public": 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 @@ -295,23 +305,26 @@ 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,
"first_message_id": 1,
"email_notifications": False,
"wildcard_mentions_notify": False,
}


@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 @@ -326,19 +339,96 @@ 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_announcement_only": False,
"first_message_id": 1,
"email_notifications": False,
"wildcard_mentions_notify": False,
"is_web_public": False,
}
)
return deepcopy(streams)


@pytest.fixture
def unsubscribed_streams_fixture() -> List[Subscription]:
unsubscribed_streams: List[Subscription] = []
for i in range(3, 5):
unsubscribed_streams.append(
{
"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() -> List[Stream]:
never_subscribed_streams: List[Stream] = []
for i in range(5, 7):
never_subscribed_streams.append(
{
"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 all_stream_ids(
streams_fixture: List[Subscription],
unsubscribed_streams_fixture: List[Subscription],
never_subscribed_streams_fixture: List[Stream],
) -> List[int]:
return [
stream["stream_id"]
for stream in streams_fixture
+ unsubscribed_streams_fixture
+ never_subscribed_streams_fixture
]


@pytest.fixture
def realm_emojis() -> Dict[str, Dict[str, Any]]:
# Omitting source_url, author_id (server version 3.0),
Expand Down Expand Up @@ -872,7 +962,9 @@ def clean_custom_profile_data_fixture() -> List[CustomProfileData]:
def initial_data(
logged_on_user: Dict[str, Any],
users_fixture: List[Dict[str, Any]],
streams_fixture: List[Dict[str, Any]],
streams_fixture: List[Subscription],
unsubscribed_streams_fixture: List[Subscription],
never_subscribed_streams_fixture: List[Stream],
realm_emojis: Dict[str, Dict[str, Any]],
custom_profile_fields_fixture: List[Dict[str, Union[str, int]]],
) -> Dict[str, Any]:
Expand All @@ -884,24 +976,7 @@ def initial_data(
"email": logged_on_user["email"],
"user_id": logged_on_user["user_id"],
"realm_name": "Test Organization Name",
"unsubscribed": [
{
"audible_notifications": False,
"description": "announce",
"stream_id": 7,
"is_old_stream": True,
"desktop_notifications": False,
"pin_to_top": False,
"stream_weekly_traffic": 0,
"invite_only": False,
"name": "announce",
"push_notifications": False,
"email_address": "",
"color": "#bfd56f",
"is_muted": False,
"history_public_to_subscribers": True,
}
],
"unsubscribed": unsubscribed_streams_fixture,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor: I'd mention these changes to the fixtures in the commit text, even though we don't use them until now.

"result": "success",
"queue_id": "1522420755:786",
"realm_users": users_fixture,
Expand Down Expand Up @@ -950,24 +1025,7 @@ def initial_data(
"subscriptions": streams_fixture,
"msg": "",
"max_message_id": 552761,
"never_subscribed": [
{
"invite_only": False,
"description": "Announcements from the Zulip GCI Mentors",
"stream_id": 87,
"name": "GCI announce",
"is_old_stream": True,
"stream_weekly_traffic": 0,
},
{
"invite_only": False,
"description": "General discussion",
"stream_id": 74,
"name": "GCI general",
"is_old_stream": True,
"stream_weekly_traffic": 0,
},
],
"never_subscribed": never_subscribed_streams_fixture,
"unread_msgs": {
"pms": [
{"sender_id": 1, "unread_message_ids": [1, 2]},
Expand Down Expand Up @@ -1433,10 +1491,30 @@ 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 stream_dict(streams_fixture: List[Subscription]) -> Dict[int, Subscription]:
return {stream["stream_id"]: stream for stream in streams_fixture}


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


@pytest.fixture
def never_subscribed_streams(
never_subscribed_streams_fixture: List[Stream],
) -> Dict[int, Stream]:
return {
never_subscribed_stream["stream_id"]: never_subscribed_stream
for never_subscribed_stream in never_subscribed_streams_fixture
}


@pytest.fixture(
params=[
{
Expand Down
Loading