def test_get_gcm_payload(self):
        # type: () -> None
        stream = Stream.objects.filter(name='Verona').get()
        message = self.get_message(Recipient.STREAM, stream.id)
        message.content = 'a' * 210
        message.rendered_content = 'a' * 210
        message.save()
        message.trigger = 'mentioned'

        user_profile = self.example_user('hamlet')
        payload = apn.get_gcm_payload(user_profile, message)
        expected = {
            "user": user_profile.email,
            "event": "message",
            "alert": "New mention from King Hamlet",
            "zulip_message_id": message.id,
            "time": apn.datetime_to_timestamp(message.pub_date),
            "content": 'a' * 200 + '…',
            "content_truncated": True,
            "sender_email": self.example_email("hamlet"),
            "sender_full_name": "King Hamlet",
            "sender_avatar_url": apn.absolute_avatar_url(message.sender),
            "recipient_type": "stream",
            "stream": apn.get_display_recipient(message.recipient),
            "topic": message.subject,
        }
        self.assertDictEqual(payload, expected)
 def test_get_gcm_payload_stream_notifications(self):
     # type: () -> None
     message = self.get_message(Recipient.STREAM, 1)
     message.triggers = {
         'private_message': False,
         'mentioned': False,
         'stream_push_notify': True,
     }
     message.stream_name = 'Denmark'
     user_profile = self.example_user('hamlet')
     payload = apn.get_gcm_payload(user_profile, message)
     expected = {
         "user": user_profile.email,
         "event": "message",
         "alert": "New stream message from King Hamlet in Denmark",
         "zulip_message_id": message.id,
         "time": apn.datetime_to_timestamp(message.pub_date),
         "content": message.content,
         "content_truncated": False,
         "sender_email": self.example_email("hamlet"),
         "sender_full_name": "King Hamlet",
         "sender_avatar_url": apn.absolute_avatar_url(message.sender),
         "recipient_type": "stream",
         "topic": "Test Message",
         "stream": "Denmark"
     }
     self.assertDictEqual(payload, expected)
 def test_get_gcm_payload_personal(self):
     # type: () -> None
     message = self.get_message(Recipient.PERSONAL, 1)
     message.trigger = 'private_message'
     user_profile = self.example_user('hamlet')
     payload = apn.get_gcm_payload(user_profile, message)
     expected = {
         "user": user_profile.email,
         "event": "message",
         "alert": "New private message from King Hamlet",
         "zulip_message_id": message.id,
         "time": apn.datetime_to_timestamp(message.pub_date),
         "content": message.content,
         "content_truncated": False,
         "sender_email": self.example_email("hamlet"),
         "sender_full_name": "King Hamlet",
         "sender_avatar_url": apn.absolute_avatar_url(message.sender),
         "recipient_type": "private",
     }
     self.assertDictEqual(payload, expected)
 def test_get_gcm_payload_redacted_content(self):
     # type: () -> None
     message = self.get_message(Recipient.STREAM, 1)
     message.trigger = 'stream_push_notify'
     message.stream_name = 'Denmark'
     user_profile = self.example_user('hamlet')
     payload = apn.get_gcm_payload(user_profile, message)
     expected = {
         "user": user_profile.email,
         "event": "message",
         "alert": "New stream message from King Hamlet in Denmark",
         "zulip_message_id": message.id,
         "time": apn.datetime_to_timestamp(message.pub_date),
         "content": "***REDACTED***",
         "content_truncated": False,
         "sender_email": self.example_email("hamlet"),
         "sender_full_name": "King Hamlet",
         "sender_avatar_url": apn.absolute_avatar_url(message.sender),
         "recipient_type": "stream",
         "topic": "Test Message",
         "stream": "Denmark"
     }
     self.assertDictEqual(payload, expected)