From 4e2cba1ce1951210fd7914404e682c628dd2aae2 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 2 Sep 2021 12:17:42 -0700 Subject: [PATCH] test_push_notifications: Add test for unexpected APNs error. Signed-off-by: Anders Kaseorg --- zerver/tests/test_push_notifications.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py index 6b9e71896f..a82cadd042 100644 --- a/zerver/tests/test_push_notifications.py +++ b/zerver/tests/test_push_notifications.py @@ -1452,6 +1452,24 @@ class TestAPNs(PushNotificationTest): 1, ) + def test_internal_server_error(self) -> None: + self.setup_apns_tokens() + with self.mock_apns() as apns_context, self.assertLogs( + "zerver.lib.push_notifications", level="INFO" + ) as logger: + result = mock.Mock() + result.is_successful = False + result.description = "InternalServerError" + apns_context.apns.send_notification.return_value = asyncio.Future( + loop=apns_context.loop + ) + apns_context.apns.send_notification.return_value.set_result(result) + self.send(devices=self.devices()[0:1]) + self.assertIn( + f"WARNING:zerver.lib.push_notifications:APNs: Failed to send for user {self.user_profile.id} to device {self.devices()[0].token}: InternalServerError", + logger.output, + ) + def test_modernize_apns_payload(self) -> None: payload = { "alert": "Message from Hamlet",