Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

test_classes: Add functions to get read/unread user IDs for a message.

Saubhagya Patel3d33a054553a
diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py
index dabdaabab6e..5c08393b3fc 100644
--- a/zerver/lib/test_classes.py
+++ b/zerver/lib/test_classes.py
@@ -1264,6 +1264,22 @@ Output:
data = self.get_messages_response(anchor, num_before, num_after, use_first_unread_anchor)
return data["messages"]
+ def get_user_ids_for_whom_message_read(self, message_id: int) -> set[int]:
+ user_ids = set(
+ UserMessage.objects.filter(message_id=message_id)
+ .extra(where=[UserMessage.where_read()]) # noqa: S610
+ .values_list("user_profile_id", flat=True)
+ )
+ return user_ids
+
+ def get_user_ids_for_whom_message_unread(self, message_id: int) -> set[int]:
+ user_ids = set(
+ UserMessage.objects.filter(message_id=message_id)
+ .extra(where=[UserMessage.where_unread()]) # noqa: S610
+ .values_list("user_profile_id", flat=True)
+ )
+ return user_ids
+
def users_subscribed_to_stream(self, stream_name: str, realm: Realm) -> list[UserProfile]:
stream = Stream.objects.get(name=stream_name, realm=realm)
recipient = Recipient.objects.get(type_id=stream.id, type=Recipient.STREAM)
diff --git a/zerver/tests/test_message_move_topic.py b/zerver/tests/test_message_move_topic.py
index 911f5e9cb8b..bec0072ba7d 100644
--- a/zerver/tests/test_message_move_topic.py
+++ b/zerver/tests/test_message_move_topic.py
@@ -1666,20 +1666,11 @@ class MessageMoveTopicTest(ZulipTestCase):
)
# Check topic resolved notification message is only unread for participants.
- assert (
- UserMessage.objects.filter(
- user_profile__in=[admin_user, hamlet, aaron], message__id=messages[2].id
- )
- .extra(where=[UserMessage.where_unread()]) # noqa: S610
- .count()
- == 3
- )
+ unread_user_ids = self.get_user_ids_for_whom_message_unread(messages[2].id)
+ self.assertEqual(unread_user_ids, {admin_user.id, hamlet.id, aaron.id})
- assert (
- not UserMessage.objects.filter(user_profile=cordelia, message__id=messages[2].id)
- .extra(where=[UserMessage.where_unread()]) # noqa: S610
- .exists()
- )
+ read_user_ids = self.get_user_ids_for_whom_message_read(messages[2].id)
+ self.assertEqual(read_user_ids, {cordelia.id})
# Now move to a weird state and confirm we get the normal topic moved message.
weird_topic_name = "✔ ✔✔" + original_topic_name
@@ -1738,20 +1729,11 @@ class MessageMoveTopicTest(ZulipTestCase):
)
# Check topic unresolved notification message is only unread for participants.
- assert (
- UserMessage.objects.filter(
- user_profile__in=[admin_user, hamlet, aaron], message__id=messages[4].id
- )
- .extra(where=[UserMessage.where_unread()]) # noqa: S610
- .count()
- == 3
- )
+ unread_user_ids = self.get_user_ids_for_whom_message_unread(messages[4].id)
+ self.assertEqual(unread_user_ids, {admin_user.id, hamlet.id, aaron.id})
- assert (
- not UserMessage.objects.filter(user_profile=cordelia, message__id=messages[4].id)
- .extra(where=[UserMessage.where_unread()]) # noqa: S610
- .exists()
- )
+ read_user_ids = self.get_user_ids_for_whom_message_read(messages[4].id)
+ self.assertEqual(read_user_ids, {cordelia.id})
@override_settings(RESOLVE_TOPIC_UNDO_GRACE_PERIOD_SECONDS=60)
def test_mark_topic_as_resolved_within_grace_period(self) -> None: