push: Don't pass a UserProfile into _do_push_to_apns_service.

This commit is contained in:
Tim Abbott
2017-03-05 18:24:50 -08:00
parent 53c9e3b4ca
commit 393c4d2eaa
2 changed files with 8 additions and 8 deletions

View File

@@ -137,10 +137,10 @@ def hex_to_b64(data):
# type: (Text) -> bytes
return base64.b64encode(binascii.unhexlify(data.encode('utf-8')))
def _do_push_to_apns_service(user, message, apns_connection):
# type: (UserProfile, APNsMessage, APNs) -> None
def _do_push_to_apns_service(user_id, message, apns_connection):
# type: (int, APNsMessage, APNs) -> None
if not apns_connection:
logging.info("Not delivering APNS message %s to user %s due to missing connection" % (message, user))
logging.info("Not delivering APNS message %s to user %s due to missing connection" % (message, user_id))
return
frame = message.get_frame()
@@ -176,7 +176,7 @@ def send_apple_push_notification(user, devices, alert, **extra_data):
logging.info("APNS: Sending apple push notification "
"to devices: %s" % (valid_devices,))
zulip_message = APNsMessage(user.id, valid_tokens, alert=alert, **extra_data)
_do_push_to_apns_service(user, zulip_message, conn)
_do_push_to_apns_service(user.id, zulip_message, conn)
else:
logging.warn("APNS: Not sending notification because "
"tokens didn't match devices: %s" % (app_ids,))

View File

@@ -173,9 +173,9 @@ class SendNotificationTest(PushNotificationTest):
@mock.patch('zerver.lib.push_notifications._do_push_to_apns_service')
def test_send_apple_push_notifiction(self, mock_send, mock_info, mock_warn):
# type: (mock.MagicMock, mock.MagicMock, mock.MagicMock) -> None
def test_send(user, message, alert):
# type: (UserProfile, Message, str) -> None
self.assertEqual(user.id, self.user_profile.id)
def test_send(user_id, message, alert):
# type: (int, Message, str) -> None
self.assertEqual(user_id, self.user_profile.id)
self.assertEqual(set(message.tokens), set(self.tokens))
mock_send.side_effect = test_send
@@ -192,7 +192,7 @@ class SendNotificationTest(PushNotificationTest):
self.assertIs(message, msg.get_frame())
mock_push.side_effect = test_push
apn._do_push_to_apns_service(self.user_profile, msg, apn.connection)
apn._do_push_to_apns_service(self.user_profile.id, msg, apn.connection)
@mock.patch('logging.warn')
@mock.patch('logging.info')