mirror of https://github.com/zulip/zulip.git
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:
parent
5d8897b909
commit
9cff7e14c4
|
@ -2231,14 +2231,18 @@ class TestGetAPNsPayload(PushNotificationTest):
|
||||||
class TestGetGCMPayload(PushNotificationTest):
|
class TestGetGCMPayload(PushNotificationTest):
|
||||||
def _test_get_message_payload_gcm_stream_message(
|
def _test_get_message_payload_gcm_stream_message(
|
||||||
self,
|
self,
|
||||||
|
truncate_content: bool = False,
|
||||||
mentioned_user_group_id: Optional[int] = None,
|
mentioned_user_group_id: Optional[int] = None,
|
||||||
mentioned_user_group_name: Optional[str] = None,
|
mentioned_user_group_name: Optional[str] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
stream = Stream.objects.filter(name="Verona").get()
|
stream = Stream.objects.filter(name="Verona").get()
|
||||||
message = self.get_message(Recipient.STREAM, stream.id, stream.realm_id)
|
message = self.get_message(Recipient.STREAM, stream.id, stream.realm_id)
|
||||||
message.content = "a" * 210
|
content = message.content
|
||||||
message.rendered_content = "a" * 210
|
if truncate_content:
|
||||||
message.save()
|
message.content = "a" * 210
|
||||||
|
message.rendered_content = "a" * 210
|
||||||
|
message.save()
|
||||||
|
content = "a" * 200 + "…"
|
||||||
|
|
||||||
hamlet = self.example_user("hamlet")
|
hamlet = self.example_user("hamlet")
|
||||||
payload, gcm_options = get_message_payload_gcm(
|
payload, gcm_options = get_message_payload_gcm(
|
||||||
|
@ -2249,8 +2253,8 @@ class TestGetGCMPayload(PushNotificationTest):
|
||||||
"event": "message",
|
"event": "message",
|
||||||
"zulip_message_id": message.id,
|
"zulip_message_id": message.id,
|
||||||
"time": datetime_to_timestamp(message.date_sent),
|
"time": datetime_to_timestamp(message.date_sent),
|
||||||
"content": "a" * 200 + "…",
|
"content": content,
|
||||||
"content_truncated": True,
|
"content_truncated": truncate_content,
|
||||||
"server": settings.EXTERNAL_HOST,
|
"server": settings.EXTERNAL_HOST,
|
||||||
"realm_id": hamlet.realm.id,
|
"realm_id": hamlet.realm.id,
|
||||||
"realm_uri": hamlet.realm.uri,
|
"realm_uri": hamlet.realm.uri,
|
||||||
|
@ -2281,6 +2285,9 @@ class TestGetGCMPayload(PushNotificationTest):
|
||||||
def test_get_message_payload_gcm_stream_message(self) -> None:
|
def test_get_message_payload_gcm_stream_message(self) -> None:
|
||||||
self._test_get_message_payload_gcm_stream_message()
|
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:
|
def test_get_message_payload_gcm_user_group_mention(self) -> None:
|
||||||
# Note that the @mobile_team user group doesn't actually
|
# Note that the @mobile_team user group doesn't actually
|
||||||
# exist; this test is just verifying the formatting logic.
|
# 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)
|
@override_settings(PUSH_NOTIFICATION_REDACT_CONTENT=True)
|
||||||
def test_get_message_payload_gcm_redacted_content(self) -> None:
|
def test_get_message_payload_gcm_redacted_content(self) -> None:
|
||||||
stream = Stream.objects.get(name="Denmark")
|
stream = Stream.objects.get(name="Denmark")
|
||||||
|
|
Loading…
Reference in New Issue