Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
push_notifs: Don't send request to bouncer if no devices found.
Mateusz Mandera2916a601b332
diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.pyindex a7aa9bdb48a..da5f69d237c 100644--- a/zerver/lib/push_notifications.py+++ b/zerver/lib/push_notifications.py@@ -589,6 +589,11 @@ def send_notifications_to_bouncer(android_devices: Sequence[DeviceToken],apple_devices: Sequence[DeviceToken],) -> Tuple[int, int]:+ if not android_devices and not apple_devices:+ # Avoid making a useless API request to the bouncer if there+ # are no mobile devices registered for this user.+ return 0, 0+post_data = {"user_uuid": str(user_profile.uuid),# user_uuid is the intended future format, but we also need to send user_iddiff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.pyindex c64ad215de7..d179c23e4a7 100644--- a/zerver/tests/test_push_notifications.py+++ b/zerver/tests/test_push_notifications.py@@ -3561,6 +3561,18 @@ class TestGetGCMPayload(PushNotificationTest):class TestSendNotificationsToBouncer(PushNotificationTest):+ def test_send_notifications_to_bouncer_when_no_devices(self) -> None:+ user = self.example_user("hamlet")++ with mock.patch("zerver.lib.remote_server.send_to_push_bouncer") as mock_send:+ total_android_devices, total_apple_devices = send_notifications_to_bouncer(+ user, {"apns": True}, {"gcm": True}, {}, android_devices=[], apple_devices=[]+ )++ self.assertEqual(total_android_devices, 0)+ self.assertEqual(total_apple_devices, 0)+ mock_send.assert_not_called()+@mock.patch("zerver.lib.remote_server.send_to_push_bouncer")def test_send_notifications_to_bouncer(self, mock_send: mock.MagicMock) -> None:user = self.example_user("hamlet")