Skip to content

Commit 0f79181

Browse files
authored
Changed firebase-admin's deprecated send_all method for send_each (#715)
1 parent 44977b1 commit 0f79181

File tree

7 files changed

+27
-27
lines changed

7 files changed

+27
-27
lines changed

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Dependencies
3737
- For WebPush (WP), pywebpush 1.3.0+ is required (optional). py-vapid 1.3.0+ is required for generating the WebPush private key; however this
3838
step does not need to occur on the application server.
3939
- For Apple Push (APNS), apns2 0.3+ is required (optional).
40-
- For FCM, firebase-admin 5+ is required (optional).
40+
- For FCM, firebase-admin 6.2+ is required (optional).
4141

4242
Setup
4343
-----

push_notifications/gcm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def send_message(
182182
messages = [
183183
_prepare_message(message, token) for token in chunk
184184
]
185-
responses = messaging.send_all(messages, dry_run=dry_run, app=app).responses
185+
responses = messaging.send_each(messages, dry_run=dry_run, app=app).responses
186186
ret.extend(responses)
187187
_deactivate_devices_with_error_results(registration_ids, ret)
188188
return messaging.BatchResponse(ret)

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ APNS =
4141

4242
WP = pywebpush>=1.3.0
4343

44-
FCM = firebase-admin>=5,<6
44+
FCM = firebase-admin>=6.2
4545

4646

4747
[options.packages.find]

tests/test_admin.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_send_bulk_messages_action(self):
2424
admin.message_user = mock.Mock()
2525

2626
with mock.patch(
27-
"firebase_admin.messaging.send_all", return_value=responses.FCM_SUCCESS
27+
"firebase_admin.messaging.send_each", return_value=responses.FCM_SUCCESS
2828
) as p:
2929
admin.send_messages(request, queryset, bulk=True)
3030

@@ -61,7 +61,7 @@ def test_send_single_message_action(self):
6161
admin.message_user = mock.Mock()
6262

6363
with mock.patch(
64-
"firebase_admin.messaging.send_all", return_value=responses.FCM_SUCCESS
64+
"firebase_admin.messaging.send_each", return_value=responses.FCM_SUCCESS
6565
) as p:
6666
admin.send_messages(request, queryset, bulk=False)
6767

@@ -102,7 +102,7 @@ def test_send_bulk_messages_action_fail(self):
102102
)
103103

104104
with mock.patch(
105-
"firebase_admin.messaging.send_all", return_value=response
105+
"firebase_admin.messaging.send_each", return_value=response
106106
) as p:
107107
admin.send_messages(request, queryset, bulk=True)
108108

tests/test_gcm_push_payload.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class GCMPushPayloadTest(TestCase):
1313

1414
def test_fcm_push_payload(self):
15-
with mock.patch("firebase_admin.messaging.send_all", return_value=FCM_SUCCESS) as p:
15+
with mock.patch("firebase_admin.messaging.send_each", return_value=FCM_SUCCESS) as p:
1616
message = dict_to_fcm_message({"message": "Hello world"})
1717

1818
send_message("abc", message)
@@ -37,7 +37,7 @@ def test_fcm_push_payload(self):
3737
self.assertEqual(message.android.notification.body, "Hello world")
3838

3939
def test_fcm_push_payload_many(self):
40-
with mock.patch("firebase_admin.messaging.send_all", return_value=FCM_SUCCESS) as p:
40+
with mock.patch("firebase_admin.messaging.send_each", return_value=FCM_SUCCESS) as p:
4141
message = dict_to_fcm_message({"message": "Hello world"})
4242

4343
send_message(["abc", "123"], message)

tests/test_models.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_can_create_save_device(self):
3838
def test_fcm_send_message(self):
3939
device = GCMDevice.objects.create(registration_id="abc", cloud_message_type="FCM")
4040
with mock.patch(
41-
"firebase_admin.messaging.send_all", return_value=responses.FCM_SUCCESS
41+
"firebase_admin.messaging.send_each", return_value=responses.FCM_SUCCESS
4242
) as p:
4343
device.send_message("Hello world")
4444

