Skip to content
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

Add integration tests for send_each and send_each_for_multicast #700

Merged
merged 4 commits into from
Jun 7, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ['3.7', '3.8', '3.9', '3.10', 'pypy3.7']
python: ['3.7', '3.8', '3.9', '3.10', 'pypy3.8']

steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions firebase_admin/_auth_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, app, tenant_id=None):
if emulator_host:
base_url = 'http://{0}/identitytoolkit.googleapis.com'.format(emulator_host)
endpoint_urls['v1'] = base_url + '/v1'
endpoint_urls['v2beta1'] = base_url + '/v2beta1'
endpoint_urls['v2'] = base_url + '/v2'
credential = _utils.EmulatorAdminCredentials()
self.emulated = True
else:
Expand All @@ -67,7 +67,7 @@ def __init__(self, app, tenant_id=None):
self._user_manager = _user_mgt.UserManager(
http_client, app.project_id, tenant_id, url_override=endpoint_urls.get('v1'))
self._provider_manager = _auth_providers.ProviderConfigClient(
http_client, app.project_id, tenant_id, url_override=endpoint_urls.get('v2beta1'))
http_client, app.project_id, tenant_id, url_override=endpoint_urls.get('v2'))

@property
def tenant_id(self):
Expand Down
2 changes: 1 addition & 1 deletion firebase_admin/_auth_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def items(self):
class ProviderConfigClient:
"""Client for managing Auth provider configurations."""

PROVIDER_CONFIG_URL = 'https://identitytoolkit.googleapis.com/v2beta1'
PROVIDER_CONFIG_URL = 'https://identitytoolkit.googleapis.com/v2'

def __init__(self, http_client, project_id, tenant_id=None, url_override=None):
self.http_client = http_client
Expand Down
2 changes: 1 addition & 1 deletion firebase_admin/tenant_mgt.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def enable_email_link_sign_in(self):
class _TenantManagementService:
"""Firebase tenant management service."""

TENANT_MGT_URL = 'https://identitytoolkit.googleapis.com/v2beta1'
TENANT_MGT_URL = 'https://identitytoolkit.googleapis.com/v2'

def __init__(self, app):
credential = app.credential.get_credential()
Expand Down
62 changes: 62 additions & 0 deletions integration/test_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,68 @@ def test_send_malformed_token():
with pytest.raises(exceptions.InvalidArgumentError):
messaging.send(msg, dry_run=True)

def test_send_each():
messages = [
messaging.Message(
topic='foo-bar', notification=messaging.Notification('Title', 'Body')),
messaging.Message(
topic='foo-bar', notification=messaging.Notification('Title', 'Body')),
messaging.Message(
token='not-a-token', notification=messaging.Notification('Title', 'Body')),
]

batch_response = messaging.send_each(messages, dry_run=True)

assert batch_response.success_count == 2
assert batch_response.failure_count == 1
assert len(batch_response.responses) == 3

response = batch_response.responses[0]
assert response.success is True
assert response.exception is None
assert re.match('^projects/.*/messages/.*$', response.message_id)

response = batch_response.responses[1]
assert response.success is True
assert response.exception is None
assert re.match('^projects/.*/messages/.*$', response.message_id)

response = batch_response.responses[2]
assert response.success is False
assert isinstance(response.exception, exceptions.InvalidArgumentError)
assert response.message_id is None

def test_send_each_500():
messages = []
for msg_number in range(500):
topic = 'foo-bar-{0}'.format(msg_number % 10)
messages.append(messaging.Message(topic=topic))

batch_response = messaging.send_each(messages, dry_run=True)

assert batch_response.success_count == 500
assert batch_response.failure_count == 0
assert len(batch_response.responses) == 500
for response in batch_response.responses:
assert response.success is True
assert response.exception is None
assert re.match('^projects/.*/messages/.*$', response.message_id)

def test_send_each_for_multicast():
multicast = messaging.MulticastMessage(
notification=messaging.Notification('Title', 'Body'),
tokens=['not-a-token', 'also-not-a-token'])

batch_response = messaging.send_each_for_multicast(multicast)

assert batch_response.success_count == 0
assert batch_response.failure_count == 2
assert len(batch_response.responses) == 2
for response in batch_response.responses:
assert response.success is False
assert response.exception is not None
assert response.message_id is None

def test_send_all():
messages = [
messaging.Message(
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
long_description=long_description,
url=about['__url__'],
project_urls={
'Release Notes': 'https://firebase.google.com/support/release-notes/admin/python',
'Source': 'https://github.com/firebase/firebase-admin-python',
},
author=about['__author__'],
Expand Down
4 changes: 2 additions & 2 deletions tests/test_auth_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
from firebase_admin import exceptions
from tests import testutils

ID_TOOLKIT_URL = 'https://identitytoolkit.googleapis.com/v2beta1'
ID_TOOLKIT_URL = 'https://identitytoolkit.googleapis.com/v2'
EMULATOR_HOST_ENV_VAR = 'FIREBASE_AUTH_EMULATOR_HOST'
AUTH_EMULATOR_HOST = 'localhost:9099'
EMULATED_ID_TOOLKIT_URL = 'http://{}/identitytoolkit.googleapis.com/v2beta1'.format(
EMULATED_ID_TOOLKIT_URL = 'http://{}/identitytoolkit.googleapis.com/v2'.format(
AUTH_EMULATOR_HOST)
URL_PROJECT_SUFFIX = '/projects/mock-project-id'
USER_MGT_URLS = {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_tenant_mgt.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@
INVALID_BOOLEANS = ['', 1, 0, list(), tuple(), dict()]

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


@pytest.fixture(scope='module')
Expand Down