Skip to content

Commit 3c3b5a8

Browse files
Doris-Gelahirumarambapragatimodisamueldg
authored
Add integration tests for send_each and send_each_for_multicast (#700)
* Add integration tests for send_each and send_each_for_multicast Add test_send_each, test_send_each_500 and test_send_each_for_multicast * chore: Fix pypy tests (#694) * chore(auth): Update Auth API to `v2` (#691) * `v2beta1` -> `v2` * Reverting auto formatting changes * undo auto formatting * Add release notes to project URLs in PyPI (#679) It's useful to be able to navigate to the release notes easily from the package index when upgrading. "Release Notes" is a special keyword that will have the scroll icon in the project page. A random example: * https://pypi.org/project/streamlit/ * https://github.com/streamlit/streamlit/blob/815a3ea6fa3e7f9099b479e8365bd3a5874ddc35/lib/setup.py#L111 Co-authored-by: Lahiru Maramba <[email protected]> --------- Co-authored-by: Lahiru Maramba <[email protected]> Co-authored-by: pragatimodi <[email protected]> Co-authored-by: Samuel Dion-Girardeau <[email protected]>
1 parent 7f5d62e commit 3c3b5a8

File tree

8 files changed

+72
-9
lines changed

8 files changed

+72
-9
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
python: ['3.7', '3.8', '3.9', '3.10', 'pypy3.7']
11+
python: ['3.7', '3.8', '3.9', '3.10', 'pypy3.8']
1212

1313
steps:
1414
- uses: actions/checkout@v3

firebase_admin/_auth_client.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self, app, tenant_id=None):
5050
if emulator_host:
5151
base_url = 'http://{0}/identitytoolkit.googleapis.com'.format(emulator_host)
5252
endpoint_urls['v1'] = base_url + '/v1'
53-
endpoint_urls['v2beta1'] = base_url + '/v2beta1'
53+
endpoint_urls['v2'] = base_url + '/v2'
5454
credential = _utils.EmulatorAdminCredentials()
5555
self.emulated = True
5656
else:
@@ -67,7 +67,7 @@ def __init__(self, app, tenant_id=None):
6767
self._user_manager = _user_mgt.UserManager(
6868
http_client, app.project_id, tenant_id, url_override=endpoint_urls.get('v1'))
6969
self._provider_manager = _auth_providers.ProviderConfigClient(
70-
http_client, app.project_id, tenant_id, url_override=endpoint_urls.get('v2beta1'))
70+
http_client, app.project_id, tenant_id, url_override=endpoint_urls.get('v2'))
7171

7272
@property
7373
def tenant_id(self):

firebase_admin/_auth_providers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def items(self):
176176
class ProviderConfigClient:
177177
"""Client for managing Auth provider configurations."""
178178

179-
PROVIDER_CONFIG_URL = 'https://identitytoolkit.googleapis.com/v2beta1'
179+
PROVIDER_CONFIG_URL = 'https://identitytoolkit.googleapis.com/v2'
180180

181181
def __init__(self, http_client, project_id, tenant_id=None, url_override=None):
182182
self.http_client = http_client

firebase_admin/tenant_mgt.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def enable_email_link_sign_in(self):
232232
class _TenantManagementService:
233233
"""Firebase tenant management service."""
234234

235-
TENANT_MGT_URL = 'https://identitytoolkit.googleapis.com/v2beta1'
235+
TENANT_MGT_URL = 'https://identitytoolkit.googleapis.com/v2'
236236

237237
def __init__(self, app):
238238
credential = app.credential.get_credential()

integration/test_messaging.py

+62
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,68 @@ def test_send_malformed_token():
8686
with pytest.raises(exceptions.InvalidArgumentError):
8787
messaging.send(msg, dry_run=True)
8888

