test_push_notifications: Add test for unexpected APNs error.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-09-02 12:17:42 -07:00 committed by Alex Vandiver
parent 56a9d669f8
commit 4e2cba1ce1
1 changed files with 18 additions and 0 deletions

View File

@ -1452,6 +1452,24 @@ class TestAPNs(PushNotificationTest):
1, 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: def test_modernize_apns_payload(self) -> None:
payload = { payload = {
"alert": "Message from Hamlet", "alert": "Message from Hamlet",