@@ -65,7 +65,7 @@ def test_fcm_send_message(self):
6565
def test_fcm_send_message_with_fcm_message(self):
6666
device = GCMDevice.objects.create(registration_id="abc", cloud_message_type="FCM")
6767
with mock.patch(
68-
"firebase_admin.messaging.send_all", return_value=responses.FCM_SUCCESS
68+
"firebase_admin.messaging.send_each", return_value=responses.FCM_SUCCESS
6969
) as p:
7070
message_to_send = messaging.Message(
7171
notification=messaging.Notification(
@@ -99,7 +99,7 @@ def test_fcm_send_message_with_fcm_message(self):
9999
def test_fcm_send_message_extra_data(self):
100100
device = GCMDevice.objects.create(registration_id="abc", cloud_message_type="FCM")
101101
with mock.patch(
102-
"firebase_admin.messaging.send_all", return_value=responses.FCM_SUCCESS
102+
"firebase_admin.messaging.send_each", return_value=responses.FCM_SUCCESS
103103
) as p:
104104
device.send_message("Hello world", extra={"foo": "bar"})
105105

@@ -125,7 +125,7 @@ def test_fcm_send_message_extra_data(self):
125125
def test_fcm_send_message_extra_options(self):
126126
device = GCMDevice.objects.create(registration_id="abc", cloud_message_type="FCM")
127127
with mock.patch(
128-
"firebase_admin.messaging.send_all", return_value=responses.FCM_SUCCESS
128+
"firebase_admin.messaging.send_each", return_value=responses.FCM_SUCCESS
129129
) as p:
130130
device.send_message("Hello world", collapse_key="test_key", foo="bar")
131131

@@ -152,7 +152,7 @@ def test_fcm_send_message_extra_options(self):
152152
def test_fcm_send_message_extra_notification(self):
153153
device = GCMDevice.objects.create(registration_id="abc", cloud_message_type="FCM")
154154
with mock.patch(
155-
"firebase_admin.messaging.send_all", return_value=responses.FCM_SUCCESS
155+
"firebase_admin.messaging.send_each", return_value=responses.FCM_SUCCESS
156156
) as p:
157157
device.send_message("Hello world", extra={"icon": "test_icon"}, title="test")
158158

@@ -180,7 +180,7 @@ def test_fcm_send_message_extra_notification(self):
180180
def test_fcm_send_message_extra_options_and_notification_and_data(self):
181181
device = GCMDevice.objects.create(registration_id="abc", cloud_message_type="FCM")
182182
with mock.patch(
183-
"firebase_admin.messaging.send_all", return_value=responses.FCM_SUCCESS
183+
"firebase_admin.messaging.send_each", return_value=responses.FCM_SUCCESS
184184
) as p:
185185
device.send_message(
186186
"Hello world",
@@ -215,7 +215,7 @@ def test_fcm_send_message_to_multiple_devices(self):
215215
self._create_fcm_devices(["abc", "abc1"])
216216

217217
with mock.patch(
218-
"firebase_admin.messaging.send_all", return_value=responses.FCM_SUCCESS_MULTIPLE
218+
"firebase_admin.messaging.send_each", return_value=responses.FCM_SUCCESS_MULTIPLE
219219
) as p:
220220
GCMDevice.objects.all().send_message("Hello world")
221221

@@ -245,7 +245,7 @@ def test_fcm_send_message_to_multiple_devices_fcm_message(self):
245245
self._create_fcm_devices(["abc", "abc1"])
246246

247247
with mock.patch(
248-
"firebase_admin.messaging.send_all", return_value=responses.FCM_SUCCESS_MULTIPLE
248+
"firebase_admin.messaging.send_each", return_value=responses.FCM_SUCCESS_MULTIPLE
249249
) as p:
250250
message_to_send = messaging.Message(
251251
notification=messaging.Notification(
@@ -283,7 +283,7 @@ def test_gcm_send_message_does_not_send(self):
283283
device = GCMDevice.objects.create(registration_id="abc", cloud_message_type="GCM")
284284

285285
with mock.patch(
286-
"firebase_admin.messaging.send_all", return_value=responses.FCM_SUCCESS_MULTIPLE
286+
"firebase_admin.messaging.send_each", return_value=responses.FCM_SUCCESS_MULTIPLE
287287
) as p:
288288
message_to_send = messaging.Message(
289289
notification=messaging.Notification(
@@ -299,7 +299,7 @@ def test_gcm_send_multiple_message_does_not_send(self):
299299
self._create_devices(["abc", "abc1"])
300300

301301
with mock.patch(
302-
"firebase_admin.messaging.send_all", return_value=responses.FCM_SUCCESS_MULTIPLE
302+
"firebase_admin.messaging.send_each", return_value=responses.FCM_SUCCESS_MULTIPLE
303303
) as p:
304304
message_to_send = messaging.Message(
305305
notification=messaging.Notification(
@@ -318,7 +318,7 @@ def test_fcm_send_message_active_devices(self):
318318
GCMDevice.objects.create(registration_id="xyz", active=False, cloud_message_type="FCM")
319319

320320
with mock.patch(
321-
"firebase_admin.messaging.send_all", return_value=responses.FCM_SUCCESS_MULTIPLE
321+
"firebase_admin.messaging.send_each", return_value=responses.FCM_SUCCESS_MULTIPLE
322322
) as p:
323323
GCMDevice.objects.all().send_message("Hello world")
324324

@@ -344,7 +344,7 @@ def test_fcm_send_message_collapse_to_multiple_devices(self):
344344
self._create_fcm_devices(["abc", "abc1"])
345345

346346
with mock.patch(
347-
"firebase_admin.messaging.send_all", return_value=responses.FCM_SUCCESS_MULTIPLE
347+
"firebase_admin.messaging.send_each", return_value=responses.FCM_SUCCESS_MULTIPLE
348348
) as p:
349349
GCMDevice.objects.all().send_message("Hello world", collapse_key="test_key")
350350

@@ -386,7 +386,7 @@ def test_fcm_send_message_to_single_device_with_error(self):
386386
[SendResponse(resp={"name": "..."}, exception=error)]
387387
)
388388
with mock.patch(
389-
"firebase_admin.messaging.send_all", return_value=return_value
389+
"firebase_admin.messaging.send_each", return_value=return_value
390390
):
391391
device = GCMDevice.objects.get(registration_id=devices[index])
392392
device.send_message("Hello World!")
@@ -399,7 +399,7 @@ def test_fcm_send_message_to_single_device_with_error_mismatch(self):
399399
[SendResponse(resp={"name": "..."}, exception=OSError())]
400400
)
401401
with mock.patch(
402-
"firebase_admin.messaging.send_all",
402+
"firebase_admin.messaging.send_each",
403403
return_value=return_value
404404
):
405405
# these errors are not device specific, device is not deactivated
@@ -417,7 +417,7 @@ def test_fcm_send_message_to_multiple_devices_with_error(self):
417417
SendResponse(resp={"name": "..."}, exception=InvalidArgumentError("Invalid registration")),
418418
])
419419
with mock.patch(
420-
"firebase_admin.messaging.send_all", return_value=return_value
420+
"firebase_admin.messaging.send_each", return_value=return_value
421421
):
422422
GCMDevice.objects.all().send_message("Hello World")
423423
self.assertFalse(GCMDevice.objects.get(registration_id="abc").active)
@@ -436,7 +436,7 @@ def test_fcm_send_message_to_multiple_devices_with_error_b(self):
436436
])
437437

438438
with mock.patch(
439-
"firebase_admin.messaging.send_all", return_value=return_value
439+
"firebase_admin.messaging.send_each", return_value=return_value
440440
):
441441
GCMDevice.objects.all().send_message("Hello World")
442442
self.assertTrue(GCMDevice.objects.get(registration_id="abc").active)
@@ -448,14 +448,14 @@ def test_fcm_send_message_with_no_reg_ids(self):
448448
self._create_fcm_devices(["abc", "abc1"])
449449

450450
with mock.patch(
451-
"firebase_admin.messaging.send_all",
451+
"firebase_admin.messaging.send_each",
452452
return_value=responses.FCM_SUCCESS_MULTIPLE
453453
) as p:
454454
GCMDevice.objects.filter(registration_id="xyz").send_message("Hello World")
455455
p.assert_not_called()
456456

457457
with mock.patch(
458-
"firebase_admin.messaging.send_all",
458+
"firebase_admin.messaging.send_each",
459459
return_value=responses.FCM_SUCCESS_MULTIPLE
460460
) as p:
461461
reg_ids = [obj.registration_id for obj in GCMDevice.objects.all()]

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ deps =
3535
pytest-django
3636
pywebpush
3737
djangorestframework
38-
firebase-admin>=5,<6
38+
firebase-admin>=6.2
3939
dj22: Django>=2.2,<3.0
4040
dj32: Django>=3.2,<3.3
4141
dj40: Django>=4.0,<4.0.5

0 commit comments

Comments
 (0)