push notifications: Remove tests for get_alert_from_message.

The string that is returned from get_alert_from_message is
dependent upon the same message that is passed into get_apns_payload
and get_gcm_payload. The contents of those payloads that are tested via
TestGetAPNsPayload and TestGetGCMPayload, which makes the tests for
get_alert_from_message redundant.

Also, simplify the logic by removing the last elif conditional.
This commit is contained in:
Jack Zhang
2018-10-04 20:08:54 -07:00
committed by Tim Abbott
parent e2ee455314
commit 92a100798c
2 changed files with 2 additions and 40 deletions

View File

@@ -440,11 +440,8 @@ def get_alert_from_message(message: Message) -> str:
return "New private message from %s" % (sender_str,)
elif message.is_stream_message() and message.trigger == 'mentioned':
return "New mention from %s" % (sender_str,)
elif (message.is_stream_message() and
(message.trigger == 'stream_push_notify' and message.stream_name)):
else: # message.is_stream_message() and message.trigger == 'stream_push_notify'
return "New stream message from %s in %s" % (sender_str, message.stream_name,)
else:
return "New Zulip mentions and private messages from %s" % (sender_str,)
def get_mobile_push_content(rendered_content: str) -> str:
def get_text(elem: LH.HtmlElement) -> str:

View File

@@ -731,42 +731,7 @@ class TestAPNs(PushNotificationTest):
self.assertEqual(
apn.modernize_apns_payload(payload),
payload)
class TestGetAlertFromMessage(PushNotificationTest):
def test_get_alert_from_private_group_message(self) -> None:
message = self.get_message(Recipient.HUDDLE)
message.trigger = 'private_message'
alert = apn.get_alert_from_message(message)
self.assertEqual(alert, "New private group message from King Hamlet")
def test_get_alert_from_private_message(self) -> None:
message = self.get_message(Recipient.PERSONAL)
message.trigger = 'private_message'
alert = apn.get_alert_from_message(message)
self.assertEqual(alert, "New private message from King Hamlet")
def test_get_alert_from_mention(self) -> None:
message = self.get_message(Recipient.STREAM)
message.trigger = 'mentioned'
alert = apn.get_alert_from_message(message)
self.assertEqual(alert, "New mention from King Hamlet")
def test_get_alert_from_stream_message(self) -> None:
message = self.get_message(Recipient.STREAM)
message.trigger = 'stream_push_notify'
message.stream_name = 'Denmark'
alert = apn.get_alert_from_message(message)
self.assertEqual(alert, "New stream message from King Hamlet in Denmark")
def test_get_alert_from_other_message(self) -> None:
message = self.get_message(0)
message.trigger = 'stream_push_notify'
alert = apn.get_alert_from_message(message)
alert = apn.get_alert_from_message(self.get_message(0))
self.assertEqual(alert,
"New Zulip mentions and private messages from King "
"Hamlet")
class TestGetAPNsPayload(PushNotificationTest):
def test_get_apns_payload(self) -> None:
user_profile = self.example_user("othello")