Skip to content

fix(fcm): Passing params as keyword arguments to googleapiclient #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion firebase_admin/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ def batch_callback(_, response, error):
send_response = SendResponse(response, exception)
responses.append(send_response)

batch = http.BatchHttpRequest(batch_callback, _MessagingService.FCM_BATCH_URL)
batch = http.BatchHttpRequest(
callback=batch_callback, batch_uri=_MessagingService.FCM_BATCH_URL)
for message in messages:
body = json.dumps(self._message_data(message, dry_run))
req = http.HttpRequest(
Expand Down
19 changes: 17 additions & 2 deletions tests/test_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import json
import numbers

from googleapiclient.http import HttpMockSequence
from googleapiclient import http
from googleapiclient import _helpers
import pytest

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

def test_send_all_with_positional_param_enforcement(self):
payload = json.dumps({'name': 'message-id'})
_ = self._instrument_batch_messaging_service(
payload=self._batch_payload([(200, payload), (200, payload)]))
msg = messaging.Message(topic='foo')

enforcement = _helpers.positional_parameters_enforcement
_helpers.positional_parameters_enforcement = _helpers.POSITIONAL_EXCEPTION
try:
batch_response = messaging.send_all([msg, msg], dry_run=True)
assert batch_response.success_count == 2
finally:
_helpers.positional_parameters_enforcement = enforcement

@pytest.mark.parametrize('status', HTTP_ERROR_CODES)
def test_send_all_detailed_error(self, status):
success_payload = json.dumps({'name': 'message-id'})
Expand Down