push_notifications: Upgrade aioapns.

This commit is contained in:
Alex Vandiver 2023-08-28 22:43:51 +00:00 committed by Tim Abbott
parent 168e1d5f85
commit 733c6da298
4 changed files with 24 additions and 28 deletions

View File

@ -7,9 +7,9 @@
#
# For details, see requirements/README.md .
#
aioapns==2.2 \
--hash=sha256:36f55048008e07c14de16d30980df5cf14fcbddc6e80b454813e8d65e1a9f39b \
--hash=sha256:dc530d221219aecb4f2937c756637e2b6f144761b6e876794bf26d5e66859357
aioapns==3.0 \
--hash=sha256:32216377d1d8693ba08cfeba3b6e13824f766c2f751901e082fcb5b1d408bbed \
--hash=sha256:67f0bbdb784f62a8ee615751ab8069613a80f7b5e280535ffd3d1c7739be3259
# via -r requirements/common.in
aiohttp==3.8.5 \
--hash=sha256:00ad4b6f185ec67f3e6562e8a1d2b69660be43070bd0ef6fcec5211154c7df67 \

View File

@ -7,9 +7,9 @@
#
# For details, see requirements/README.md .
#
aioapns==2.2 \
--hash=sha256:36f55048008e07c14de16d30980df5cf14fcbddc6e80b454813e8d65e1a9f39b \
--hash=sha256:dc530d221219aecb4f2937c756637e2b6f144761b6e876794bf26d5e66859357
aioapns==3.0 \
--hash=sha256:32216377d1d8693ba08cfeba3b6e13824f766c2f751901e082fcb5b1d408bbed \
--hash=sha256:67f0bbdb784f62a8ee615751ab8069613a80f7b5e280535ffd3d1c7739be3259
# via -r requirements/common.in
aiohttp==3.8.5 \
--hash=sha256:00ad4b6f185ec67f3e6562e8a1d2b69660be43070bd0ef6fcec5211154c7df67 \

View File

@ -48,4 +48,4 @@ API_FEATURE_LEVEL = 206
# historical commits sharing the same major version, in which case a
# minor version bump suffices.
PROVISION_VERSION = (247, 6)
PROVISION_VERSION = (247, 7)

View File

@ -996,12 +996,14 @@ class PushNotificationTest(BouncerTestCase):
return message
@contextmanager
def mock_apns(self) -> Iterator[APNsContext]:
apns_context = APNsContext(apns=mock.Mock(), loop=asyncio.new_event_loop())
def mock_apns(self) -> Iterator[Tuple[APNsContext, mock.AsyncMock]]:
apns = mock.Mock(spec=aioapns.APNs)
apns.send_notification = mock.AsyncMock()
apns_context = APNsContext(apns=apns, loop=asyncio.new_event_loop())
try:
with mock.patch("zerver.lib.push_notifications.get_apns_context") as mock_get:
mock_get.return_value = apns_context
yield apns_context
yield apns_context, apns.send_notification
finally:
apns_context.loop.close()
@ -1096,7 +1098,7 @@ class HandlePushNotificationTest(PushNotificationTest):
}
with mock.patch(
"zerver.lib.push_notifications.gcm_client"
) as mock_gcm, self.mock_apns() as apns_context, self.assertLogs(
) as mock_gcm, self.mock_apns() as (apns_context, send_notification), self.assertLogs(
"zerver.lib.push_notifications", level="INFO"
) as pn_logger, self.assertLogs(
"zilencer.views", level="INFO"
@ -1112,8 +1114,7 @@ class HandlePushNotificationTest(PushNotificationTest):
mock_gcm.json_request.return_value = {
"success": {device[2]: message.id for device in gcm_devices}
}
apns_context.apns.send_notification = mock.AsyncMock()
apns_context.apns.send_notification.return_value.is_successful = True
send_notification.return_value.is_successful = True
handle_push_notification(self.user_profile.id, missed_message)
self.assertEqual(
views_logger.output,
@ -1158,7 +1159,7 @@ class HandlePushNotificationTest(PushNotificationTest):
}
with mock.patch(
"zerver.lib.push_notifications.gcm_client"
) as mock_gcm, self.mock_apns() as apns_context, self.assertLogs(
) as mock_gcm, self.mock_apns() as (apns_context, send_notification), self.assertLogs(
"zerver.lib.push_notifications", level="INFO"
) as pn_logger, self.assertLogs(
"zilencer.views", level="INFO"
@ -1172,9 +1173,8 @@ class HandlePushNotificationTest(PushNotificationTest):
for device in RemotePushDeviceToken.objects.filter(kind=PushDeviceToken.GCM)
]
mock_gcm.json_request.return_value = {"success": {gcm_devices[0][2]: message.id}}
apns_context.apns.send_notification = mock.AsyncMock()
apns_context.apns.send_notification.return_value.is_successful = False
apns_context.apns.send_notification.return_value.description = "Unregistered"
send_notification.return_value.is_successful = False
send_notification.return_value.description = "Unregistered"
handle_push_notification(self.user_profile.id, missed_message)
self.assertEqual(
views_logger.output,
@ -1852,11 +1852,10 @@ class TestAPNs(PushNotificationTest):
def test_success(self) -> None:
self.setup_apns_tokens()
with self.mock_apns() as apns_context, self.assertLogs(
with self.mock_apns() as (apns_context, send_notification), self.assertLogs(
"zerver.lib.push_notifications", level="INFO"
) as logger:
apns_context.apns.send_notification = mock.AsyncMock()
apns_context.apns.send_notification.return_value.is_successful = True
send_notification.return_value.is_successful = True
self.send()
for device in self.devices():
self.assertIn(
@ -1866,12 +1865,10 @@ class TestAPNs(PushNotificationTest):
def test_http_retry_eventually_fails(self) -> None:
self.setup_apns_tokens()
with self.mock_apns() as apns_context, self.assertLogs(
with self.mock_apns() as (apns_context, send_notification), self.assertLogs(
"zerver.lib.push_notifications", level="INFO"
) as logger:
apns_context.apns.send_notification = mock.AsyncMock(
side_effect=aioapns.exceptions.ConnectionError()
)
send_notification.side_effect = aioapns.exceptions.ConnectionError()
self.send(devices=self.devices()[0:1])
self.assertIn(
f"ERROR:zerver.lib.push_notifications:APNs: ConnectionError sending for user <id:{self.user_profile.id}> to device {self.devices()[0].token}; check certificate expiration",
@ -1880,12 +1877,11 @@ class TestAPNs(PushNotificationTest):
def test_internal_server_error(self) -> None:
self.setup_apns_tokens()
with self.mock_apns() as apns_context, self.assertLogs(
with self.mock_apns() as (apns_context, send_notification), self.assertLogs(
"zerver.lib.push_notifications", level="INFO"
) as logger:
apns_context.apns.send_notification = mock.AsyncMock()
apns_context.apns.send_notification.return_value.is_successful = False
apns_context.apns.send_notification.return_value.description = "InternalServerError"
send_notification.return_value.is_successful = False
send_notification.return_value.description = "InternalServerError"
self.send(devices=self.devices()[0:1])
self.assertIn(
f"WARNING:zerver.lib.push_notifications:APNs: Failed to send for user <id:{self.user_profile.id}> to device {self.devices()[0].token}: InternalServerError",