push_notifications: Test message content truncated in a simple manner.

'test_get_message_payload_gcm_stream_message' verifies the payload
for notifications generated (for stream messages) due to any of the
push notification triggers, including
'NotificationTriggers.STREAM_PUSH'.

Earlier, 'test_get_message_payload_gcm_stream_notifications' tested
the same thing as 'test_get_message_payload_gcm_stream_message' with
the only difference that it included content that was not truncated.

This commit removes the test
'test_get_message_payload_gcm_stream_notifications' and updates
the test 'test_get_message_payload_gcm_stream_message' to cover
both the cases, i.e., truncated as well as not truncated content.
This commit is contained in:
Prakhar Pratyush 2023-08-29 20:22:45 +05:30 committed by Tim Abbott
parent 5d8897b909
commit 9cff7e14c4
1 changed files with 12 additions and 39 deletions

View File

@ -2231,14 +2231,18 @@ class TestGetAPNsPayload(PushNotificationTest):
class TestGetGCMPayload(PushNotificationTest):
def _test_get_message_payload_gcm_stream_message(
self,
truncate_content: bool = False,
mentioned_user_group_id: Optional[int] = None,
mentioned_user_group_name: Optional[str] = None,
) -> None:
stream = Stream.objects.filter(name="Verona").get()
message = self.get_message(Recipient.STREAM, stream.id, stream.realm_id)
content = message.content
if truncate_content:
message.content = "a" * 210
message.rendered_content = "a" * 210
message.save()
content = "a" * 200 + ""
hamlet = self.example_user("hamlet")
payload, gcm_options = get_message_payload_gcm(
@ -2249,8 +2253,8 @@ class TestGetGCMPayload(PushNotificationTest):
"event": "message",
"zulip_message_id": message.id,
"time": datetime_to_timestamp(message.date_sent),
"content": "a" * 200 + "",
"content_truncated": True,
"content": content,
"content_truncated": truncate_content,
"server": settings.EXTERNAL_HOST,
"realm_id": hamlet.realm.id,
"realm_uri": hamlet.realm.uri,
@ -2281,6 +2285,9 @@ class TestGetGCMPayload(PushNotificationTest):
def test_get_message_payload_gcm_stream_message(self) -> None:
self._test_get_message_payload_gcm_stream_message()
def test_get_message_payload_gcm_stream_message_truncate_content(self) -> None:
self._test_get_message_payload_gcm_stream_message(truncate_content=True)
def test_get_message_payload_gcm_user_group_mention(self) -> None:
# Note that the @mobile_team user group doesn't actually
# exist; this test is just verifying the formatting logic.
@ -2323,40 +2330,6 @@ class TestGetGCMPayload(PushNotificationTest):
},
)
def test_get_message_payload_gcm_stream_notifications(self) -> None:
stream = Stream.objects.get(name="Denmark")
message = self.get_message(Recipient.STREAM, stream.id, stream.realm_id)
hamlet = self.example_user("hamlet")
payload, gcm_options = get_message_payload_gcm(hamlet, message)
self.assertDictEqual(
payload,
{
"user_id": hamlet.id,
"event": "message",
"zulip_message_id": message.id,
"time": datetime_to_timestamp(message.date_sent),
"content": message.content,
"content_truncated": False,
"server": settings.EXTERNAL_HOST,
"realm_id": hamlet.realm.id,
"realm_uri": hamlet.realm.uri,
"sender_id": hamlet.id,
"sender_email": hamlet.email,
"sender_full_name": "King Hamlet",
"sender_avatar_url": absolute_avatar_url(message.sender),
"recipient_type": "stream",
"topic": "Test topic",
"stream": "Denmark",
"stream_id": stream.id,
},
)
self.assertDictEqual(
gcm_options,
{
"priority": "high",
},
)
@override_settings(PUSH_NOTIFICATION_REDACT_CONTENT=True)
def test_get_message_payload_gcm_redacted_content(self) -> None:
stream = Stream.objects.get(name="Denmark")