Skip to content

Commit 076591f

Browse files
authored
fix(fcm): Passing params as keyword arguments to googleapiclient (#414)
* fix(fcm): Passing batch URI as a keyword arg to googleapiclient * Adding test case
1 parent e35a45a commit 076591f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

firebase_admin/messaging.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ def batch_callback(_, response, error):
372372
send_response = SendResponse(response, exception)
373373
responses.append(send_response)
374374

375-
batch = http.BatchHttpRequest(batch_callback, _MessagingService.FCM_BATCH_URL)
375+
batch = http.BatchHttpRequest(
376+
callback=batch_callback, batch_uri=_MessagingService.FCM_BATCH_URL)
376377
for message in messages:
377378
body = json.dumps(self._message_data(message, dry_run))
378379
req = http.HttpRequest(

tests/test_messaging.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
import json
1818
import numbers
1919

20-
from googleapiclient.http import HttpMockSequence
20+
from googleapiclient import http
21+
from googleapiclient import _helpers
2122
import pytest
2223

2324
import firebase_admin
@@ -1810,7 +1811,7 @@ def _instrument_batch_messaging_service(self, app=None, status=200, payload=''):
18101811
content_type = 'multipart/mixed; boundary=boundary'
18111812
else:
18121813
content_type = 'application/json'
1813-
fcm_service._transport = HttpMockSequence([
1814+
fcm_service._transport = http.HttpMockSequence([
18141815
({'status': str(status), 'content-type': content_type}, payload),
18151816
])
18161817
return fcm_service
@@ -1867,6 +1868,20 @@ def test_send_all(self):
18671868
assert all([r.success for r in batch_response.responses])
18681869
assert not any([r.exception for r in batch_response.responses])
18691870

1871+
def test_send_all_with_positional_param_enforcement(self):
1872+
payload = json.dumps({'name': 'message-id'})
1873+
_ = self._instrument_batch_messaging_service(
1874+
payload=self._batch_payload([(200, payload), (200, payload)]))
1875+
msg = messaging.Message(topic='foo')
1876+
1877+
enforcement = _helpers.positional_parameters_enforcement
1878+
_helpers.positional_parameters_enforcement = _helpers.POSITIONAL_EXCEPTION
1879+
try:
1880+
batch_response = messaging.send_all([msg, msg], dry_run=True)
1881+
assert batch_response.success_count == 2
1882+
finally:
1883+
_helpers.positional_parameters_enforcement = enforcement
1884+
18701885
@pytest.mark.parametrize('status', HTTP_ERROR_CODES)
18711886
def test_send_all_detailed_error(self, status):
18721887
success_payload = json.dumps({'name': 'message-id'})

0 commit comments

Comments
 (0)