push_notifications: Catch IOError while pushing to GCM.

This commit is contained in:
Umair Khan
2017-05-17 12:58:27 +05:00
committed by Tim Abbott
parent e12d3100db
commit 38ecc35cd9
2 changed files with 14 additions and 1 deletions

View File

@@ -242,7 +242,11 @@ def send_android_push_notification(devices, data, remote=False):
else:
DeviceTokenClass = PushDeviceToken
res = gcm.json_request(registration_ids=reg_ids, data=data)
try:
res = gcm.json_request(registration_ids=reg_ids, data=data)
except IOError as e:
logging.warning(str(e))
return
if res and 'success' in res:
for reg_id, msg_id in res['success'].items():

View File

@@ -790,6 +790,15 @@ class GCMNotSetTest(GCMTest):
"notification, but no API key was "
"configured")
class GCMIOErrorTest(GCMTest):
@mock.patch('zerver.lib.push_notifications.gcm.json_request')
@mock.patch('logging.warning')
def test_json_request_raises_ioerror(self, mock_warn, mock_json_request):
# type: (mock.MagicMock, mock.MagicMock) -> None
mock_json_request.side_effect = IOError('error')
apn.send_android_push_notification_to_user(self.user_profile, {})
mock_warn.assert_called_with('error')
class GCMSuccessTest(GCMTest):
@mock.patch('logging.warning')
@mock.patch('logging.info')