89+
def test_send_each():
90+
messages = [
91+
messaging.Message(
92+
topic='foo-bar', notification=messaging.Notification('Title', 'Body')),
93+
messaging.Message(
94+
topic='foo-bar', notification=messaging.Notification('Title', 'Body')),
95+
messaging.Message(
96+
token='not-a-token', notification=messaging.Notification('Title', 'Body')),
97+
]
98+
99+
batch_response = messaging.send_each(messages, dry_run=True)
100+
101+
assert batch_response.success_count == 2
102+
assert batch_response.failure_count == 1
103+
assert len(batch_response.responses) == 3
104+
105+
response = batch_response.responses[0]
106+
assert response.success is True
107+
assert response.exception is None
108+
assert re.match('^projects/.*/messages/.*$', response.message_id)
109+
110+
response = batch_response.responses[1]
111+
assert response.success is True
112+
assert response.exception is None
113+
assert re.match('^projects/.*/messages/.*$', response.message_id)
114+
115+
response = batch_response.responses[2]
116+
assert response.success is False
117+
assert isinstance(response.exception, exceptions.InvalidArgumentError)
118+
assert response.message_id is None
119+
120+
def test_send_each_500():
121+
messages = []
122+
for msg_number in range(500):
123+
topic = 'foo-bar-{0}'.format(msg_number % 10)
124+
messages.append(messaging.Message(topic=topic))
125+
126+
batch_response = messaging.send_each(messages, dry_run=True)
127+
128+
assert batch_response.success_count == 500
129+
assert batch_response.failure_count == 0
130+
assert len(batch_response.responses) == 500
131+
for response in batch_response.responses:
132+
assert response.success is True
133+
assert response.exception is None
134+
assert re.match('^projects/.*/messages/.*$', response.message_id)
135+
136+
def test_send_each_for_multicast():
137+
multicast = messaging.MulticastMessage(
138+
notification=messaging.Notification('Title', 'Body'),
139+
tokens=['not-a-token', 'also-not-a-token'])
140+
141+
batch_response = messaging.send_each_for_multicast(multicast)
142+
143+
assert batch_response.success_count == 0
144+
assert batch_response.failure_count == 2
145+
assert len(batch_response.responses) == 2
146+
for response in batch_response.responses:
147+
assert response.success is False
148+
assert response.exception is not None
149+
assert response.message_id is None
150+
89151
def test_send_all():
90152
messages = [
91153
messaging.Message(

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
long_description=long_description,
5353
url=about['__url__'],
5454
project_urls={
55+
'Release Notes': 'https://firebase.google.com/support/release-notes/admin/python',
5556
'Source': 'https://github.com/firebase/firebase-admin-python',
5657
},
5758
author=about['__author__'],

tests/test_auth_providers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
from firebase_admin import exceptions
2424
from tests import testutils
2525

26-
ID_TOOLKIT_URL = 'https://identitytoolkit.googleapis.com/v2beta1'
26+
ID_TOOLKIT_URL = 'https://identitytoolkit.googleapis.com/v2'
2727
EMULATOR_HOST_ENV_VAR = 'FIREBASE_AUTH_EMULATOR_HOST'
2828
AUTH_EMULATOR_HOST = 'localhost:9099'
29-
EMULATED_ID_TOOLKIT_URL = 'http://{}/identitytoolkit.googleapis.com/v2beta1'.format(
29+
EMULATED_ID_TOOLKIT_URL = 'http://{}/identitytoolkit.googleapis.com/v2'.format(
3030
AUTH_EMULATOR_HOST)
3131
URL_PROJECT_SUFFIX = '/projects/mock-project-id'
3232
USER_MGT_URLS = {

tests/test_tenant_mgt.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@
108108
INVALID_BOOLEANS = ['', 1, 0, list(), tuple(), dict()]
109109

110110
USER_MGT_URL_PREFIX = 'https://identitytoolkit.googleapis.com/v1/projects/mock-project-id'
111-
PROVIDER_MGT_URL_PREFIX = 'https://identitytoolkit.googleapis.com/v2beta1/projects/mock-project-id'
112-
TENANT_MGT_URL_PREFIX = 'https://identitytoolkit.googleapis.com/v2beta1/projects/mock-project-id'
111+
PROVIDER_MGT_URL_PREFIX = 'https://identitytoolkit.googleapis.com/v2/projects/mock-project-id'
112+
TENANT_MGT_URL_PREFIX = 'https://identitytoolkit.googleapis.com/v2/projects/mock-project-id'
113113

114114

115115
@pytest.fixture(scope='module')

0 commit comments

Comments
 (0)