mirror of https://github.com/zulip/zulip.git
push_notifs: Rename parse_gcm_options to parse_fcm_options.
This commit is contained in:
parent
497be370f5
commit
297141f8c4
|
@ -402,7 +402,7 @@ def send_android_push_notification_to_user(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def parse_gcm_options(options: Dict[str, Any], data: Dict[str, Any]) -> str:
|
def parse_fcm_options(options: Dict[str, Any], data: Dict[str, Any]) -> str:
|
||||||
"""
|
"""
|
||||||
Parse FCM options, supplying defaults, and raising an error if invalid.
|
Parse FCM options, supplying defaults, and raising an error if invalid.
|
||||||
|
|
||||||
|
@ -463,7 +463,7 @@ def send_android_push_notification(
|
||||||
data: The JSON object (decoded) to send as the 'data' parameter of
|
data: The JSON object (decoded) to send as the 'data' parameter of
|
||||||
the FCM message.
|
the FCM message.
|
||||||
options: Additional options to control the FCM message sent.
|
options: Additional options to control the FCM message sent.
|
||||||
For details, see `parse_gcm_options`.
|
For details, see `parse_fcm_options`.
|
||||||
"""
|
"""
|
||||||
if not devices:
|
if not devices:
|
||||||
return 0
|
return 0
|
||||||
|
@ -486,7 +486,7 @@ def send_android_push_notification(
|
||||||
"GCM: Sending notification for local user %s to %d devices", user_identity, len(devices)
|
"GCM: Sending notification for local user %s to %d devices", user_identity, len(devices)
|
||||||
)
|
)
|
||||||
reg_ids = [device.token for device in devices]
|
reg_ids = [device.token for device in devices]
|
||||||
priority = parse_gcm_options(options, data)
|
priority = parse_fcm_options(options, data)
|
||||||
try:
|
try:
|
||||||
# See https://firebase.google.com/docs/cloud-messaging/http-server-ref .
|
# See https://firebase.google.com/docs/cloud-messaging/http-server-ref .
|
||||||
# Two kwargs `retries` and `session` get eaten by `json_request`;
|
# Two kwargs `retries` and `session` get eaten by `json_request`;
|
||||||
|
|
|
@ -59,7 +59,7 @@ from zerver.lib.push_notifications import (
|
||||||
handle_remove_push_notification,
|
handle_remove_push_notification,
|
||||||
hex_to_b64,
|
hex_to_b64,
|
||||||
modernize_apns_payload,
|
modernize_apns_payload,
|
||||||
parse_gcm_options,
|
parse_fcm_options,
|
||||||
send_android_push_notification_to_user,
|
send_android_push_notification_to_user,
|
||||||
send_apple_push_notification,
|
send_apple_push_notification,
|
||||||
send_notifications_to_bouncer,
|
send_notifications_to_bouncer,
|
||||||
|
@ -4773,20 +4773,20 @@ class TestPushApi(BouncerTestCase):
|
||||||
class GCMParseOptionsTest(ZulipTestCase):
|
class GCMParseOptionsTest(ZulipTestCase):
|
||||||
def test_invalid_option(self) -> None:
|
def test_invalid_option(self) -> None:
|
||||||
with self.assertRaises(JsonableError):
|
with self.assertRaises(JsonableError):
|
||||||
parse_gcm_options({"invalid": True}, {})
|
parse_fcm_options({"invalid": True}, {})
|
||||||
|
|
||||||
def test_invalid_priority_value(self) -> None:
|
def test_invalid_priority_value(self) -> None:
|
||||||
with self.assertRaises(JsonableError):
|
with self.assertRaises(JsonableError):
|
||||||
parse_gcm_options({"priority": "invalid"}, {})
|
parse_fcm_options({"priority": "invalid"}, {})
|
||||||
|
|
||||||
def test_default_priority(self) -> None:
|
def test_default_priority(self) -> None:
|
||||||
self.assertEqual("high", parse_gcm_options({}, {"event": "message"}))
|
self.assertEqual("high", parse_fcm_options({}, {"event": "message"}))
|
||||||
self.assertEqual("normal", parse_gcm_options({}, {"event": "remove"}))
|
self.assertEqual("normal", parse_fcm_options({}, {"event": "remove"}))
|
||||||
self.assertEqual("normal", parse_gcm_options({}, {}))
|
self.assertEqual("normal", parse_fcm_options({}, {}))
|
||||||
|
|
||||||
def test_explicit_priority(self) -> None:
|
def test_explicit_priority(self) -> None:
|
||||||
self.assertEqual("normal", parse_gcm_options({"priority": "normal"}, {}))
|
self.assertEqual("normal", parse_fcm_options({"priority": "normal"}, {}))
|
||||||
self.assertEqual("high", parse_gcm_options({"priority": "high"}, {}))
|
self.assertEqual("high", parse_fcm_options({"priority": "high"}, {}))
|
||||||
|
|
||||||
|
|
||||||
@mock.patch("zerver.lib.push_notifications.gcm_client")
|
@mock.patch("zerver.lib.push_notifications.gcm_client")
|
||||||
|
|
Loading…
Reference in New Issue