Skip to content
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

Migrated internal code to use Direct Message terminology #1406

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
88 changes: 44 additions & 44 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,19 @@ def general_stream() -> Dict[str, Any]:
}


# This is a private stream;
# This is a direct stream;
# only description/stream_id/invite_only/name/color vary from above
@pytest.fixture
def secret_stream() -> Dict[str, Any]:
return {
"description": "Some private stream",
"description": "Some direct stream",
"stream_id": 99,
"pin_to_top": False,
"invite_only": True,
"name": "Secret stream",
"date_created": 1472047124,
"email_address": "secret@example.com",
"rendered_description": "Some private stream",
"rendered_description": "Some direct stream",
"color": "#ccc", # Color in '#xxx' format
"is_muted": False,
"audible_notifications": False,
Expand Down Expand Up @@ -401,7 +401,7 @@ def display_recipient_factory(
recipient_details_list: List[Tuple[int, str]]
) -> List[Dict[str, Any]]:
"""
Generate display_recipient field for (PM/group) messages
Generate display_recipient field for (DM/group) messages
"""
return [
{
Expand All @@ -424,9 +424,9 @@ def msg_template_factory(
recipients: Union[str, List[Dict[str, Any]]] = "PTEST",
) -> Message:
"""
Generate message template for all types of messages(stream/PM/group)
Generate message template for all types of messages(stream/DM/group)
"""
# TODO: Separate Message into distinct types for stream and private messages.
# TODO: Separate Message into distinct types for stream and direct messages.
message = Message(
id=msg_id,
sender_full_name="Foo Foo",
Expand Down Expand Up @@ -476,31 +476,31 @@ def extra_stream_msg_template() -> Message:


@pytest.fixture
def pm_template() -> Message:
def dm_template() -> Message:
recipients = display_recipient_factory([(5179, "Boo Boo"), (5140, "Foo Foo")])
return msg_template_factory(537287, "private", 1520918736, recipients=recipients)
return msg_template_factory(537287, "direct", 1520918736, recipients=recipients)


@pytest.fixture
def group_pm_template() -> Message:
def group_dm_template() -> Message:
recipients = display_recipient_factory(
[(5179, "Boo Boo"), (5140, "Foo Foo"), (5180, "Bar Bar")]
)
return msg_template_factory(537288, "private", 1520918737, recipients=recipients)
return msg_template_factory(537288, "direct", 1520918737, recipients=recipients)


@pytest.fixture(params=["pm_template", "group_pm_template"])
def private_message_fixture(request: Any) -> Message:
@pytest.fixture(params=["dm_template", "group_dm_template"])
def direct_message_fixture(request: Any) -> Message:
return request.getfixturevalue(request.param)


@pytest.fixture(
params=["stream_msg_template", "pm_template", "group_pm_template"],
ids=["stream_message", "pm_message", "group_pm_message"],
params=["stream_msg_template", "dm_template", "group_dm_template"],
ids=["stream_message", "dm_message", "group_dm_message"],
)
def message_fixture(request: Any) -> Message:
"""
Acts as a parametrize fixture for stream msg, pms and group_pms.
Acts as a parametrize fixture for stream msg, dms and group_dms.
"""
# `request` currently does not have an exported Pytest type.
# TODO: Use the exported type when it's made available.
Expand All @@ -511,8 +511,8 @@ def message_fixture(request: Any) -> Message:
@pytest.fixture
def messages_successful_response(
stream_msg_template: Message,
pm_template: Message,
group_pm_template: Message,
dm_template: Message,
group_dm_template: Message,
) -> Dict[str, Any]:
"""
A successful response from a /messages API query.
Expand All @@ -522,8 +522,8 @@ def messages_successful_response(
"anchor": 10000000000000000,
"messages": [
stream_msg_template,
pm_template,
group_pm_template,
dm_template,
group_dm_template,
],
"result": "success",
"msg": "",
Expand Down Expand Up @@ -610,10 +610,10 @@ def topics() -> List[str]:
],
ids=[
"stream_mention__stream_wildcard",
"stream+pm_mention__no_wildcard",
"no_mention__stream+pm_wildcard",
"stream+group_mention__pm_wildcard",
"pm_mention__stream+group_wildcard",
"stream+dm_mention__no_wildcard",
"no_mention__stream+dm_wildcard",
"stream+group_mention__dm_wildcard",
"dm_mention__stream+group_wildcard",
"group_mention__all_wildcard",
"all_mention__stream_wildcard",
"stream+group_mention__wildcard",
Expand Down Expand Up @@ -726,7 +726,7 @@ def initial_data(
},
],
"unread_msgs": {
"pms": [
"dms": [
{"sender_id": 1, "unread_message_ids": [1, 2]},
{"sender_id": 2, "unread_message_ids": [3]},
],
Expand All @@ -741,7 +741,7 @@ def initial_data(
},
{
"stream_id": 99,
"topic": "Some private unread topic",
"topic": "Some direct unread topic",
"unread_message_ids": [7],
"sender_ids": [1, 2],
},
Expand Down Expand Up @@ -795,7 +795,7 @@ def initial_data(
},
},
"twenty_four_hour_time": True,
"pm_content_in_desktop_notifications": True,
"dm_content_in_desktop_notifications": True,
"realm_emoji": realm_emojis,
"realm_message_retention_days": 74,
"last_event_id": -1,
Expand All @@ -816,16 +816,16 @@ def initial_index() -> Index:

@pytest.fixture
def empty_index(
stream_msg_template: Message, pm_template: Message, group_pm_template: Message
stream_msg_template: Message, dm_template: Message, group_dm_template: Message
) -> Index:
return deepcopy(
Index(
pointer=dict(),
all_msg_ids=set(),
starred_msg_ids=set(),
mentioned_msg_ids=set(),
private_msg_ids=set(),
private_msg_ids_by_user_ids=defaultdict(set, {}),
direct_msg_ids=set(),
direct_msg_ids_by_user_ids=defaultdict(set, {}),
stream_msg_ids_by_stream_id=defaultdict(set, {}),
topic_msg_ids=defaultdict(dict, {}),
edited_messages=set(),
Expand All @@ -835,8 +835,8 @@ def empty_index(
lambda: {},
{
stream_msg_template["id"]: stream_msg_template,
pm_template["id"]: pm_template,
group_pm_template["id"]: group_pm_template,
dm_template["id"]: dm_template,
group_dm_template["id"]: group_dm_template,
},
),
)
Expand All @@ -860,7 +860,7 @@ def index_stream(empty_index: Index) -> Index:
"""
index = empty_index
index["stream_msg_ids_by_stream_id"] = defaultdict(set, {205: {537286}})
index["private_msg_ids"] = {537287, 537288}
index["direct_msg_ids"] = {537287, 537288}
return index


Expand Down Expand Up @@ -896,26 +896,26 @@ def index_multiple_topic_msg(
@pytest.fixture
def index_user(empty_index: Index) -> Index:
"""
Expected index of initial_data when model.narrow = [['pm_with',
Expected index of initial_data when model.narrow = [['dm_with',
'boo@zulip.com'],
"""
user_ids = frozenset({5179, 5140})
index = empty_index
index["private_msg_ids_by_user_ids"] = defaultdict(set, {user_ids: {537287}})
index["private_msg_ids"] = {537287, 537288}
index["direct_msg_ids_by_user_ids"] = defaultdict(set, {user_ids: {537287}})
index["direct_msg_ids"] = {537287, 537288}
return index


@pytest.fixture
def index_user_multiple(empty_index: Index) -> Index:
"""
Expected index of initial_data when model.narrow = [['pm_with',
Expected index of initial_data when model.narrow = [['dm_with',
'boo@zulip.com, bar@zulip.com'],
"""
user_ids = frozenset({5179, 5140, 5180})
index = empty_index
index["private_msg_ids_by_user_ids"] = defaultdict(set, {user_ids: {537288}})
index["private_msg_ids"] = {537287, 537288}
index["direct_msg_ids_by_user_ids"] = defaultdict(set, {user_ids: {537288}})
index["direct_msg_ids"] = {537287, 537288}
return index


Expand All @@ -934,7 +934,7 @@ def index_all_starred(empty_index: Index, request: Any) -> Index:
msgs_with_stars = request.param
index = empty_index
index["starred_msg_ids"] = msgs_with_stars
index["private_msg_ids"] = {537287, 537288}
index["direct_msg_ids"] = {537287, 537288}
for msg_id, msg in index["messages"].items():
if msg_id in msgs_with_stars and "starred" not in msg["flags"]:
msg["flags"].append("starred")
Expand All @@ -948,7 +948,7 @@ def index_all_mentions(
mentioned_messages, wildcard_mentioned_messages = mentioned_messages_combination
index = empty_index
index["mentioned_msg_ids"] = mentioned_messages | wildcard_mentioned_messages
index["private_msg_ids"] = {537287, 537288}
index["direct_msg_ids"] = {537287, 537288}
for msg_id, msg in index["messages"].items():
if msg_id in mentioned_messages and "mentioned" not in msg["flags"]:
msg["flags"].append("mentioned")
Expand Down Expand Up @@ -1145,7 +1145,7 @@ def streams() -> List[Dict[str, Any]]:
"id": 99,
"color": "#ccc",
"invite_only": True,
"description": "Some private stream",
"description": "Some direct stream",
},
{
"name": "Some general stream",
Expand Down Expand Up @@ -1224,12 +1224,12 @@ def classified_unread_counts() -> Dict[str, Any]:
"""
return {
"all_msg": 12,
"all_pms": 8,
"all_dms": 8,
"unread_topics": {
(1000, "Some general unread topic"): 3,
(99, "Some private unread topic"): 1,
(99, "Some direct unread topic"): 1,
},
"unread_pms": {
"unread_dms": {
1: 2,
2: 1,
},
Expand Down
22 changes: 11 additions & 11 deletions tests/core/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,12 @@ def test_narrow_to_user(

controller.narrow_to_user(recipient_emails=emails)

assert controller.model.narrow == [["pm-with", user_email]]
assert controller.model.narrow == [["dm-with", user_email]]
controller.view.message_view.log.clear.assert_called_once_with()
recipients = frozenset([controller.model.user_id, user_id])
assert controller.model.recipients == recipients
widget = controller.view.message_view.log.extend.call_args_list[0][0][0][0]
id_list = index_user["private_msg_ids_by_user_ids"][recipients]
id_list = index_user["direct_msg_ids_by_user_ids"][recipients]
assert {widget.original_widget.message["id"]} == id_list

@pytest.mark.parametrize(
Expand Down Expand Up @@ -273,7 +273,7 @@ def test_narrow_to_all_messages(
assert msg_ids == id_list
assert final_focus_msg_id == expected_final_focus_msg_id

def test_narrow_to_all_pm(
def test_narrow_to_all_dm(
self, mocker: MockerFixture, controller: Controller, index_user: Index
) -> None:
controller.model.narrow = []
Expand All @@ -282,13 +282,13 @@ def test_narrow_to_all_pm(
controller.model.user_id = 1
controller.model.user_email = "some@email"

controller.narrow_to_all_pm() # FIXME: Add id narrowing test
controller.narrow_to_all_dm() # FIXME: Add id narrowing test

assert controller.model.narrow == [["is", "private"]]
assert controller.model.narrow == [["is", "direct"]]
controller.view.message_view.log.clear.assert_called_once_with()

widgets = controller.view.message_view.log.extend.call_args_list[0][0][0]
id_list = index_user["private_msg_ids"]
id_list = index_user["direct_msg_ids"]
msg_ids = {widget.original_widget.message["id"] for widget in widgets}
assert msg_ids == id_list

Expand Down Expand Up @@ -474,8 +474,8 @@ def test_stream_muting_confirmation_popup(
([["search", "BOO"]], [["search", "FOO"]]),
([["stream", "PTEST"]], [["stream", "PTEST"], ["search", "FOO"]]),
(
[["pm-with", "foo@zulip.com"], ["search", "BOO"]],
[["pm-with", "foo@zulip.com"], ["search", "FOO"]],
[["dm-with", "foo@zulip.com"], ["search", "BOO"]],
[["dm-with", "foo@zulip.com"], ["search", "FOO"]],
),
(
[["stream", "PTEST"], ["topic", "RDS"]],
Expand All @@ -486,7 +486,7 @@ def test_stream_muting_confirmation_popup(
"Default_all_msg_search",
"redo_default_search",
"search_within_stream",
"pm_search_again",
"dm_search_again",
"search_within_topic_narrow",
],
)
Expand Down Expand Up @@ -551,8 +551,8 @@ def test_maximum_popup_dimensions(
@pytest.mark.parametrize(
"active_conversation_info",
[
case({"sender_name": "hamlet"}, id="in_pm_narrow_with_sender_typing:start"),
case({}, id="in_pm_narrow_with_sender_typing:stop"),
case({"sender_name": "hamlet"}, id="in_dm_narrow_with_sender_typing:start"),
case({}, id="in_dm_narrow_with_sender_typing:stop"),
],
)
def test_show_typing_notification(
Expand Down
Loading
Loading