firebase-admin 7.4.0__tar.gz → 7.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/PKG-INFO +2 -1
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/__about__.py +1 -1
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/_messaging_encoder.py +45 -12
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/_messaging_utils.py +2 -1
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/messaging.py +38 -25
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin.egg-info/PKG-INFO +2 -1
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin.egg-info/requires.txt +3 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/setup.py +1 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_messaging.py +150 -5
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/testutils.py +4 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/LICENSE +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/README.md +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/__init__.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/_auth_client.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/_auth_providers.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/_auth_utils.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/_http_client.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/_retry.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/_rfc3339.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/_sseclient.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/_token_gen.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/_user_identifier.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/_user_import.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/_user_mgt.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/_utils.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/app_check.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/auth.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/credentials.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/db.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/exceptions.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/firestore.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/firestore_async.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/functions.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/instance_id.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/ml.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/phone_number_verification.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/project_management.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/remote_config.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/storage.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin/tenant_mgt.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin.egg-info/SOURCES.txt +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin.egg-info/dependency_links.txt +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/firebase_admin.egg-info/top_level.txt +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/setup.cfg +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_app.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_app_check.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_auth_providers.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_credentials.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_db.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_exceptions.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_firestore.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_firestore_async.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_functions.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_http_client.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_instance_id.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_ml.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_phone_number_verification.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_project_management.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_remote_config.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_retry.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_rfc3339.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_sseclient.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_storage.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_tenant_mgt.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_token_gen.py +0 -0
- {firebase_admin-7.4.0 → firebase_admin-7.5.0}/tests/test_user_mgt.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: firebase_admin
|
|
3
|
-
Version: 7.
|
|
3
|
+
Version: 7.5.0
|
|
4
4
|
Summary: Firebase Admin Python SDK
|
|
5
5
|
Home-page: https://firebase.google.com/docs/admin/setup/
|
|
6
6
|
Author: Firebase
|
|
@@ -25,6 +25,7 @@ Requires-Dist: google-api-core[grpc]<3.0.0dev,>=2.25.1; platform_python_implemen
|
|
|
25
25
|
Requires-Dist: google-cloud-firestore>=2.21.0; platform_python_implementation != "PyPy"
|
|
26
26
|
Requires-Dist: google-cloud-storage>=3.1.1
|
|
27
27
|
Requires-Dist: pyjwt[crypto]>=2.10.1
|
|
28
|
+
Requires-Dist: cryptography<44.0.0; platform_python_implementation == "PyPy" and python_version < "3.11"
|
|
28
29
|
Requires-Dist: httpx[http2]==0.28.1
|
|
29
30
|
Dynamic: author
|
|
30
31
|
Dynamic: classifier
|
|
@@ -19,6 +19,7 @@ import json
|
|
|
19
19
|
import math
|
|
20
20
|
import numbers
|
|
21
21
|
import re
|
|
22
|
+
import warnings
|
|
22
23
|
|
|
23
24
|
from firebase_admin import _messaging_utils
|
|
24
25
|
|
|
@@ -27,7 +28,7 @@ class Message:
|
|
|
27
28
|
"""A message that can be sent via Firebase Cloud Messaging.
|
|
28
29
|
|
|
29
30
|
Contains payload information as well as recipient information. In particular, the message must
|
|
30
|
-
contain exactly one of token, topic or condition fields.
|
|
31
|
+
contain exactly one of fid, token, topic or condition fields.
|
|
31
32
|
|
|
32
33
|
Args:
|
|
33
34
|
data: A dictionary of data fields (optional). All keys and values in the dictionary must be
|
|
@@ -37,20 +38,29 @@ class Message:
|
|
|
37
38
|
webpush: An instance of ``messaging.WebpushConfig`` (optional).
|
|
38
39
|
apns: An instance of ``messaging.ApnsConfig`` (optional).
|
|
39
40
|
fcm_options: An instance of ``messaging.FCMOptions`` (optional).
|
|
40
|
-
|
|
41
|
+
fid: The Firebase installation ID of an FCM registered app instance to which the
|
|
42
|
+
message should be sent (optional).
|
|
43
|
+
token: Deprecated. Use ``fid`` instead.
|
|
41
44
|
topic: Name of the FCM topic to which the message should be sent (optional). Topic name
|
|
42
45
|
may contain the ``/topics/`` prefix.
|
|
43
46
|
condition: The FCM condition to which the message should be sent (optional).
|
|
44
47
|
"""
|
|
45
48
|
|
|
46
49
|
def __init__(self, data=None, notification=None, android=None, webpush=None, apns=None,
|
|
47
|
-
fcm_options=None, token=None, topic=None, condition=None):
|
|
50
|
+
fcm_options=None, token=None, topic=None, condition=None, fid=None):
|
|
51
|
+
if token is not None:
|
|
52
|
+
warnings.warn(
|
|
53
|
+
"Message.token is deprecated. Use Message.fid instead.",
|
|
54
|
+
DeprecationWarning,
|
|
55
|
+
stacklevel=2
|
|
56
|
+
)
|
|
48
57
|
self.data = data
|
|
49
58
|
self.notification = notification
|
|
50
59
|
self.android = android
|
|
51
60
|
self.webpush = webpush
|
|
52
61
|
self.apns = apns
|
|
53
62
|
self.fcm_options = fcm_options
|
|
63
|
+
self.fid = fid
|
|
54
64
|
self.token = token
|
|
55
65
|
self.topic = topic
|
|
56
66
|
self.condition = condition
|
|
@@ -60,10 +70,10 @@ class Message:
|
|
|
60
70
|
|
|
61
71
|
|
|
62
72
|
class MulticastMessage:
|
|
63
|
-
"""A message that can be sent to multiple tokens via Firebase Cloud Messaging.
|
|
73
|
+
"""A message that can be sent to multiple tokens or fids via Firebase Cloud Messaging.
|
|
64
74
|
|
|
65
75
|
Args:
|
|
66
|
-
tokens:
|
|
76
|
+
tokens: Deprecated. Use ``fids`` instead (optional).
|
|
67
77
|
data: A dictionary of data fields (optional). All keys and values in the dictionary must be
|
|
68
78
|
strings.
|
|
69
79
|
notification: An instance of ``messaging.Notification`` (optional).
|
|
@@ -71,13 +81,35 @@ class MulticastMessage:
|
|
|
71
81
|
webpush: An instance of ``messaging.WebpushConfig`` (optional).
|
|
72
82
|
apns: An instance of ``messaging.ApnsConfig`` (optional).
|
|
73
83
|
fcm_options: An instance of ``messaging.FCMOptions`` (optional).
|
|
84
|
+
fids: A list of Firebase Installation IDs of targeted app instances (optional).
|
|
74
85
|
"""
|
|
75
|
-
def __init__(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if
|
|
79
|
-
|
|
86
|
+
def __init__(
|
|
87
|
+
self, tokens=None, data=None, notification=None, android=None,
|
|
88
|
+
webpush=None, apns=None, fcm_options=None, fids=None):
|
|
89
|
+
if tokens is not None:
|
|
90
|
+
warnings.warn(
|
|
91
|
+
"MulticastMessage.tokens is deprecated. Use MulticastMessage.fids instead.",
|
|
92
|
+
DeprecationWarning,
|
|
93
|
+
stacklevel=2
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
if tokens is None and fids is None:
|
|
97
|
+
raise ValueError(
|
|
98
|
+
"Must specify at least one of MulticastMessage.tokens or MulticastMessage.fids.")
|
|
99
|
+
|
|
100
|
+
if tokens is not None:
|
|
101
|
+
_Validators.check_string_list('MulticastMessage.tokens', tokens)
|
|
102
|
+
if fids is not None:
|
|
103
|
+
_Validators.check_string_list('MulticastMessage.fids', fids)
|
|
104
|
+
|
|
105
|
+
tokens_len = len(tokens) if tokens is not None else 0
|
|
106
|
+
fids_len = len(fids) if fids is not None else 0
|
|
107
|
+
if tokens_len + fids_len > 500:
|
|
108
|
+
raise ValueError(
|
|
109
|
+
'Total number of tokens and fids must not exceed 500.')
|
|
110
|
+
|
|
80
111
|
self.tokens = tokens
|
|
112
|
+
self.fids = fids
|
|
81
113
|
self.data = data
|
|
82
114
|
self.notification = notification
|
|
83
115
|
self.android = android
|
|
@@ -695,6 +727,7 @@ class MessageEncoder(json.JSONEncoder):
|
|
|
695
727
|
'Message.condition', o.condition, non_empty=True),
|
|
696
728
|
'data': _Validators.check_string_dict('Message.data', o.data),
|
|
697
729
|
'notification': MessageEncoder.encode_notification(o.notification),
|
|
730
|
+
'fid': _Validators.check_string('Message.fid', o.fid, non_empty=True),
|
|
698
731
|
'token': _Validators.check_string('Message.token', o.token, non_empty=True),
|
|
699
732
|
'topic': _Validators.check_string('Message.topic', o.topic, non_empty=True),
|
|
700
733
|
'webpush': MessageEncoder.encode_webpush(o.webpush),
|
|
@@ -702,9 +735,9 @@ class MessageEncoder(json.JSONEncoder):
|
|
|
702
735
|
}
|
|
703
736
|
result['topic'] = MessageEncoder.sanitize_topic_name(result.get('topic'))
|
|
704
737
|
result = MessageEncoder.remove_null_values(result)
|
|
705
|
-
target_count = sum(t in result for t in ['token', 'topic', 'condition'])
|
|
738
|
+
target_count = sum(t in result for t in ['fid', 'token', 'topic', 'condition'])
|
|
706
739
|
if target_count != 1:
|
|
707
|
-
raise ValueError('Exactly one of token, topic or condition must be specified.')
|
|
740
|
+
raise ValueError('Exactly one of fid, token, topic or condition must be specified.')
|
|
708
741
|
return result
|
|
709
742
|
|
|
710
743
|
@classmethod
|
|
@@ -519,7 +519,8 @@ class SenderIdMismatchError(exceptions.PermissionDeniedError):
|
|
|
519
519
|
class UnregisteredError(exceptions.NotFoundError):
|
|
520
520
|
"""App instance was unregistered from FCM.
|
|
521
521
|
|
|
522
|
-
This usually means that the token
|
|
522
|
+
This usually means that the registration token or installation ID (FID) used
|
|
523
|
+
is no longer valid and a new one must be used."""
|
|
523
524
|
|
|
524
525
|
def __init__(self, message, cause=None, http_response=None):
|
|
525
526
|
exceptions.NotFoundError.__init__(self, message, cause, http_response)
|
|
@@ -20,6 +20,7 @@ import concurrent.futures
|
|
|
20
20
|
import json
|
|
21
21
|
import asyncio
|
|
22
22
|
import logging
|
|
23
|
+
import warnings
|
|
23
24
|
import requests
|
|
24
25
|
import httpx
|
|
25
26
|
|
|
@@ -172,13 +173,45 @@ async def send_each_async(
|
|
|
172
173
|
"""
|
|
173
174
|
return await _get_messaging_service(app).send_each_async(messages, dry_run)
|
|
174
175
|
|
|
176
|
+
def _get_messages_from_multicast(multicast_message: MulticastMessage) -> List[Message]:
|
|
177
|
+
"""Extracts individual Message objects from a MulticastMessage."""
|
|
178
|
+
if not isinstance(multicast_message, MulticastMessage):
|
|
179
|
+
raise ValueError('Message must be an instance of messaging.MulticastMessage class.')
|
|
180
|
+
|
|
181
|
+
messages = []
|
|
182
|
+
if multicast_message.tokens is not None:
|
|
183
|
+
with warnings.catch_warnings():
|
|
184
|
+
warnings.simplefilter("ignore", DeprecationWarning)
|
|
185
|
+
messages.extend([Message(
|
|
186
|
+
data=multicast_message.data,
|
|
187
|
+
notification=multicast_message.notification,
|
|
188
|
+
android=multicast_message.android,
|
|
189
|
+
webpush=multicast_message.webpush,
|
|
190
|
+
apns=multicast_message.apns,
|
|
191
|
+
fcm_options=multicast_message.fcm_options,
|
|
192
|
+
token=token
|
|
193
|
+
) for token in multicast_message.tokens])
|
|
194
|
+
|
|
195
|
+
if multicast_message.fids is not None:
|
|
196
|
+
messages.extend([Message(
|
|
197
|
+
data=multicast_message.data,
|
|
198
|
+
notification=multicast_message.notification,
|
|
199
|
+
android=multicast_message.android,
|
|
200
|
+
webpush=multicast_message.webpush,
|
|
201
|
+
apns=multicast_message.apns,
|
|
202
|
+
fcm_options=multicast_message.fcm_options,
|
|
203
|
+
fid=fid
|
|
204
|
+
) for fid in multicast_message.fids])
|
|
205
|
+
|
|
206
|
+
return messages
|
|
207
|
+
|
|
175
208
|
async def send_each_for_multicast_async(
|
|
176
209
|
multicast_message: MulticastMessage,
|
|
177
210
|
dry_run: bool = False,
|
|
178
211
|
app: Optional[App] = None
|
|
179
212
|
) -> BatchResponse:
|
|
180
|
-
"""Sends the given
|
|
181
|
-
(FCM).
|
|
213
|
+
"""Sends the given multicast message to each token or fid asynchronously via
|
|
214
|
+
Firebase Cloud Messaging (FCM).
|
|
182
215
|
|
|
183
216
|
If the ``dry_run`` mode is enabled, the message will not be actually delivered to the
|
|
184
217
|
recipients. Instead, FCM performs all the usual validations and emulates the send operation.
|
|
@@ -195,21 +228,11 @@ async def send_each_for_multicast_async(
|
|
|
195
228
|
FirebaseError: If an error occurs while sending the message to the FCM service.
|
|
196
229
|
ValueError: If the input arguments are invalid.
|
|
197
230
|
"""
|
|
198
|
-
|
|
199
|
-
raise ValueError('Message must be an instance of messaging.MulticastMessage class.')
|
|
200
|
-
messages = [Message(
|
|
201
|
-
data=multicast_message.data,
|
|
202
|
-
notification=multicast_message.notification,
|
|
203
|
-
android=multicast_message.android,
|
|
204
|
-
webpush=multicast_message.webpush,
|
|
205
|
-
apns=multicast_message.apns,
|
|
206
|
-
fcm_options=multicast_message.fcm_options,
|
|
207
|
-
token=token
|
|
208
|
-
) for token in multicast_message.tokens]
|
|
231
|
+
messages = _get_messages_from_multicast(multicast_message)
|
|
209
232
|
return await _get_messaging_service(app).send_each_async(messages, dry_run)
|
|
210
233
|
|
|
211
234
|
def send_each_for_multicast(multicast_message, dry_run=False, app=None):
|
|
212
|
-
"""Sends the given
|
|
235
|
+
"""Sends the given multicast message to each token or fid via Firebase Cloud Messaging (FCM).
|
|
213
236
|
|
|
214
237
|
If the ``dry_run`` mode is enabled, the message will not be actually delivered to the
|
|
215
238
|
recipients. Instead, FCM performs all the usual validations and emulates the send operation.
|
|
@@ -226,17 +249,7 @@ def send_each_for_multicast(multicast_message, dry_run=False, app=None):
|
|
|
226
249
|
FirebaseError: If an error occurs while sending the message to the FCM service.
|
|
227
250
|
ValueError: If the input arguments are invalid.
|
|
228
251
|
"""
|
|
229
|
-
|
|
230
|
-
raise ValueError('Message must be an instance of messaging.MulticastMessage class.')
|
|
231
|
-
messages = [Message(
|
|
232
|
-
data=multicast_message.data,
|
|
233
|
-
notification=multicast_message.notification,
|
|
234
|
-
android=multicast_message.android,
|
|
235
|
-
webpush=multicast_message.webpush,
|
|
236
|
-
apns=multicast_message.apns,
|
|
237
|
-
fcm_options=multicast_message.fcm_options,
|
|
238
|
-
token=token
|
|
239
|
-
) for token in multicast_message.tokens]
|
|
252
|
+
messages = _get_messages_from_multicast(multicast_message)
|
|
240
253
|
return _get_messaging_service(app).send_each(messages, dry_run)
|
|
241
254
|
|
|
242
255
|
def subscribe_to_topic(tokens, topic, app=None):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: firebase_admin
|
|
3
|
-
Version: 7.
|
|
3
|
+
Version: 7.5.0
|
|
4
4
|
Summary: Firebase Admin Python SDK
|
|
5
5
|
Home-page: https://firebase.google.com/docs/admin/setup/
|
|
6
6
|
Author: Firebase
|
|
@@ -25,6 +25,7 @@ Requires-Dist: google-api-core[grpc]<3.0.0dev,>=2.25.1; platform_python_implemen
|
|
|
25
25
|
Requires-Dist: google-cloud-firestore>=2.21.0; platform_python_implementation != "PyPy"
|
|
26
26
|
Requires-Dist: google-cloud-storage>=3.1.1
|
|
27
27
|
Requires-Dist: pyjwt[crypto]>=2.10.1
|
|
28
|
+
Requires-Dist: cryptography<44.0.0; platform_python_implementation == "PyPy" and python_version < "3.11"
|
|
28
29
|
Requires-Dist: httpx[http2]==0.28.1
|
|
29
30
|
Dynamic: author
|
|
30
31
|
Dynamic: classifier
|
|
@@ -42,6 +42,7 @@ install_requires = [
|
|
|
42
42
|
'google-cloud-firestore>=2.21.0; platform.python_implementation != "PyPy"',
|
|
43
43
|
'google-cloud-storage>=3.1.1',
|
|
44
44
|
'pyjwt[crypto] >= 2.10.1',
|
|
45
|
+
'cryptography < 44.0.0; platform.python_implementation == "PyPy" and python_version < "3.11"',
|
|
45
46
|
'httpx[http2] == 0.28.1',
|
|
46
47
|
]
|
|
47
48
|
|
|
@@ -73,18 +73,22 @@ class TestMessageStr:
|
|
|
73
73
|
messaging.Message(topic='topic', condition='condition'),
|
|
74
74
|
messaging.Message(condition='condition', token='token'),
|
|
75
75
|
messaging.Message(topic='topic', token='token', condition='condition'),
|
|
76
|
+
messaging.Message(fid='fid', token='token'),
|
|
77
|
+
messaging.Message(fid='fid', topic='topic'),
|
|
78
|
+
messaging.Message(fid='fid', condition='condition'),
|
|
79
|
+
messaging.Message(fid='fid', token='token', topic='topic'),
|
|
76
80
|
])
|
|
77
81
|
def test_invalid_target_message(self, msg):
|
|
78
82
|
with pytest.raises(ValueError) as excinfo:
|
|
79
83
|
str(msg)
|
|
80
84
|
assert str(
|
|
81
|
-
excinfo.value) == 'Exactly one of token, topic or condition must be specified.'
|
|
85
|
+
excinfo.value) == 'Exactly one of fid, token, topic or condition must be specified.'
|
|
82
86
|
|
|
83
87
|
def test_empty_message(self):
|
|
84
88
|
assert str(messaging.Message(token='value')) == '{"token": "value"}'
|
|
85
89
|
assert str(messaging.Message(topic='value')) == '{"topic": "value"}'
|
|
86
|
-
assert str(messaging.Message(condition='value')
|
|
87
|
-
|
|
90
|
+
assert str(messaging.Message(condition='value')) == '{"condition": "value"}'
|
|
91
|
+
assert str(messaging.Message(fid='value')) == '{"fid": "value"}'
|
|
88
92
|
|
|
89
93
|
def test_data_message(self):
|
|
90
94
|
assert str(messaging.Message(topic='topic', data={})
|
|
@@ -95,6 +99,12 @@ class TestMessageStr:
|
|
|
95
99
|
|
|
96
100
|
class TestMulticastMessage:
|
|
97
101
|
|
|
102
|
+
def test_invalid_targets(self):
|
|
103
|
+
with pytest.raises(ValueError) as excinfo:
|
|
104
|
+
messaging.MulticastMessage()
|
|
105
|
+
expected = "Must specify at least one of MulticastMessage.tokens or MulticastMessage.fids."
|
|
106
|
+
assert str(excinfo.value) == expected
|
|
107
|
+
|
|
98
108
|
@pytest.mark.parametrize('tokens', NON_LIST_ARGS)
|
|
99
109
|
def test_invalid_tokens_type(self, tokens):
|
|
100
110
|
with pytest.raises(ValueError) as excinfo:
|
|
@@ -109,7 +119,7 @@ class TestMulticastMessage:
|
|
|
109
119
|
def test_tokens_over_500(self):
|
|
110
120
|
with pytest.raises(ValueError) as excinfo:
|
|
111
121
|
messaging.MulticastMessage(tokens=['token' for _ in range(0, 501)])
|
|
112
|
-
expected = '
|
|
122
|
+
expected = 'Total number of tokens and fids must not exceed 500.'
|
|
113
123
|
assert str(excinfo.value) == expected
|
|
114
124
|
|
|
115
125
|
def test_tokens_type(self):
|
|
@@ -119,6 +129,54 @@ class TestMulticastMessage:
|
|
|
119
129
|
message = messaging.MulticastMessage(tokens=['token' for _ in range(0, 500)])
|
|
120
130
|
assert len(message.tokens) == 500
|
|
121
131
|
|
|
132
|
+
@pytest.mark.parametrize('fids', NON_LIST_ARGS)
|
|
133
|
+
def test_invalid_fids_type(self, fids):
|
|
134
|
+
with pytest.raises(ValueError) as excinfo:
|
|
135
|
+
messaging.MulticastMessage(fids=fids)
|
|
136
|
+
if isinstance(fids, list):
|
|
137
|
+
expected = 'MulticastMessage.fids must not contain non-string values.'
|
|
138
|
+
assert str(excinfo.value) == expected
|
|
139
|
+
else:
|
|
140
|
+
expected = 'MulticastMessage.fids must be a list of strings.'
|
|
141
|
+
assert str(excinfo.value) == expected
|
|
142
|
+
|
|
143
|
+
def test_fids_over_500(self):
|
|
144
|
+
with pytest.raises(ValueError) as excinfo:
|
|
145
|
+
messaging.MulticastMessage(fids=['fid' for _ in range(0, 501)])
|
|
146
|
+
expected = 'Total number of tokens and fids must not exceed 500.'
|
|
147
|
+
assert str(excinfo.value) == expected
|
|
148
|
+
|
|
149
|
+
def test_fids_type(self):
|
|
150
|
+
message = messaging.MulticastMessage(fids=['fid'])
|
|
151
|
+
assert len(message.fids) == 1
|
|
152
|
+
|
|
153
|
+
message = messaging.MulticastMessage(fids=['fid' for _ in range(0, 500)])
|
|
154
|
+
assert len(message.fids) == 500
|
|
155
|
+
|
|
156
|
+
def test_combined_over_500(self):
|
|
157
|
+
with pytest.raises(ValueError) as excinfo:
|
|
158
|
+
messaging.MulticastMessage(
|
|
159
|
+
tokens=['token' for _ in range(0, 250)],
|
|
160
|
+
fids=['fid' for _ in range(0, 251)]
|
|
161
|
+
)
|
|
162
|
+
expected = 'Total number of tokens and fids must not exceed 500.'
|
|
163
|
+
assert str(excinfo.value) == expected
|
|
164
|
+
|
|
165
|
+
def test_mixed_targets(self):
|
|
166
|
+
message = messaging.MulticastMessage(tokens=['token'], fids=['fid'])
|
|
167
|
+
assert len(message.tokens) == 1
|
|
168
|
+
assert len(message.fids) == 1
|
|
169
|
+
|
|
170
|
+
def test_tokens_deprecation_warning(self):
|
|
171
|
+
msg = 'MulticastMessage.tokens is deprecated. Use MulticastMessage.fids instead.'
|
|
172
|
+
with pytest.warns(DeprecationWarning, match=msg):
|
|
173
|
+
messaging.MulticastMessage(tokens=['token'])
|
|
174
|
+
|
|
175
|
+
def test_tokens_deprecation_warning_positional(self):
|
|
176
|
+
msg = 'MulticastMessage.tokens is deprecated. Use MulticastMessage.fids instead.'
|
|
177
|
+
with pytest.warns(DeprecationWarning, match=msg):
|
|
178
|
+
messaging.MulticastMessage(['token'])
|
|
179
|
+
|
|
122
180
|
|
|
123
181
|
class TestMessageEncoder:
|
|
124
182
|
|
|
@@ -128,11 +186,16 @@ class TestMessageEncoder:
|
|
|
128
186
|
messaging.Message(topic='topic', condition='condition'),
|
|
129
187
|
messaging.Message(condition='condition', token='token'),
|
|
130
188
|
messaging.Message(topic='topic', token='token', condition='condition'),
|
|
189
|
+
messaging.Message(fid='fid', token='token'),
|
|
190
|
+
messaging.Message(fid='fid', topic='topic'),
|
|
191
|
+
messaging.Message(fid='fid', condition='condition'),
|
|
192
|
+
messaging.Message(fid='fid', token='token', topic='topic'),
|
|
131
193
|
])
|
|
132
194
|
def test_invalid_target_message(self, msg):
|
|
133
195
|
with pytest.raises(ValueError) as excinfo:
|
|
134
196
|
check_encoding(msg)
|
|
135
|
-
|
|
197
|
+
expected = 'Exactly one of fid, token, topic or condition must be specified.'
|
|
198
|
+
assert str(excinfo.value) == expected
|
|
136
199
|
|
|
137
200
|
@pytest.mark.parametrize('target', NON_STRING_ARGS + [''])
|
|
138
201
|
def test_invalid_token(self, target):
|
|
@@ -140,6 +203,12 @@ class TestMessageEncoder:
|
|
|
140
203
|
check_encoding(messaging.Message(token=target))
|
|
141
204
|
assert str(excinfo.value) == 'Message.token must be a non-empty string.'
|
|
142
205
|
|
|
206
|
+
@pytest.mark.parametrize('target', NON_STRING_ARGS + [''])
|
|
207
|
+
def test_invalid_fid(self, target):
|
|
208
|
+
with pytest.raises(ValueError) as excinfo:
|
|
209
|
+
check_encoding(messaging.Message(fid=target))
|
|
210
|
+
assert str(excinfo.value) == 'Message.fid must be a non-empty string.'
|
|
211
|
+
|
|
143
212
|
@pytest.mark.parametrize('target', NON_STRING_ARGS + [''])
|
|
144
213
|
def test_invalid_topic(self, target):
|
|
145
214
|
with pytest.raises(ValueError) as excinfo:
|
|
@@ -159,9 +228,15 @@ class TestMessageEncoder:
|
|
|
159
228
|
|
|
160
229
|
def test_empty_message(self):
|
|
161
230
|
check_encoding(messaging.Message(token='value'), {'token': 'value'})
|
|
231
|
+
check_encoding(messaging.Message(fid='value'), {'fid': 'value'})
|
|
162
232
|
check_encoding(messaging.Message(topic='value'), {'topic': 'value'})
|
|
163
233
|
check_encoding(messaging.Message(condition='value'), {'condition': 'value'})
|
|
164
234
|
|
|
235
|
+
def test_token_deprecation_warning(self):
|
|
236
|
+
msg = 'Message.token is deprecated. Use Message.fid instead.'
|
|
237
|
+
with pytest.warns(DeprecationWarning, match=msg):
|
|
238
|
+
messaging.Message(token='value')
|
|
239
|
+
|
|
165
240
|
@pytest.mark.parametrize('data', NON_DICT_ARGS)
|
|
166
241
|
def test_invalid_data_message(self, data):
|
|
167
242
|
with pytest.raises(ValueError):
|
|
@@ -2212,6 +2287,76 @@ class TestSendEachForMulticast(TestSendEach):
|
|
|
2212
2287
|
assert all(r.success for r in batch_response.responses)
|
|
2213
2288
|
assert not any(r.exception for r in batch_response.responses)
|
|
2214
2289
|
|
|
2290
|
+
def test_send_each_for_multicast_fids(self):
|
|
2291
|
+
payload1 = json.dumps({'name': 'message-id1'})
|
|
2292
|
+
payload2 = json.dumps({'name': 'message-id2'})
|
|
2293
|
+
_ = self._instrument_messaging_service(
|
|
2294
|
+
response_dict={'foo1': [200, payload1], 'foo2': [200, payload2]})
|
|
2295
|
+
msg = messaging.MulticastMessage(fids=['foo1', 'foo2'])
|
|
2296
|
+
batch_response = messaging.send_each_for_multicast(msg, dry_run=True)
|
|
2297
|
+
assert batch_response.success_count == 2
|
|
2298
|
+
assert batch_response.failure_count == 0
|
|
2299
|
+
assert len(batch_response.responses) == 2
|
|
2300
|
+
assert [r.message_id for r in batch_response.responses] == ['message-id1', 'message-id2']
|
|
2301
|
+
assert all(r.success for r in batch_response.responses)
|
|
2302
|
+
assert not any(r.exception for r in batch_response.responses)
|
|
2303
|
+
|
|
2304
|
+
def test_send_each_for_multicast_mixed(self):
|
|
2305
|
+
payload1 = json.dumps({'name': 'message-id1'})
|
|
2306
|
+
payload2 = json.dumps({'name': 'message-id2'})
|
|
2307
|
+
_ = self._instrument_messaging_service(
|
|
2308
|
+
response_dict={'foo1': [200, payload1], 'foo2': [200, payload2]})
|
|
2309
|
+
msg = messaging.MulticastMessage(tokens=['foo1'], fids=['foo2'])
|
|
2310
|
+
batch_response = messaging.send_each_for_multicast(msg, dry_run=True)
|
|
2311
|
+
assert batch_response.success_count == 2
|
|
2312
|
+
assert batch_response.failure_count == 0
|
|
2313
|
+
assert len(batch_response.responses) == 2
|
|
2314
|
+
assert [r.message_id for r in batch_response.responses] == ['message-id1', 'message-id2']
|
|
2315
|
+
assert all(r.success for r in batch_response.responses)
|
|
2316
|
+
assert not any(r.exception for r in batch_response.responses)
|
|
2317
|
+
|
|
2318
|
+
@respx.mock
|
|
2319
|
+
@pytest.mark.asyncio
|
|
2320
|
+
async def test_send_each_for_multicast_async(self):
|
|
2321
|
+
responses = [
|
|
2322
|
+
respx.MockResponse(200, http_version='HTTP/2', json={'name': 'message-id1'}),
|
|
2323
|
+
respx.MockResponse(200, http_version='HTTP/2', json={'name': 'message-id2'}),
|
|
2324
|
+
]
|
|
2325
|
+
msg = messaging.MulticastMessage(tokens=['foo1', 'foo2'])
|
|
2326
|
+
route = respx.request(
|
|
2327
|
+
method='POST',
|
|
2328
|
+
url='https://fcm.googleapis.com/v1/projects/explicit-project-id/messages:send'
|
|
2329
|
+
)
|
|
2330
|
+
route.side_effect = responses
|
|
2331
|
+
batch_response = await messaging.send_each_for_multicast_async(msg, dry_run=True)
|
|
2332
|
+
assert batch_response.success_count == 2
|
|
2333
|
+
assert batch_response.failure_count == 0
|
|
2334
|
+
assert len(batch_response.responses) == 2
|
|
2335
|
+
assert [r.message_id for r in batch_response.responses] == ['message-id1', 'message-id2']
|
|
2336
|
+
assert all(r.success for r in batch_response.responses)
|
|
2337
|
+
assert not any(r.exception for r in batch_response.responses)
|
|
2338
|
+
|
|
2339
|
+
@respx.mock
|
|
2340
|
+
@pytest.mark.asyncio
|
|
2341
|
+
async def test_send_each_for_multicast_async_fids(self):
|
|
2342
|
+
responses = [
|
|
2343
|
+
respx.MockResponse(200, http_version='HTTP/2', json={'name': 'message-id1'}),
|
|
2344
|
+
respx.MockResponse(200, http_version='HTTP/2', json={'name': 'message-id2'}),
|
|
2345
|
+
]
|
|
2346
|
+
msg = messaging.MulticastMessage(fids=['foo1', 'foo2'])
|
|
2347
|
+
route = respx.request(
|
|
2348
|
+
method='POST',
|
|
2349
|
+
url='https://fcm.googleapis.com/v1/projects/explicit-project-id/messages:send'
|
|
2350
|
+
)
|
|
2351
|
+
route.side_effect = responses
|
|
2352
|
+
batch_response = await messaging.send_each_for_multicast_async(msg, dry_run=True)
|
|
2353
|
+
assert batch_response.success_count == 2
|
|
2354
|
+
assert batch_response.failure_count == 0
|
|
2355
|
+
assert len(batch_response.responses) == 2
|
|
2356
|
+
assert [r.message_id for r in batch_response.responses] == ['message-id1', 'message-id2']
|
|
2357
|
+
assert all(r.success for r in batch_response.responses)
|
|
2358
|
+
assert not any(r.exception for r in batch_response.responses)
|
|
2359
|
+
|
|
2215
2360
|
@pytest.mark.parametrize('status', HTTP_ERROR_CODES)
|
|
2216
2361
|
def test_send_each_for_multicast_detailed_error(self, status):
|
|
2217
2362
|
success_payload = json.dumps({'name': 'message-id'})
|
|
@@ -159,6 +159,10 @@ class MockGoogleComputeEngineCredential(compute_engine.Credentials):
|
|
|
159
159
|
self._service_account_email = None
|
|
160
160
|
self._token_state = credentials.TokenState.INVALID
|
|
161
161
|
|
|
162
|
+
@property
|
|
163
|
+
def universe_domain(self):
|
|
164
|
+
return 'googleapis.com'
|
|
165
|
+
|
|
162
166
|
def refresh(self, request):
|
|
163
167
|
self.token = 'mock-compute-engine-token'
|
|
164
168
|
self._service_account_email = 'mock-gce-email'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|