mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 16:37:23 +00:00
push: Don't pass a UserProfile into _do_push_to_apns_service.
This commit is contained in:
@@ -137,10 +137,10 @@ def hex_to_b64(data):
|
|||||||
# type: (Text) -> bytes
|
# type: (Text) -> bytes
|
||||||
return base64.b64encode(binascii.unhexlify(data.encode('utf-8')))
|
return base64.b64encode(binascii.unhexlify(data.encode('utf-8')))
|
||||||
|
|
||||||
def _do_push_to_apns_service(user, message, apns_connection):
|
def _do_push_to_apns_service(user_id, message, apns_connection):
|
||||||
# type: (UserProfile, APNsMessage, APNs) -> None
|
# type: (int, APNsMessage, APNs) -> None
|
||||||
if not apns_connection:
|
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
|
return
|
||||||
|
|
||||||
frame = message.get_frame()
|
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 "
|
logging.info("APNS: Sending apple push notification "
|
||||||
"to devices: %s" % (valid_devices,))
|
"to devices: %s" % (valid_devices,))
|
||||||
zulip_message = APNsMessage(user.id, valid_tokens, alert=alert, **extra_data)
|
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:
|
else:
|
||||||
logging.warn("APNS: Not sending notification because "
|
logging.warn("APNS: Not sending notification because "
|
||||||
"tokens didn't match devices: %s" % (app_ids,))
|
"tokens didn't match devices: %s" % (app_ids,))
|
||||||
|
|||||||
@@ -173,9 +173,9 @@ class SendNotificationTest(PushNotificationTest):
|
|||||||
@mock.patch('zerver.lib.push_notifications._do_push_to_apns_service')
|
@mock.patch('zerver.lib.push_notifications._do_push_to_apns_service')
|
||||||
def test_send_apple_push_notifiction(self, mock_send, mock_info, mock_warn):
|
def test_send_apple_push_notifiction(self, mock_send, mock_info, mock_warn):
|
||||||
# type: (mock.MagicMock, mock.MagicMock, mock.MagicMock) -> None
|
# type: (mock.MagicMock, mock.MagicMock, mock.MagicMock) -> None
|
||||||
def test_send(user, message, alert):
|
def test_send(user_id, message, alert):
|
||||||
# type: (UserProfile, Message, str) -> None
|
# type: (int, Message, str) -> None
|
||||||
self.assertEqual(user.id, self.user_profile.id)
|
self.assertEqual(user_id, self.user_profile.id)
|
||||||
self.assertEqual(set(message.tokens), set(self.tokens))
|
self.assertEqual(set(message.tokens), set(self.tokens))
|
||||||
|
|
||||||
mock_send.side_effect = test_send
|
mock_send.side_effect = test_send
|
||||||
@@ -192,7 +192,7 @@ class SendNotificationTest(PushNotificationTest):
|
|||||||
self.assertIs(message, msg.get_frame())
|
self.assertIs(message, msg.get_frame())
|
||||||
|
|
||||||
mock_push.side_effect = test_push
|
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.warn')
|
||||||
@mock.patch('logging.info')
|
@mock.patch('logging.info')
|
||||||
|
|||||||
Reference in New Issue
Block a user